BookmarkSubscribeRSS Feed
jenim514
Pyrite | Level 9

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!

 

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;

Tom
Super User Tom
Super User

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;

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