BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SR11
Obsidian | Level 7

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. 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

@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.;

  

View solution in original post

8 REPLIES 8
SASKiwi
PROC Star

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

SR11
Obsidian | Level 7

Could you please tell me how can I check that?

SASKiwi
PROC Star

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;
SR11
Obsidian | Level 7

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? 

 

SASKiwi
PROC Star

@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
Obsidian | Level 7

Thank you very much. it worked. 

SR11
Obsidian | Level 7

Thank you for sharing this information. 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2779 views
  • 2 likes
  • 3 in conversation