Directing SAS Output and the SAS Log |
Routing Output to an Alternate Location |
You can use the PRINTTO procedure to redirect SAS procedure output from the listing destination to an alternate location. These locations are:
After PROC PRINTTO executes, all procedure output is sent to the alternate location until you execute another PROC PRINTTO statement or until your program or session ends.The default destination for the procedure output depends on how you configure SAS to handle output. For more information, see the discussion of SAS output in Understanding and Customizing SAS Output: The Basics.
Note: If you used the Output Delivery System (ODS) to close the listing destination, then PROC PRINTTO does not receive any output to redirect. However, the procedure results still go to the destination that you specified with ODS.
You use the PRINT= option in the PROC PRINTTO statement to specify the name of the file or SAS catalog that will contain the procedure output. If you specify a file, then either use the complete name of the file in quotation marks or use a fileref for the file. (See Using External Files in Your SAS Job for more information about filerefs and filenames.) You can also specify the NEW option in the PROC PRINTTO statement so that SAS replaces the previous contents of the output file. Otherwise, SAS appends the output to any output that is currently in the file.
To route output to an alternate file, insert a PROC PRINTTO step in the program before the PROC step that generates the procedure output. The following program routes the output from PROC PRINT to an external file:
proc printto print='alternate-output-file' new; run; proc print data=sat_scores; title 'Mean SAT Scores for Entering University Classes'; run; proc printto; run;
After the PROC PRINT step executes, alternate-output-file contains the procedure output. The second PROC PRINTTO step redirects output back to its default destination.
The PRINTTO procedure does not produce the output. Instead it tells SAS to route the results of all subsequent procedures until another PROC PRINTTO statement executes. Therefore, the PROC PRINTTO statement must precede the procedure whose output you want to route.
Using PROC PRINTTO Route Output shows how SAS uses PROC PRINTTO to route procedure output. You can also use PROC PRINTTO multiple times in a program so that output from different steps of a SAS job is stored in different files.
Using PROC PRINTTO Route Output
Routing the SAS Log to an Alternate Location |
You can use the PRINTTO procedure to redirect the SAS log to an alternate location. The location can be one of the following:
After PROC PRINTTO executes, the log is sent either to a permanent external file or to a SAS catalog entry until you execute another PROC PRINTTO statement, or until your program or session ends.You use the LOG= option in the PROC PRINTTO statement to specify the name of the file or SAS catalog that will contain the log. If you specify a file, then either use the complete name of the file in quotation marks or use a fileref for the file. You can also specify the NEW option in the PROC PRINTTO statement so that SAS replaces the previous contents of the file. Otherwise, SAS appends the log to any log that is currently in the file.
The following program routes the SAS log to an alternate file:
proc printto log='alternate-log-file'; run;
After the PROC PRINT step executes, alternate-log-file contains the SAS log. The contents of this file are shown in the following output:
Using the PRINTTO Procedure to Route the SAS Log to an Alternate File
8 data sat_scores; 9 input Test $ Gender $ Year SATscore @@; 10 datalines; NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.SAT_SCORES has 108 observations and 4 variables. 65 ; 66 proc print data=sat_scores; 67 title 'Mean SAT Scores for Entering University Classes'; 68 run; NOTE: There were 108 observations read from the dataset WORK.SAT_SCORES. 69 proc printto; run;
Restoring the Default Destination |
Specify the PROC PRINTTO statement with no argument when you want to route the log and the output back to their default destinations:
proc printto; run;
You might want to return only the log or only the procedure output to its default destination. The following PROC PRINTTO statement routes only the log back to the default destination:
proc printto log=log; run;
The following PROC PRINTTO statement routes only the procedure output to the default destination:
proc printto print=print; run;
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.