Monday, February 12, 2018

Michael A. Raithel's SAS Limerick #4

SAS Programming Professionals,


Something to make you smile while you write programs today:

    I once inherited a SAS macro so intense,

    That its logic just did not make sense,

    I thought that MLOGIC, SYMBOLGEN, and MPRINT,

    Would show me where the macro's logic ultimately went,

    But the resulting log was too overly dense.

Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

Hack 7.6 Determining SAS Files Types by Their Extensions




SAS Programming Professionals,

Did you know that you can quickly determine the nature of SAS files when viewing them on your operating system via their file extension? 

Knowing what SAS file type corresponds to the file extension can be handy when combing through directories in Windows Explorer or in native Linux.  Here are the file extensions:

Easy:

·        .sas      - SAS program
·        .log      - SAS log
·        .lst      - SAS list
·        .sas7bdat - SAS data set

More Obscure:

·        .sas7bndx - SAS index
·        .sas7bcat - SAS catalog
·        .sas7bvew - SAS view

Most Obscure:

·        .sas7bmdb - SAS MDDB
·        .sas7bitm - SAS Itemstore

You can get a list of SAS file extensions for you particular environment by accessing the SAS online documentation and viewing the SAS Companion document for that operating system.  For example, if you were using Windows, you would access the SAS 9.4 Companion for Windows and search for “file extension”.  That will net you a web page with a very nice table of SAS file extensions.  Check it out!

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

Monday, February 5, 2018

Michael A. Raithel's SAS Limerick #3

SAS Programming Professionals,


Something to make you smile while you write programs today:

    In my SAS logs nothing could be rarer,

    Than to find a SAS WARNING or ERROR,

    Because I buy books from SAS Press,

    To keep my syntax from being a mess,
   
    Every one of my logs is a good news bearer.


Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

Hack 7.5 Creating SAS Data Sets with Another Operating System’s Data Representation




SAS Programming Professionals,

Did you know that you can create a SAS data set in another operating system's internal data representation format? 

For example, you might be running SAS on Windows and want to create a UNIX SAS data set in a Windows directory for later delivery to a UNIX system.  You can do this using either the OUTREP data set option or the OUTREP LIBNAME option.  Here are examples of both options:

options msglevel=I;

/* Two examples of using the OUTREP LIBNAME option */

libname UNIXDATA "C:\TEMP\UNIXDATA" outrep=hp_ux;

/* 1. Creating a new SAS data set in the "Foreign" data library */

data UNIXDATA.class;
set  sashelp.class;
run;

proc contents data=UNIXDATA.class;
run;

/* 2. Copying a SAS data set to the "Foreign" data library */
proc copy in=sashelp out=UNIXDATA noclone;
      select prdsale;
run;

proc contents data=UNIXDATA.prdsale;
run;

/* 3. Using the OUTREP data set option */

libname UNIXDATA clear;

libname UNIXDATA "C:\TEMP\UNIXDATA";

data UNIXDATA.orsales(outrep=hp_ux);
set  sashelp.orsales;
run;

proc contents data=UNIXDATA.orsales;
run;

In the first LIBNAME OUTREP option example, the newly created CLASS data set will be in HP-UX format, even though it is stored on a Windows directory.  Check out the Data Representation field in the CONTENTS listing.

In the second LIBNAME OUTREP option example, the PRDSALE data set will be in HP-UX format.  But, notice that when the COPY procedure is executed, SAS normally "CLONE"-s the format of the input data set to the output data set.  So, you need to use the NOCLONE option for the new data set (UNIXLIB.PRDSALE) to be in HP-UX format.

The final example illustrates how you can code OUTREP data set option to store UNIXDATA.ORSALES as a UNIX SAS data set, even though it is stored in a Windows directly--as specified in the LIBNAME statement.

Note that with the MSGLEVEL=I option enabled, you will see the following type of message in your SAS log:

INFO: Data file UNIXDATA.CLASS.DATA is in a format that is native to another host, or the file encoding does not match the session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce performance.


That message lets you know that you have, indeed, been successful in storing a SAS data set in a foreign host’s data representation.  Good job!

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers