BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smeeker
Calcite | Level 5

I am working with a dataset that has vaccine administration dates and repeats the entire row each time there is a new vaccine. I'm trying to analyze the data, but it's becoming difficult when I have 5 rows with all of the same info except for the vaccine_admin_date. I am wanting to create a sequence variable that starts with 1 and restarts its counting with each new 'id'. Unfortunately, there is no "partition by" in proc sql - I can't seem to find a solution.  

HAVE 
idvaccine_admin_date
17/1/2024
18/1/2024
19/1/2024
110/1/2024
21/2/2024
22/2/2024
23/2/2024
24/2/2024

 

WANT  
idvaccine_admin_datevaccine_sequence
17/1/20241
18/1/20242
19/1/20243
110/1/20244
21/2/20241
22/2/20242
23/2/20243
35/4/20241
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

SQL is not the best tool here.

 

data want;
    set have;
    by id;
    if first.id then vaccine_sequence=0;
    vaccine_sequence+1;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

SQL is not the best tool here.

 

data want;
    set have;
    by id;
    if first.id then vaccine_sequence=0;
    vaccine_sequence+1;
run;
--
Paige Miller
smeeker
Calcite | Level 5

Thank you, this was a lot less complicated than I was making it. Appreciate it!

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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