Wednesday, December 21, 2011

SAS: Merging Log and Output in a single file

SAS typically displays the code, log and procedure output in separate windows.  You can use PROC PRINTTO to re-direct log and procedure output into a single file. Since the code run is typically mirrored in the log file, you have a nice single file documenting your code and output, along with any warnings and other useful information from the log file.  The trick is to specify the same file in the log= and print= options in PROC PRINTTO

For example:

proc printto log="I:\sasods\printto_test.txt" print="I:\sasods\printto_test.txt";
data numbers;
   input x y z;
   datalines;
 14.2   25.2   96.8
 10.8   51.6   96.8
  9.5   34.2  138.2
  8.8   27.6   83.2
 11.5   49.4  287.0
  6.3   42.0  170.7
;
 
proc print data=numbers;
   title 'Listing of NUMBERS Data Set';
run;

proc printto;
run;


creates the following file:

NOTE: PROCEDURE PRINTTO used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
     

3    data numbers;
4       input x y z;
5       datalines;

NOTE: The data set WORK.NUMBERS has 6 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
     

12   ;
13  
14   proc print data=numbers;
15      title 'Listing of NUMBERS Data Set';
16   run;

Listing of NUMBERS Data Set


Obs      x       y       z

 1     14.2    25.2     96.8
 2     10.8    51.6     96.8
 3      9.5    34.2    138.2
 4      8.8    27.6     83.2
 5     11.5    49.4    287.0
 6      6.3    42.0    170.7
NOTE: There were 6 observations read from the data set WORK.NUMBERS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
     

17  
18   proc printto;
19   run;


 The last PROC PRINTTO resets to the default output and log destinations.

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner

Followers

google analytics