BookmarkSubscribeRSS Feed
mandyosu01
Obsidian | Level 7

Hello,


I want to sort years in column sequentially. For example, 


Data have 

id  year
1 1998
1 1998
1 1999
1 1999
1 2000
1 2000
1 2000
1 2000
1 2001



Data want

id  year
1 1998
1 1999
1 2000
1 2001
1 1998
1 1999
1 2000
1 2000
1 2000

 

Thank you so much!

2 REPLIES 2
Astounding
PROC Star

You'll need to add a variable to indicate the proper order.  For example:

data want;
   set have;
   by id year;
   if first.year then order=1;
   else order + 1;
run;

Then all you need to do is sort the data:

proc sort data=want;
   by id order year;
run;
Reeza
Super User
FYI - I edited your question to remove the spoiler under the assumption that it was erroneously added.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 2 replies
  • 334 views
  • 3 likes
  • 3 in conversation