University of Southern California

ITS Information Technology Services

A division of the Office of the Chief Information Officer

Slightly less simple reports with SAS

The first steps in modifying a report from the basic print procedure, are to sort the report in the order of some variable, give descriptive labels to columns, select specific variables for the report and add titles.

To sort your data before printing, use the following:

Proc sort data = dataset-name out = new dataset-name ;
by variable-name

The out = on the proc sort statement is optional. By default, the dataset will be sorted and the original, unsorted dataset replaced by the sorted one. In some cases, however, you may wish to create a new dataset. In the example at the end of this page, the Where statement is used to only keep those records where the variable "tribe" does not have a missing value will be saved. You may wish to keep the original dataset with all the records, and create a new dataset that is sorted by tribe and only has those records where the respondent gave a value for the tribe in which he or she was enrolled. In this case, the out = option is used.

The Proc print statement also has several options. One useful option is the (obs = ) n which only prints the first n observations. You may wish to print out the first five or six records to check the data has the expected format or see the look of your final report. Another common option is split = to define where to split labels across lines.

"But wait, what is a label?" you may be asking. A Label statement gives the description of a variable name to be printed on a report. It takes the following format:

Label variable1 ="Whatever text you want here."
variable2 ="Whatever text you want here." ;

NOTE: You can use single quotes or double quotes. The important thing to remember is that you must begin and end the same way. A statement like the example below will cause unwanted results in your program, most likely ending with an ERROR statement.

Label "variable = This is an example of what not to do.' ;

Two other very common statements used in producing reports are the Id, and Var statements. The syntax for each of these is quite simple:

Id variable' ;
and
Var list of variables'

The variable listed on the Id statement will print on the report first followed by the variables on the Var statement, in the order listed. Variables not listed on the Var statement will not be printed.

NOTE: The Id, Var, and Label statements are part of the print procedure. Therefore, the Proc print statement must come first, followed by these statements.

The Title statement is not part of any procedure. It can be the first statement in your program or in the middle. Once you have given a Title statement it will be the title for the output for every procedure that follows until you give a different title using a new Title statement. A report can have multiple Title statements. The first title statement prints on the first line, the statement Title2 will print on the second line, and so on. The format is as follows:

Title "Whatever text you want here." ;

Now that you know two procedures, and several statements, let's put all of these together in a single example.

proc sort data = allsubjects out = tribalmembers ;
by tribe ;
where tribe ne "" ;

Title "Internet Access and Demographics" ;
Title2 "By Tribe" ;
proc print data= tribalmembers (obs=6) split = " " ;
id tribe ;
var age gender homeComputer HomeInternet Yrs_educ ;
Label
HomeComputer = "Home Computer Access"
HomeInternet = "Home Internet Access"
Tribe = "Tribal Enrollment"
Yrs_educ = "Years of Education" ;

These result in the less simple report shown below. SAS less simple

Want it less simple yet? For anyone interested in more polished reports with print or any other SAS procedure, the USC-ITS documentation page HTML, PDF and RTF output is a must-read.

Last updated:
September 24, 2008

SAS

The use of all USC computing resources is governed by the USC Computing Policies.