PRINTTO Procedure

Example 2: Routing to SAS Catalog Entries

Features:

PRINTTO statement without options

PRINTTO statement options::
LABEL=
LOG=
NEW
PRINT=

Details

This example uses PROC PRINTTO to route the SAS log and procedure output to a SAS catalog entry and then to reset both destinations to the default.

Program

options source;
libname lib1 'SAS-library';
proc printto log=test.log label='Inventory program' new;
run;
data lib1.inventry;
   length Dept $ 4 Item $ 6 Season $ 6 Year 4;
   input dept item season year @@;
   datalines;
3070 20410  spring 2011 3070 20411  spring 2012
3070 20412  spring 2012 3070 20413  spring 2012
3070 20414  spring 2011 3070 20416  spring 2009
3071 20500  spring 2011 3071 20501  spring 2009
3071 20502  spring 2011 3071 20503  spring 2011
3071 20505  spring 2010 3071 20506  spring 2009
3071 20507  spring 2009 3071 20424  spring 2011
;
ods listing;
proc printto print=lib1.cat1.inventry.output
             label='Inventory program' new;
run;

proc report data=lib1.inventry nowindows headskip;
   column dept item season year;
   title 'Current Inventory Listing';
run;
proc printto;
run;
ods listing close;

Program Description

Set the SAS system options. The SOURCE option specifies to write source statements to the SAS log.
options source;
Assign a libref.
libname lib1 'SAS-library';
Route the SAS log to a SAS catalog entry. PROC PRINTTO routes the SAS log to a SAS catalog entry named SASUSER.PROFILE.TEST.LOG. The PRINTTO procedure uses the default libref and catalog SASUSER.PROFILE because only the entry name and type are specified. LABEL= assigns a description for the catalog entry.
proc printto log=test.log label='Inventory program' new;
run;
Create the LIB1.INVENTORY data set. The DATA step creates a permanent SAS data set.
data lib1.inventry;
   length Dept $ 4 Item $ 6 Season $ 6 Year 4;
   input dept item season year @@;
   datalines;
3070 20410  spring 2011 3070 20411  spring 2012
3070 20412  spring 2012 3070 20413  spring 2012
3070 20414  spring 2011 3070 20416  spring 2009
3071 20500  spring 2011 3071 20501  spring 2009
3071 20502  spring 2011 3071 20503  spring 2011
3071 20505  spring 2010 3071 20506  spring 2009
3071 20507  spring 2009 3071 20424  spring 2011
;
Route the procedure output to a SAS catalog entry.To write to a SAS catalog entry you must open the LISTING destination. PROC PRINTTO routes procedure output from the subsequent PROC REPORT step to the SAS catalog entry LIB1.CAT1.INVENTRY.OUTPUT. LABEL= assigns a description for the catalog entry.
ods listing;
proc printto print=lib1.cat1.inventry.output
             label='Inventory program' new;
run;

proc report data=lib1.inventry nowindows headskip;
   column dept item season year;
   title 'Current Inventory Listing';
run;
Reset the SAS log and procedure output back to the default and close the file. PROC PRINTTO closes the current files that were opened by the previous PROC PRINTTO step and reroutes subsequent SAS logs and procedure output to their default destinations. Close the Listing destination.
proc printto;
run;
ods listing close;

Log

To view this log using SAS Explorer, select Sasuserthen selectProfile. Double-click on Test. The log opens in NOTEPAD.
SAS Log Routed to SAS Catalog Entry SASUSER.PROFILE.TEST.LOG.
NOTE: PROCEDURE PRINTTO used (Total process time):                        
      real time           0.00 seconds                                         
      cpu time            0.00 seconds                                         
                                                                               
                                                                               
49                                                                             
50   data lib1.inventry;                                                       
51      length Dept $ 4 Item $ 6 Season $ 6 Year 4;                            
52      input dept item season year @@;                                        
53      datalines;                                                             
                                                                               
NOTE: SAS went to a new line when INPUT statement reached past the end of a    
      line.                                                                    
NOTE: The data set LIB1.INVENTRY has 14 observations and 4 variables.          
NOTE: DATA statement used (Total process time):                                
      real time           0.03 seconds                                         
      cpu time            0.00 seconds                                         
                                                                               
                                                                               
61   ;                                                                         
62   ods listing;                                                              
63   proc printto print=lib1.cat1.inventry.output                              
64                label='Inventory program' new;                               
65   run;                                                                      
                                                                               
NOTE: PROCEDURE PRINTTO used (Total process time):                             
      real time           0.00 seconds                                         
      cpu time            0.00 seconds                                         
                                                                               
                                                                               
66                                                                             
67   proc report data=lib1.inventry nowindows headskip;                        
68      column dept item season year;                                          
69      title 'Current Inventory Listing';                                     
70   run;                                                                      
                                                                               
NOTE: There were 14 observations read from the data set LIB1.INVENTRY.         
NOTE: PROCEDURE REPORT used (Total process time):                              
      real time           0.09 seconds                                         
      cpu time            0.04 seconds                                         
                                                                               
                                                                               
71                                                                             
72   proc printto;                                                             
73   run;          
NOTE: PROCEDURE PRINTTO used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


74   ods listing close;

Output

To view this log using SAS Explorer, select Lib1then selectCat1. Double-click on Inventry. The output opens in NOTEPAD.
Procedure Output Routed to SAS Catalog Entry LIB1.CAT1.INVENTRY.OUTPUT.
Procedure Output Routed to SAS Catalog Entry LIB1.CAT1.INVENTRY.OUTPUT.