Hi! I'm trying to count visits with the same date and then reset count to zero when encountering new subject.
This does what I need it to do, but how can I reset to ) when encountering new subject?
proc sort data= lb4; by usubjid lbdat visitx ; run;
data want;
set have;
by subject lbdat;
if first.lbdat then vscount +1;
run;
Thanks!
Try
proc sort data= lb4; by usubjid lbdat visitx ; run;
data want;
set have;
by subject lbdat;
if first.subject then vscount=1;
else if first.lbdat then vscount +1;
run;
Use the FIRST.USUBJID variable, just like you are using the FIRST.LBDAT variable.
proc sort data= lb4;
by usubjid lbdat visitx ;
run;
data want;
set lb4;
by usubjid lbdat;
if first.usubjid then vscount=0;
vscount + first.lbdat;
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 save with the early bird rate—just $795!
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.