Monday, October 10, 2016

Hack 3.22 Simplifying PROC DATASETS Output with the NOLIST Option

SAS Programming Professionals,

Did you know that you can stop PROC DATASETS from inflating your SAS log with those pesky long library contents listings?

By default, PROC DATASETS prints a list of the contents of the SAS library it is operating on to the SAS log.  If you have one or two SAS files in that library, then it may not be noteworthy.  But, if you have scores, dozens, hundreds, or more SAS files in the SAS data library, it can be burdensome to have such information plopped into the middle of the log—especially if you use the DATASETS procedure multiple times in the same program.

The NOLIST option on the PROC DATASETS statement prevents the procedure from printing a library directory in your SAS log.  Here is an example.

This code:

libname ctemp "c:\temp";

proc datasets library=ctemp;
       modify drugs;
            rename subject = patient;
      run;
quit;

Produces the following SAS log:

1    libname ctemp "c:\temp";
NOTE: Libref CTEMP was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\temp

2    proc datasets library=ctemp;
Directory

Libref         CTEMP
Engine         V9
Physical Name  c:\temp
Filename       c:\temp


Member
#  Name                 Type     File Size  Last Modified

1  BUY                  DATA          5120  19May11:09:53:04
2  CARS                 DATA         74752  14Jun11:16:17:29
3  CLASS                DATA          5120  09Mar12:16:50:44
4  CLASSCAT             CATALOG      13312  13Jan12:11:06:42
5  DRUGS                DATA         13312  09Mar12:16:54:29
6  FINAL                DATA          5120  18Oct10:15:01:04
7  FORMATS              CATALOG    2499584  17Sep07:10:25:50
8  HEART                DATA        902144  09Mar12:16:55:46
9  HEART_BACKUP         DATA        885760  05Jul11:16:08:07
10  MASSZIPS             DATA        377856  20May11:16:15:19
11  MYFMTS               CATALOG      17408  13Feb12:14:34:11
12  ORSALES              DATA        111616  05Jun09:08:30:45
13  PRDSAL2              DATA       2790400  24Jun11:11:26:33
14  SALES                DATA          5120  12Nov09:09:46:31
15  SAMPLE_RESPITE       DATA          9216  19Jul11:11:54:20
16  SAMPLE_RESPITE1      DATA          5120  19Jul11:13:14:25
17  SASMACR              CATALOG      33792  07Nov11:10:06:08
18  SHOEAUD              DATA        132096  12Nov09:10:41:52
19  SHOES                DATA         17408  12Nov09:10:28:26
    SHOES                AUDIT       140288  12Nov09:10:28:26
20  SUMCLASS             DATA          5120  03Dec09:16:14:27
21  ZIPCODE_11Q2_UNIQUE  DATA      33915904  21May11:09:40:21
    ZIPCODE_11Q2_UNIQUE  INDEX       762880  21May11:09:40:20
22  ZIPMIL_11Q2          DATA        492544  21May11:09:40:22
    ZIPMIL_11Q2          INDEX        21504  21May11:09:40:22
23  ZIPMISC_11Q2         DATA         33792  21May11:09:40:22
    ZIPMISC_11Q2         INDEX         9216  21May11:09:40:22
3
4        modify drugs;
5            rename subject = patient;
NOTE: Renaming variable subject to patient.
6        run;

NOTE: MODIFY was successful for CTEMP.DRUGS.DATA.
7    quit;

Interesting enough, but definitely TMI!  The NOTE’s tell the tale that we were successful in renaming SUBJECT to PATIENT and that our modify of the DRUGS data set was successful.  So, we do not really need any additional information about the SAS data library at this time.

We decided that we want to rename PATIENT back to SUBJECT, and this time use the NOLIST option:

proc datasets library=ctemp nolist;

      modify drugs;
            rename patient = subject ;
      run;
quit;

… resulting in this log:

10   proc datasets library=ctemp nolist;
11
12       modify drugs;
13           rename patient = subject ;
NOTE: Renaming variable patient to subject.
14       run;

NOTE: MODIFY was successful for CTEMP.DRUGS.DATA.
15   quit;

Now, that’s exactly what we want: a leaner, cleaner log!

Best of luck in all your SAS endeavors!

----MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)

Excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

I plan to post each and every one of the hacks in the book to social media on a weekly basis.  Please pass them along to colleagues who you know would benefit.