BookmarkSubscribeRSS Feed
Utabikunda
Calcite | Level 5

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;

 

1 REPLY 1
PGStats
Opal | Level 21

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;
PG

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 280 views
  • 0 likes
  • 2 in conversation