Previous Page | Next Page

The SORT Procedure

Example 3: Maintaining the Relative Order of Observations in Each BY Group


Procedure features:

PROC SORT statement option:

EQUALS | NOEQUALS

Other features: PROC PRINT

This example


Program

 Note about code
options nodate pageno=1 linesize=80 pagesize=60;
 Note about code
data insurance;
   input YearsWorked 1 InsuranceID 3-5;
   datalines;
5 421
5 336
1 209
1 564
3 711
3 343
4 212
4 616
;
 Note about code
proc sort data=insurance out=byyears1 equals;
 Note about code
   by yearsworked;
run;
 Note about code
proc print data=byyears1;
 Note about code
   var yearsworked insuranceid;
 Note about code
   title 'Sort with EQUALS';
run;
 Note about code
proc sort data=insurance out=byyears2 noequals;
 Note about code
   by yearsworked;
run;
 Note about code
proc print data=byyears2;
 Note about code
   var yearsworked insuranceid;
 Note about code
   title 'Sort with NOEQUALS';
run;

Output

 Note about figure
                                Sort with EQUALS                                       1

                                   Years    Insurance
                           Obs    Worked        ID

                            1        1         209   
                            2        1         564   
                            3        3         711   
                            4        3         343   
                            5        4         212   
                            6        4         616   
                            7        5         421   
                            8        5         336   
                               Sort with NOEQUALS                              2

                                   Years    Insurance
                           Obs    Worked        ID

                            1        1         209   
                            2        1         564   
                            3        3         343   
                            4        3         711   
                            5        4         212   
                            6        4         616   
                            7        5         421   
                            8        5         336   

Previous Page | Next Page | Top of Page