SAS (Base SAS)+
data CLASS;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Henry|M|14|63.5|102.5
James|M|12|57.3|83
;;;;
run;
proc sort data=class out=sorted;
by age descending height;
run;
infile datalines dlm='|' dsd missover;
input Name : $8. Sex : $1. Age : best32. Height : best32. Weight : best32.;
label ;
format ;
datalines4;
Alfred|M|14|69|112.5
Henry|M|14|63.5|102.5
James|M|12|57.3|83
;;;;
run;
proc sort data=class out=sorted;
by age descending height;
run;
- To sort a dataset in SAS, we call
proc sortand name the sort keys in abystatement. proc sort data=class out=sorted;reads from CLASS and writes the sorted result to SORTED — the input is left untouched.- Without
out=, SAS would overwrite CLASS in place, which we usually avoid in production code. by age descending height;sorts first on Age ascending, then breaks ties on Height descending.- The
descendingkeyword goes before the variable it applies to — it does not carry over to later variables. - After running, open SORTED and check the youngest subject sits on top and ties on Age fall in Height-descending order.