BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abc44
Obsidian | Level 7

Hi all, 

 

I have a relatively simple task I need some help with. 

 

I would like to assign a visit # to assessments that were performed on different dates for the same subject ID. Does someone know how I can generate this 3rd column called visit? 

 

ID    Date             Visit

1     01/02/2018     1

1     01/02/2018     1

1     01/02/2018     1

1     01/02/2018     1

1     08/08/2018     2

1     08/08/2018     2

1     08/08/2018     2

2     04/03/2018     1

2     04/03/2018     1

2     04/03/2018     1

2     09/09/2018     2

2     09/09/2018     2

etc. 

 

I basically need to assign a visit number per date within each subject ID, but am struggling with the code. 

 

I look forward to your feedback!
Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want;
set have;
by id date ;
if first.id then visit=1;
else if first.date then visit+1;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data want;
set have;
by id date ;
if first.id then visit=1;
else if first.date then visit+1;
run;
abc44
Obsidian | Level 7

This works- thanks so much!

novinosrin
Tourmaline | Level 20

a teaser fun i learned from genius PD's dazzle playing with  PDV . Don't use this, but play with it. It's a joy as it gives an intuition of how DOW works 🙂

 

data want1;
if 0 then set have;
visit=0;
do until(last.id);
visit+1;
do until(last.date);
set have;
by id date;
output;
end;
end;
run;

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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