I have longitudinal data. Each participant has multiple data entries for each visit.
Unfortunately, the data does not have unique visit numbers for each participant.
For eg. Id 1 will have visit numbers 111,484,222,222, 456
And ID 2 will have to visit no’s 890, 098, 098, 450.
I would like to write a code that can assign
e.g., Id 1 visits as 111=1 ,484=2,222=3,222=3, 456=4
And I’d 2 will have visits as 890=1, 098=2, 098=2, 450=3.
This will provide consistency for all study participants for further analysis.
Any guidance will be appreciated. Thank you.
Add an enumeration/counter variable.
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
@nanavel wrote:
I have longitudinal data. Each participant has multiple data entries for each visit.
Unfortunately, the data does not have unique visit numbers for each participant.
For eg. Id 1 will have visit numbers 111,484,222,222, 456
And ID 2 will have to visit no’s 890, 098, 098, 450.
I would like to write a code that can assign
e.g., Id 1 visits as 111=1 ,484=2,222=3,222=3, 456=4
And I’d 2 will have visits as 890=1, 098=2, 098=2, 450=3.This will provide consistency for all study participants for further analysis.
Any guidance will be appreciated. Thank you.
Thank you Reeza. When I try adding an enumeration, I get it as counting variables for each datapoint per participant. For e.g. ID 1 will be numbered 1-20. Meanwhile, some of them will be same-day visits so I would want those as repeats but it does not work with this code.
proc sort data=-data have;
by id;
run;
data want;
set have;
count + 1;
by id;
if first.id then count=1;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.