New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Dear, I have not been able to solve the following problem, hopefully you can help me. I have an ID with associated dates, and I need to sort the data by ID, descending date and count these records one by one. for instance: the table I have 

Andres_Fuentes1_0-1633364693835.png

 

and this is the result that I should get.

 

Andres_Fuentes1_1-1633364800590.png

 

 

thanks you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
proc sort data=have;
by ID descending date;
run;

data want;
set have;
by id descending date;

if first.id then number_order=1;
else number_order+1;

run;

https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/

 


@Andres_Fuentes1 wrote:

Dear, I have not been able to solve the following problem, hopefully you can help me. I have an ID with associated dates, and I need to sort the data by ID, descending date and count these records one by one. for instance: the table I have 

Andres_Fuentes1_0-1633364693835.png

 

and this is the result that I should get.

 

Andres_Fuentes1_1-1633364800590.png

 

 

thanks you.

 


 

View solution in original post

1 REPLY 1
Reeza
Super User
proc sort data=have;
by ID descending date;
run;

data want;
set have;
by id descending date;

if first.id then number_order=1;
else number_order+1;

run;

https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/

 


@Andres_Fuentes1 wrote:

Dear, I have not been able to solve the following problem, hopefully you can help me. I have an ID with associated dates, and I need to sort the data by ID, descending date and count these records one by one. for instance: the table I have 

Andres_Fuentes1_0-1633364693835.png

 

and this is the result that I should get.

 

Andres_Fuentes1_1-1633364800590.png

 

 

thanks you.

 


 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1 reply
  • 800 views
  • 0 likes
  • 2 in conversation