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!
data want;
set have;
by id date ;
if first.id then visit=1;
else if first.date then visit+1;
run;
data want;
set have;
by id date ;
if first.id then visit=1;
else if first.date then visit+1;
run;
This works- thanks so much!
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;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.