Procedure features:
PRINTTO statement:
Without options
Options:
LOG=
NEW
PRINT=
This example uses PROC PRINTTO to route the log and procedure output to an external file and then reset both destinations to the default.
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page. The SOURCE option writes lines of source code to the default destination for the SAS log.
options nodate pageno=1 linesize=80 pagesize=60 source;
Route the SAS log to an external file. PROC PRINTTO uses the LOG= option to route the SAS log to an external file. By default, this log is appended to the current contents of log-file .
proc printto log=' log-file '; run;
Create the NUMBERS data set. The DATA step uses list input to create the NUMBERS data set.
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 ;
Route the procedure output to an external file. PROC PRINTTO routes output to an external file. Because NEW is specified, any output written to output-file will overwrite the file s current contents.
proc printto print=' output-file ' new; run;
Print the NUMBERS data set. The PROC PRINT output is written to the specified external file.
proc print data=numbers; title 'Listing of NUMBERS Data Set'; run;
Reset the SAS log and procedure output destinations to default. PROC PRINTTO routes subsequent logs and procedure output to their default destinations and closes both of the current files.
proc printto; run;
1 options nodate pageno=1 linesize=80 pagesize=60 source; 2 proc printto log=' log-file '; 3 run;
5 6 data numbers; 7 input x y z; 8 datalines; NOTE: The data set WORK.NUMBERS has 6 observations and 3 variables. NOTE: DATA statement used: real time 0.00 seconds cpu time 0.00 seconds 15 ; 16 proc printto print='output-file' new; 16 17 run; NOTE: PROCEDURE PRINTTO used: real time 0.00 seconds cpu time 0.00 seconds 18 19 proc print data=numbers; 20 title 'Listing of NUMBERS Data Set'; 21 run; NOTE: The PROCEDURE PRINT printed page 1. NOTE: PROCEDURE PRINT used: real time 0.00 seconds cpu time 0.00 seconds 22 23 proc printto; 24 run;
Listing of NUMBERS Data Set 1 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
Procedure features:
PRINTTO statement:
Without options
Options:
LABEL=
LOG=
NEW
PRINT=
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.
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=60 source;
Assign a libname.
libname lib1 ' SAS-data-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 1996 3070 20411 spring 1997 3070 20412 spring 1997 3070 20413 spring 1997 3070 20414 spring 1996 3070 20416 spring 1995 3071 20500 spring 1994 3071 20501 spring 1995 3071 20502 spring 1996 3071 20503 spring 1996 3071 20505 spring 1994 3071 20506 spring 1994 3071 20507 spring 1994 3071 20424 spring 1994 ;
Route the procedure output to a SAS catalog entry. 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.
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.
proc printto; run;
You can view this catalog entry in the BUILD window of the SAS Explorer.
8 9 data lib1.inventry; 10 length Dept $ 4 Item $ 6 Season $ 6 Year 4; 11 input dept item season year @@; 12 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: real time 0.00 seconds cpu time 0.00 seconds 20 ; 21 22 proc printto print=lib1.cat1.inventry.output 23 label='Inventory program' new; 24 run; NOTE: PROCEDURE PRINTTO used: real time 0.00 seconds cpu time 0.00 seconds 25 26 proc report data=lib1.inventry nowindows headskip; 27 column dept item season year; 28 title 'Current Inventory Listing'; 29 run; NOTE: PROCEDURE REPORT used: real time 0.00 seconds cpu time 0.00 seconds 30 31 proc printto; 32 run;
You can view this catalog entry in the BUILD window of the SAS Explorer.
Current Inventory Listing 1 Dept Item Season Year 3070 20410 spring 1996 3070 20411 spring 1997 3070 20412 spring 1997 3070 20413 spring 1997 3070 20414 spring 1996 3070 20416 spring 1995 3071 20500 spring 1994 3071 20501 spring 1995 3071 20502 spring 1996 3071 20503 spring 1996 3071 20505 spring 1994 3071 20506 spring 1994 3071 20507 spring 1994 3071 20424 spring 1994
Procedure features:
PRINTTO statement:
Without options
Options:
LOG=
NEW
PRINT=
This example uses PROC PRINTTO to route procedure output to an external file and then uses that file as input to a DATA step.
Generate random values for the variables. The DATA step uses the RANUNI function to randomly generate values for the variables X and Y in the data set A.
data test; do n=1 to 1000; x=int(ranuni(77777)*7); y=int(ranuni(77777)*5); output; end; run;
Assign a fileref and route procedure output to the file that is referenced. The FILENAME statement assigns a fileref to an external file. PROC PRINTTO routes subsequent procedure output to the file that is referenced by the fileref ROUTED. See Output 36.6.
filename routed ' output-filename '; proc printto print=routed new; run;
The FREQ Procedure Table of x by y x y Frequency Percent Row Pct Col Pct 0 1 2 3 4 Total ---------+--------+--------+--------+--------+--------+ 0 29 33 12 25 27 126 2.90 3.30 1.20 2.50 2.70 12.60 23.02 26.19 9.52 19.84 21.43 15.18 16.18 6.25 11.74 13.50 ---------+--------+--------+--------+--------+--------+ 1 23 26 29 20 19 117 2.30 2.60 2.90 2.00 1.90 11.70 19.66 22.22 24.79 17.09 16.24 12.04 12.75 15.10 9.39 9.50 ---------+--------+--------+--------+--------+--------+ 2 28 26 32 30 25 141 2.80 2.60 3.20 3.00 2.50 14.10 19.86 18.44 22.70 21.28 17.73 14.66 12.75 16.67 14.08 12.50 ---------+--------+--------+--------+--------+--------+ 3 26 24 36 32 45 163 2.60 2.40 3.60 3.20 4.50 16.30 15.95 14.72 22.09 19.63 27.61 13.61 11.76 18.75 15.02 22.50 ---------+--------+--------+--------+--------+--------+ 4 25 31 28 36 29 149 2.50 3.10 2.80 3.60 2.90 14.90 16.78 20.81 18.79 24.16 19.46 13.09 15.20 14.58 16.90 14.50 ---------+--------+--------+--------+--------+--------+ 5 32 29 26 33 27 147 3.20 2.90 2.60 3.30 2.70 14.70 21.77 19.73 17.69 22.45 18.37 16.75 14.22 13.54 15.49 13.50 ---------+--------+--------+--------+--------+--------+ 6 28 35 29 37 28 157 2.80 3.50 2.90 3.70 2.80 15.70 17.83 22.29 18.47 23.57 17.83 14.66 17.16 15.10 17.37 14.00 ---------+--------+--------+--------+--------+--------+ Total 191 204 192 213 200 1000 19.10 20.40 19.20 21.30 20.00 100.00 2 The FREQ Procedure Statistics for Table of x by y Statistic DF Value Prob ------------------------------------------------------ Chi-Square 24 27.2971 0.2908 Likelihood Ratio Chi-Square 24 28.1830 0.2524 Mantel-Haenszel Chi-Square 1 0.6149 0.4330 Phi Coefficient 0.1652 Contingency Coefficient 0.1630 Cramer's V 0.0826 Sample Size = 1000
Produce the frequency counts. PROC FREQ computes frequency counts and a chi-square analysis of the variables X and Y in the data set TEST. This output is routed to the file that is referenced as ROUTED.
proc freq data=test; tables x*y / chisq; run;
Close the file. You must use another PROC PRINTTO to close the file that is referenced by fileref ROUTED so that the following DATA step can read it. The step also routes subsequent procedure output to the default destination. PRINT= causes the step to affect only procedure output, not the SAS log.
proc printto print=print; run;
Create the data set PROBTEST. The DATA step uses ROUTED, the file containing PROC FREQ output, as an input file and creates the data set PROBTEST. This DATA step reads all records in ROUTED but creates an observation only from a record that begins with Chi-Squa .
data probtest; infile routed; input word1 $ @; if word1='Chi-Squa' then do; input df chisq prob; keep chisq prob; output; end; run;
Print the PROBTEST data set. PROC PRINT produces a simple listing of data set PROBTEST. This output is routed to the default destination. See Output 36.7.
proc print data=probtest; title 'Chi-Square Analysis for Table of X by Y'; run;
Chi-Square Analysis for Table of X by Y 3 Obs chisq prob 1 27.297 0.291
Procedure features:
PRINTTO statement:
Option:
PRINT= option
This example uses PROC PRINTTO to route procedure output directly to a printer.
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=60;
Associate a fileref with the printer name. The FILENAME statement associates a fileref with the printer name that you specify. If you want to associate a fileref with the default printer, omit printer-name .
filename your_fileref printer ' printer-name ';
Specify the file to route to the printer. The PRINT= option specifies the file that PROC PRINTTO routes to the printer.
proc printto print= your_fileref ; run;