DATA Step, Macro, Functions and more

Create a counter variable

Accepted Solution Solved
Reply
Super Contributor
Posts: 303
Accepted Solution

Create a counter variable

[ Edited ]

I have this data set and I want to create a count variable for number of time in hospital;

 

Id            date                               

001         01/07/17 

001         03/07/17

002         01/07/17

003         02/01/17

003         04/05/17

004         05/05/17

;

I want to create a third variable number of visit such that the data becomes;

 

Id            date                number_visit                   

001         01/07/17                  1

001         03/07/17                  2

002         01/07/17                  1

003         02/01/17                  1

003         04/05/17                  2

004         05/05/17                  1

 

best.

 

 


Accepted Solutions
Solution
‎04-26-2017 01:54 PM
Super User
Posts: 19,878

Re: Create a counter variable

[ Edited ]
Posted in reply to desireatem

All Replies
Solution
‎04-26-2017 01:54 PM
Super User
Posts: 19,878

Re: Create a counter variable

[ Edited ]
Posted in reply to desireatem
Trusted Advisor
Posts: 1,137

Re: Create a counter variable

Posted in reply to desireatem

alternatively, you could also try the proc sql monotonic()

 

proc sql;
create table want as select *, (monotonic()-min(monotonic())+1) as number_visit from have group by id;
quit;
Thanks,
Jag
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 1518 views
  • 2 likes
  • 3 in conversation