SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating List Reports
Lesson Summary
 


This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.


Setting Up
Before producing a report, you must assign a libref to the SAS data library storing the data set to be used. You can also set system options to control the appearance of your report.

Creating a Basic Report
To list the information in a SAS data set, you can use PROC PRINT. You use the PROC PRINT statement to invoke the PRINT procedure and specify the data set that you are listing. Include the DATA= option to specify the data set that you are using. By default, PROC PRINT displays all observations and variables in the data set, a column for observation numbers on the far left, and variables in the order that they occur in the data set. If you use a LABEL statement with PROC PRINT, you must specify the LABEL option in the PROC PRINT statement.

To refine a basic report, you can

  • select which variables and observations are processed
  • sort the data
  • generate column totals for numeric variables.

Selecting Variables
You can select variables and control the order in which they appear by using a VAR statement in your PROC PRINT step. To replace the default Obs heading in your PROC PRINT output, you can specify the OBS= option in the PROC PRINT statement. To remove the Obs column, you can specify the NOOBS option in the PROC PRINT statement.

Selecting Observations
The WHERE statement enables you to select observations that meet a particular condition in the SAS data set. You use comparison operators to express a condition in the WHERE statement. To specify a condition based on the value of a character variable, you must enclose the value in quotes and write the value with lower and uppercase letters exactly as it appears in the data set. You can also use WHERE statements to select a subset of observations based on multiple conditions. To link a sequence of expressions into compound expressions, you use logical operators. When you test for multiple values of the same variable, you specify the variable name in each expression. You can use the IN operator as a convenient alternative. To control the way that compound expressions are evaluated, you can use parentheses.

Specifying Column Totals
To total the values of numeric variables, use the SUM statement in the PROC PRINT step to name the numeric variables to be summed. You do not need to name the variables in a VAR statement if you specify them in the SUM statement. Column totals appear at the end of the report in the same format as the values of the variables.

Sorting Data
To display your data in sorted order, you use PROC SORT to sort your data before using PROC PRINT to create reports. By default, PROC SORT sorts the data set specified in the DATA= option permanently. If you do not want your data sorted permanently, you must create an output data set that contains the data in sorted order. The OUT= option in the PROC SORT statement specifies an output data set. If you need your data sorted to produce output for only one SAS session, you should specify a temporary SAS data set as the output data set. The BY statement, required with PROC SORT, specifies the variable(s) whose values are used to order the data.

Double Spacing Output
To double space your output, you can specify the DOUBLE option.

Specifying Labels
To display labels specified in a LABEL statement used with PROC PRINT, you must specify the LABEL option in the PROC PRINT statement.


II. Syntax

To go to the page where a statement or option was presented, select a link.

LIBNAME libref  'SAS-data-library';
OPTIONS options;
PROC SORT DATA=SAS-data-set OUT=SAS-data-set;
      BY variables;
RUN;
PROC PRINT DATA=SAS-data-set  
            NOOBS LABEL DOUBLE;
      VAR variables;
      WHERE where-expression;
      SUM variables;
      LABEL variable1='label' variable2='label';
RUN;


III. Sample Program
     libname clinic 'c:\stress\labdata';
     options nodate number pageno=15;
     proc sort data=clinic.stress out=maxrates;
        by maxhr;
     run;
     proc print data=maxrates label double noobs;
        var resthr maxhr rechr date;
        where tolerance='I' and resthr>90;
        sum fee;
        label rechr='Recovery HR';        
     run;


IV. Points to Remember
  • VAR, WHERE, and sum statements remain in effect only for the PROC step in which they appear.

  • If you don't use the OUT= option, PROC SORT permanently sorts the data set specified in the DATA= option.

  • When you use LABEL statements with PROC PRINT, remember to specify the LABEL option in the PROC PRINT statement.



back||next

 

Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement