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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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