BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
swayto
Fluorite | Level 6

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?

 
 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
zahir
Fluorite | Level 6

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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;
andreas_lds
Jade | Level 19

While sorting sas maintains the original order. You sort by Fname and Point, not by month.

zahir
Fluorite | Level 6

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;

ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1007 views
  • 0 likes
  • 5 in conversation