UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS FAQ
How can I direct the output from PC SAS to a file?

When running SAS programs interactively through the display manager, the output from any procedure is written to the Output window and notes, warnings and errors are written to the Log Window. Contents of these windows are temporary.  They can be saved to a file using the File Save pulldown menus from the Output Window and from the Log Window.  But if you want to make sure that the output of these windows is saved to a file every time, you can use proc printto to automatically route output to a file.

For example, the following program routes the output from proc printto directly to a file named auto.lst. What would have gone to the Output Window is redirected to the file c:\auto.lst .

PROC PRINTTO PRINT='c:\auto.lst' NEW;
RUN;

PROC PRINT DATA=auto;
  VAR make price ;
RUN;

PROC PRINTTO PRINT=PRINT;
RUN; 

Let's look at each statement more closely. 

The statements below tell SAS to send output that would go to the Output Window to the file c:\auto.lst and to create a new file if the file currently exists.  If the new option was omitted, SAS would append to the file if it existed.

PROC PRINTTO PRINT='c:\auto.lst' NEW;
RUN; 

This is just a regular proc print, the results of which will go to c:\auto.lst.

PROC PRINT DATA=auto;
  VAR make price ;
RUN; 

The statement below tells SAS to direct any subsequent output to the default destination (in SAS Display Manager, output will be directed back to the Output Window).

PROC PRINTTO PRINT=PRINT;
RUN; 

It is also possible to change the destination for the SAS Log as well, as shown in the example below.  This example redirects the log to c:\auto.log . The log information from the proc print is directed to c:\auto.log, and then the destination for the log is returned back to its default (in SAS Display manger, the log will be directed back to the Log Window).

PROC PRINTTO LOG='c:\auto.log' NEW;
RUN;

PROC PRINT DATA=auto;
  VAR make price ;
RUN;

PROC PRINTTO LOG=LOG;
RUN; 

Finally, you can change the destination for the SAS Output Window and Log Window at the same time, as illustrated below.

PROC PRINTTO PRINT='c:\auto.lst' LOG='c:\auto.log' NEW;
RUN;

PROC PRINT DATA=auto;
  VAR make price ;
RUN;

PROC PRINTTO PRINT=PRINT LOG=LOG ;
RUN; 

While these examples have focused on SAS Display Manager for the PC, these same commands could be used in SAS Display Manager on any platform.   In fact, this could be used in SAS in batch mode as well.  For example, it can be convenient to use proc printto to direct the output of a group of statements to one file, then to direct the output from another group of statements to another file.


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California