SAS (Base SAS)+
data sort_missing;
input id $ score;
datalines;
A 85
B .
C 90
D 70
E .
F 95
G 80
;
run;
proc sort data=sort_missing out=sorted;
by score;
run;- In SAS, missing values are treated as smaller than any number in ascending order.
proc sort data=sort_missing out=sorted; by score;sorts on score ascending and writes the sorted rows to SORTED.- Because missing is the smallest value, the two rows with
.come out first, followed by the numeric scores in increasing order. - For descending sort,
by descending score;flips the order and the missing-value rows drop to the bottom. - This behaviour is built into PROC SORT — we never have to code a special rule to get NAs first.
- After running, open SORTED and confirm the two missing rows sit at the top.