SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating List Reports
Sorting Data


By default, PROC PRINT lists observations in the order that they appear in your data set. To sort your data based on values of a variable, you must use PROC SORT to sort your data before using other procedures to create reports from the data.


General form, simple PROC SORT step:
PROC SORT DATA=SAS-data-set
            OUT=
SAS-data-set;
        BY
BY-variable(s);
RUN;

where

  • the DATA= option names the data set to be read
  • the OUT= option creates an output data set containing the data in sorted order.
  • BY-variable(s) in the required BY statement specifies one or more variables whose values are used to order the data
CAUTION: If you don't use the OUT= option, PROC SORT permanently sorts the data set specified in the DATA= option. 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.


In the following program, the PROC SORT step sorts the permanent SAS data set Clinic.Admit by the values of the variable Weight and creates the temporary SAS data set Wgtadmit. Then the PROC PRINT step prints the Wgtadmit data set.
     proc sort data=clinic.admit out=wgtadmit;
        by weight;
     run;
     proc print data=wgtadmit;
        var age height weight fee;
        where age>30;
        sum fee;
     run; 

The report displays observations in ascending order of weight.


Obs Age Height Weight Fee
2 31 61 123 149.75
3 43 65 123 124.80
4 43 63 137 149.75
6 44 66 140 149.75
7 41 67 141 149.75
9 32 67 151 149.75
10 34 66 152 124.80
11 34 73 154 124.80
12 51 71 158 124.80
13 40 69 163 124.80
15 49 64 172 124.80
16 35 70 173 149.75
17 47 72 173 124.80
18 54 71 183 149.75
20 60 71 191 149.75
        2071.60



back||next


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

Terms of Use & Legal Information | Privacy Statement