BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How does one sort records by date? I've run my data through a Proc SQL step, and output the date fields in MMDDYY10. format - can this format then be sorted by date? If not, what should I be doing instead?

Thank you in advance....looking forward to your replies.
6 REPLIES 6
Doc_Duke
Rhodochrosite | Level 12
Hmm. I'm not really sure of the question. The Filter and Query task has a tab for sorting that is pretty obvious, so I suspect that is not what you are asking. Do you want the sorted output to look like

09/17/2006
09/17/2007
09/18/2005
09/18/2006
...
?

If so, the only way I know to do that is to create a new variable that is the text representation of the date. You can do that with the PUT function,
PUT(orig_date_var,mmddyy10.) in the expression builder.

HTH
Doc Muhlbaier
deleted_user
Not applicable
Hi, Doc, and thanks for replying. What I've done, in a Proc SQL step, is to use the DATEPART function of a field that contains a SAS datea and Time value. Once I got the DATEPART value, in a PROC SORT step, I then sorted the SAS numeric date value. After that, I then had a PROC REPORT STEP, and that's where my dates go crazy. I had PROC PRINT commands after both the PROC SQL and PROC SORT, and the dates looked great. However, nothing in my report showed as being in a valid sequence, whether I used native SAS date format or an edited date format of MMDDYY10..

That's the part that's driving me nuts. Also, how might I go about putting the date into a text format to look like the format you suggested?

Thanks for responding and I look forward to hearing back from you.
Cynthia_sas
SAS Super FREQ
I wonder if your dates are going crazy because you are letting PROC REPORT think they're numeric vars that need to be grouped. For example, if you had this:
[pre]
define jobcode / group;
define hiredate / 'Hire Date';
define salary / 'Salary';
[/pre]
then the default "usage" for both hiredate and salary would be ANALYSIS, with the SUM statistic as the default.

You might want:
[pre]
define jobcode / group;
define hiredate / order order=internal 'Hire Date';
define salary / 'Salary';
[/pre]

or play around with the other possibilities for order (Internal, Formatted, Data...) which you can find in the documentation.

cynthia
deleted_user
Not applicable
Hi, Cynthia! Would that also happen if I used ORDER to try to arrange the dates in the PROC REPORT segment? I am going to play around with what you wrote...sounds interesting.

You folks (you in particular) are wonderful in the help you provide.... thank you again.
deleted_user
Not applicable
Cynthia,

Duhhhh! Please disregard my last question - my brain is definitely not awake this morning! I saw you already had ORDER in your initial reply. Sorry.....
deleted_user
Not applicable
Hi, Cynthia,

Your suggestion worked like a charm. THANK YOU!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 8742 views
  • 0 likes
  • 3 in conversation