DATA Step, Macro, Functions and more

Descending Character Months

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Descending Character Months

Given the SAS data set WORK.TEMPS:
The following program is submitted:
 
proc sort data=WORK.TEMPS:
      by descending Month Day;
run;

proc print data=WORK.TEMPS:
run; 
 
What is the output?
Answer: C
 
Why? How is C even sorted in descending order? I was thinking it would be A, since July comes after May.

Accepted Solutions
Solution
‎12-30-2015 10:29 AM
Super User
Posts: 5,516

Re: Descending Character Months

[ Edited ]

C is correct. 

 

The months are character, so alphabetical order (corresponding to ascending MONTH) would be:

 

July

June

May

 

Descending month would give you:

 

May 

June

July

 

Within each month, the observations are sorted by ascending DAY (descending only applies to one variable).  

View solution in original post


All Replies
Solution
‎12-30-2015 10:29 AM
Super User
Posts: 5,516

Re: Descending Character Months

[ Edited ]

C is correct. 

 

The months are character, so alphabetical order (corresponding to ascending MONTH) would be:

 

July

June

May

 

Descending month would give you:

 

May 

June

July

 

Within each month, the observations are sorted by ascending DAY (descending only applies to one variable).  

Contributor
Posts: 24

Re: Descending Character Months

Posted in reply to Astounding
Oh, I didn't actually think the descending would be applied to the characters themselves (thought it was the order of the dates). Makes sense though. Thanks!
Super User
Posts: 11,343

Re: Descending Character Months

This is one of the many reasons when using date, datetime or time in analysis to strongly consider making SAS date, datetime or time valued variables instead of leaving the individual components (month day year hour minute second) as separate variables of often mixed type (month=> character, day year => numeric).

Then choosing an appropriated date display format, or making a custom one, makes the output pretty.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1561 views
  • 3 likes
  • 3 in conversation