Solved
Contributor
Posts: 24

# 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?

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: 6,785

## 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).

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

## 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

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: 13,583

## 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.