I used previously proc sort statement by Date in a similar type of data. And it worked.
But now, I want to sort my new data by date. But the code is not working.
Data I have:
ID Med Date
1 A 7/8/2016
1 B 9/8/2019
1 F 10/11/2014
2 R 7/6/2015
2 E 6/8/2011
3 F 12/25/2012
3 F 11/10/2018
3 G 12/18/2010
4 B 4/5/2016
Data I want:
ID Med Date
3 G 12/18/2010
2 E 6/8/2011
3 F 12/25/2012
1 F 10/11/2014
2 R 7/6/2015
4 B 4/5/2016
1 A 7/8/2016
3 F 11/10/2018
1 B 9/8/2019
Thank you for your time.
@SR11 - you should convert the character date to a proper SAS date using the INPUT function:
Date_Num = input(date, mmddyy10.);
format Date_Num mmddyy10.;
@SR11 - Check the type of variable Date is. If it is character then sorting will not be in chronological order. You need to ensure Date is stored as a numeric to sort correctly.
Could you please tell me how can I check that?
Run this code for your dataset (replace MyDatasetName with your one) and it will tell you the type of your variables:
proc contents data = MyDatasetName;
run;
Thanks for the code.
Yes, this is a character variable. Could you please tell me how can I change it to a numerical variable? or any other way to sort the data by date?
@SR11 - you should convert the character date to a proper SAS date using the INPUT function:
Date_Num = input(date, mmddyy10.);
format Date_Num mmddyy10.;
Thank you very much. it worked.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
Thank you for sharing this information.
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!
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.