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 | |
| id | vaccine_admin_date |
| 1 | 7/1/2024 |
| 1 | 8/1/2024 |
| 1 | 9/1/2024 |
| 1 | 10/1/2024 |
| 2 | 1/2/2024 |
| 2 | 2/2/2024 |
| 2 | 3/2/2024 |
| 2 | 4/2/2024 |
| WANT | ||
| id | vaccine_admin_date | vaccine_sequence |
| 1 | 7/1/2024 | 1 |
| 1 | 8/1/2024 | 2 |
| 1 | 9/1/2024 | 3 |
| 1 | 10/1/2024 | 4 |
| 2 | 1/2/2024 | 1 |
| 2 | 2/2/2024 | 2 |
| 2 | 3/2/2024 | 3 |
| 3 | 5/4/2024 | 1 |
SQL is not the best tool here.
data want;
set have;
by id;
if first.id then vaccine_sequence=0;
vaccine_sequence+1;
run;
SQL is not the best tool here.
data want;
set have;
by id;
if first.id then vaccine_sequence=0;
vaccine_sequence+1;
run;
Thank you, this was a lot less complicated than I was making it. Appreciate it!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.