SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 32110: How to use code to write log and listing files to disk using SAS ® Enterprise Guide

DetailsAboutRate It

This sample shows how to add code in SAS Enterprise Guide that will write a SAS log file and ODS listing file to disk each time that a SAS program is run from SAS Enterprise Guide.

By default, SAS Enterprise Guide project files retain the log files and results generated by user-written code and tasks. However, many SAS customers use SAS Enterprise Guide for running their production SAS programs instead of building reports by using the point-and-click interface.

This sample can be helpful for those SAS Enterprise Guide users who work in industries such as pharmaceuticals that require separate documentation in the form of SAS log files and SAS output files for each job execution, instead of the logs and outputs embedded in a SAS Enterprise Guide project file.

  1. Start SAS Enterprise Guide and open a new project.
  2. Select Tools→Options→SAS Programs.
  3. The following image shows the Options window.

    image label

  4. Select the Insert custom SAS code before submitted code option.
  5. Click Edit.
  6. The following image shows the Edit window.

    image label

  7. Enter the following code:
  8. 
    
    options dtreset fullstimer;
    
    %let SAS_ListingDateTimeStamp   = SAS_Listing_%sysfunc(putn(%sysfunc(date()),yymmdd10.))__%sysfunc(translate(%sysfunc(putn(%sysfunc(time()),timeampm12.)),.,:));
    %let ListingOutFile  = C:\temp\test\&SAS_ListingDateTimeStamp..txt;
    ods listing file="&ListingOutFile";
    
    %let SAS_LogDateTimeStamp   = SAS_Log_%sysfunc(putn(%sysfunc(date()),yymmdd10.))__%sysfunc(translate(%sysfunc(putn(%sysfunc(time()),timeampm12.)),.,:));
    %let LogOutFile  = C:\temp\test\&SAS_LogDateTimeStamp..txt;
    filename logfile "&LogOutFile";
    
    proc printto log=logfile;
    run;
    
    

    Note: In order to use the exact code above, make sure you have write access to the path C:\temp\test on your SAS server; otherwise, modify the path in the code accordingly to point to a valid path.

  9. Click Save to close the Edit window.
  10. Select the Insert custom SAS code after submitted code option.
  11. Click Edit.
  12. The following image shows the Edit window.

    image label

  13. Enter the following code:
  14. 
    
    proc printto;
    run;
    
    

  15. Click Save to close the Edit window.
  16. Click OK to close the Options window.
  17. To test the code changes, click File→New→Code.
  18. Enter and run the following sample code:
  19. 
    
    proc print data=sashelp.class;
    run;
    
    

  20. To use SAS Enterprise Guide to see if the files were created, you can click File→Open→Other and go to the path were the files were written.
  21. The following image shows the Log and Listing files were created. Notice that they are labeled nicely with a Date and Time stamp.

    image label

  22. If you want to open the files in SAS Enterprise Guide, select a file and then click Open.
  23. When prompted, choose Select this option if you want to view the file as is and the file will open.



These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.