BookmarkSubscribeRSS Feed
nanavel
Calcite | Level 5

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.

3 REPLIES 3
Reeza
Super User

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.


 

nanavel
Calcite | Level 5

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;

Reeza
Super User
Try adding the DATE to your BY statement and using FIRST.DATE instead of FIRST.ID.

There are more complicated examples in that post that illustrate how to do it within different By groupings.

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