Monday, March 26, 2018

Hack 7.8 Getting The Process ID (PID) On UNIX and Linux




SAS Programming Professionals,

Did you know that you can use &SYSJOBID to get the Process ID (PID) of SAS tasks running on UNIX and Linux servers? 

This can be useful for differentiating between multiple SAS sessions you have running on a UNIX or Linux server.  It is also useful when you want to correlate the PID of a particular SAS batch task with UNIX or Linux system performance information. 

Here is an example of using &SYSJOBID that I have coded in many of my SAS/Connect programs:

data _null_;

pid     = &SYSJOBID;

put '******************************************************';
put '*                                                    *';
put '*The Process ID of this SAS/Linux Session is: ' pid '*';
put '*                                                    *';
put '******************************************************';

run;

This code produced the following in the SAS log when running from a PC client to a Linux server:

******************************************************
*                                                    *
* The Process ID of this SAS/Linux Session is: 31037 *
*                                                    *
******************************************************

It might make sense to use &SYSJOBID to document the PID of all of your SAS programs running in UNIX environments.  That way; you will always have that information in your SAS log if you ever need it. 

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, March 19, 2018

Hack 7.7 Dynamically Concatenating SAS Libraries




SAS Programming Professionals,

Did you know that you can dynamically insert and append SAS format libraries and macro libraries to your list of available SAS libraries dynamically within a SAS program? 

The INSERT= SAS option allows you to insert a libref as the FIRST in a series of librefs that SAS will search.  The APPEND= SAS option allows you to append a libref as the LAST in a series of librefs that SAS will search.  These two options work to modify the following SAS system options’ settings:

·        CMPLIB=
·        FMTSEARCH=
·        MAPS=
·        SASAUTOS=
·        SASSCRIPT=

Here is an example of using the INSERT= option:

libname templib "c:\temp";

options insert=(fmtsearch=(templib));

… after the code, above, has run, PROC OPTIONS will reveal that the TEMPLIB format library is placed ahead of the other SAS format libraries that SAS searches for a particular format:

FMTSEARCH=(TEMPLIB WORK LIBRARY)

Conversely, in this example of the APPEND= option:

libname templib "c:\temp";

options append=(fmtsearch=(templib));

… after the code, above, has run, PROC OPTIONS will reveal that the TEMPLIB format library is placed after the other SAS format libraries that SAS searches for a particular format:

FMTSEARCH=(WORK LIBRARY TEMPLIB)

Prior to the implementation of the INSERT= and APPEND= options, you either had to modify the –INSERT and –APPEND options in your SAS CONFIG file (and then launch SAS), or you had to specify the search order of _ALL_ libraries via the FMTSEARCH=, SASAUTOS=, etc. options within a program.  Now, you can pre-append or append the various format, macro, etc. libraries for your various projects or users on the fly.  This is a BIG step forward thanks to the brainiacs at the SAS Institute! 

In summary, you can use:

·        INSERT= to pre-append libraries so they will be searched FIRST in the search pattern when specifying CMPLIB=, FMTSEARCH=, MAPS=, SASAUTOS=, and SASSCRIPT= option statements.

·        APPEND= to append libraries so they will be searched LAST in the search pattern when specifying CMPLIB=, FMTSEARCH=, MAPS=, SASAUTOS=, and SASSCRIPT= option statements.

Pretty nifty, eh?

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