BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

The problem with the solution from @mkeintz is that it turns dates into character variables, which sort alphabetically, and so then you have to resort to adding in a sequence number at the start to force it to sort chronologically. The '25: ' or similar at the start is meaningless; no one knows what the 25 means but it takes up space and it confuses people.

 

If you use custom formats via PROC FCMP, or even the simple MONYY. format, then the values can be sorted chronologically, and thus it is not only simpler, but easier for humans to read.

--
Paige Miller
mkeintz
PROC Star

@PaigeMiller wrote:

The problem with the solution from @mkeintz is that it turns dates into character variables, which sort alphabetically, and so then you have to resort to adding in a sequence number at the start to force it to sort chronologically. The '25: ' or similar at the start is meaningless; no one knows what the 25 means but it takes up space and it confuses people.

 

If you use custom formats via PROC FCMP, or even the simple MONYY. format, then the values can be sorted chronologically, and thus it is not only simpler, but easier for humans to read.


@PaigeMiller 's criticism of the text variable shortcomings is right of course, but in this case not until July 2028, when the alphabetic sort will fail to replicate chronological order..

 

Until then, I can hide behind the OP's literal request, because each salesperiod text value starts with a two-digit (z2. format) enumerated date range (01 for 06apr2020-05may2020, etc.).  This will replicate date order until range number 100 occurs - (July 2028 I think) when three digits will be needed.

 

I guess one could extend my solution by using Z3. format (and modifying accordingly the VALUE statement for the irregular historic date ranges).  That would provide another 900 months (July 2104).  So there can be wiggle room.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 1931 views
  • 6 likes
  • 8 in conversation