Personal tools
You are here: Home Software Packages SAS Output and Graphics using SAS Proc Print Options

Proc Print Options

Great Proc Print options that you have never used but should!

Most SAS users have used proc print but few are aware of the great options available. These options allow you to to customize your output and even create variable subtotals.

Limiting observations when printing:

libname sastmp '/sastmp';
proc print data=sastmp.class (obs=50);
run;

The (obs=50) option will limit the printing to the first 50 observations in the data set. OBS specifies the last observation of the SAS data set that will be printed. It does NOT specify how many observations that should be printed. If you wanted to begin printing at the 20th observation and end at the 50th observation you can use the firstobs option:

 proc print data=sastmp.class (firstobs = 20 obs = 50);

Printing the number of observations in the data set

libname sastmp '/sastmp';
proc print data=sastmp.data1 n;
run;

The n option will print the number of observations in the data set at the end of the output. If you use a by statement, the number of observations in each BY group will be printed.

Printing with BY variables

libname sastmp '/sastmp';
proc print data=sastmp.data1;
by state county;
run;

The proc print expects the data to be in order (ascending) of the BY variable. If your data is in descending order you can use

by descending salesyr

This would put the most current sales figures first.

Creating page breaks with PAGEBY

libname sastmp '/sastmp';
proc print data=sastmp.data1;
by state county zip;
pageby county;
run;

This program will start printing a new page if the state or county changes but not if the zip code changes. You must use a BY statement with a PAGEBY statement.

Totaling variables with SUM

libname sastmp '/sastmp';
proc print data=sastmp.data1;
sum sales;
run;

This program will total and print the sum of the variable sales. If you use a SUM statement with a BY statement, you will get a subtotal for each BY group in which there is more than one observation. In the example below, the sales will be summed by region.

libname sastmp '/sastmp';
proc print data=sastmp.data1;
by region;
sum sales;
run;

Printing selected observations using WHERE

libname sastmp '/sastmp';
proc print data=sastmp.data1 (where=(zip=16802));
run;

The WHERE statement tells SAS to print only the observations in which zip = 16802. This allows you to print part of a file without having to subset it first.

Printing only certain variables or changing their order using VAR

libname sastmp '/sastmp';
proc print data=sastmp.data1;
var state county zip pop80;
run;

The VAR statement tells SAS to print only the variables listed and in the order given.

For further information on on these and other options see the Print Procedure in the SAS Procedures Guide.

Document Actions

Copyright ©2014, The Pennsylvania State University | Privacy and Legal Statements
Contact the Help Site Administrator | Last modified Aug 13, 2008 | Weblion Partner