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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.