data awards;
input Fname$ Points Month;
datalines;
Amy 2 4
Amy 1 7
Gerard 3 3
Wang 3 3
Wang 1 12
Wang 1 8
;
proc sort data=awards;
by descending fname points;
run;
Output as
Wang 1 12
Wang 1 8
............
Why ( Wang 1 12 )but not (Wang 1 😎 as the begining record?
The variable "month" is not specified as BY variable at PROC SORT, this is why SAS will keep the original data arrangement for not specified variables.
It can be resolved by following way to get the observation (Wang 1 😎 before (Wang 1 12);
proc sort data=awards;
by descending fname points month;
run;
Because you do not sort by month. If you sort by Month also, Wang 1 8 is the first row 🙂
proc sort data=awards;
by descending fname points Month;
run;
While sorting sas maintains the original order. You sort by Fname and Point, not by month.
The variable "month" is not specified as BY variable at PROC SORT, this is why SAS will keep the original data arrangement for not specified variables.
It can be resolved by following way to get the observation (Wang 1 😎 before (Wang 1 12);
proc sort data=awards;
by descending fname points month;
run;
Input order can affect results for variables NOT on the by statement. Consider the result for :
data awards; input Fname$ Points Month; datalines; Wang 1 8 Amy 2 4 Amy 1 7 Gerard 3 3 Wang 3 3 Wang 1 12 ; proc sort data=awards; by descending fname points; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.