SAS 9.4:
I am trying to count enrollment orders where an individual can enroll multiple times in multiple groups. In this case, I'd like to count the enrollment order for each group separately. Using the by statement with first.id, I can count the OVERALL enrollment order. But I'd like to count an enrollment in a different group as a completely new enrollment, even if this individual had already enrolled in a different group. So, in the example below, dataline 2 where id 1001 enrolled in group 2 should be given an enrollment order of 1. (If you run the example below, it's not working that way)
...and without using a concatenation of id and group.
data test;
input id group date;
datalines;
1001 1 22100
1001 2 22200
1001 1 22300
1001 1 22400
1002 2 22500
1002 2 22600
1002 2 22700
;
run;
proc sort data = test;
by id group date;
run;
data test;
set test;
by id group;
if (first.id) and (first.group) then enroll_ord = 1;
else enroll_ord + 1;
proc print; run;
First.id is not true (=1) when this is not a new id. You only need first.group :
data test;
set test;
by id group;
if first.group
then enroll_ord = 1;
else enroll_ord + 1;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.