of the Month
Sometimes in our program we want to get information from the option settings -- this can be something like LINESIZE information or the program name. The function that is useful to do this is the GETOPTION function.
The following code gets the LINESIZE option value and sets a horizontal line to a macro variable _horizonalLine to that length:
data _null_; _lineSize=getoption('ls'); _horizonalLine=repeat('_',_lineSize-1); call symput('_horizonalLine',strip(_horizonalLine)); run;
In the example above, the number of '_'s in the horizontal line is set from the LINESIZE setting -- if there is a LINESIZE of 77 then there will be a horizontal line made with 77 '_'s.
Similarly, the program name can be set using the SYSIN option value (this is only available in Batch mode -- the value will be blank for interactive mode) as the following code demonstrates:
data _null_; _pgmName=getoption('sysin'); if missing(_pgmName) then _pgmname='Interactive'; call symput('_pgmName',strip(_pgmName)); run;
Please note that what comes out of the SYSIN value is host dependent as some times the program name and directory is given and other times it is the program name only -- try it on your system first.
The following code will print the CLASS dataset and add a footnote with a horizontal line and put the program name and date/time the program run (note that you must save the SAS program as a
options nodate nonumber ls=77; run; data _null_; ** Get linesize and set a horizontal line; _lineSize=getoption('ls'); _horizonalLine=repeat('_',_lineSize-1); call symput('_horizonalLine',strip(_horizonalLine)); ** Get Program Name; _pgmName=getoption('sysin'); if missing(_pgmName) then _pgmName='Interactive'; call symput('_pgmName',strip(_pgmName)); run; title1 'Listing of CLASS data'; footnote1 "&_horizonalLine"; footnote2 "Program Name: &_pgmName Generation Date/Time: &sysdate9. &systime."; run; proc print data=sashelp.class; run;
Note the use of the double quotes around the text that contains the macro variables _horizonalLine and _pgmName -- as a general rule SAS will not resolve macro variable if single quotes are used.
This month is the start of conference season with SAS Global Forum starting in Seatle, WA on April 11 through April 14. If you cannot be there in person, please visit the Global SAS Forum web site and get updates -- there will be among other things a summary of the days' happenings and discussions from key people on the direction SAS is taking.
See you in May.
Updated April 05, 2010