BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bkq32
Quartz | Level 8

I have a dataset with indicators for if a given person was enrolled in a program at various months. I want to create a variable "full" that specifies the month that marks a person's first 3 continuous months of enrollment (i.e. I want to identify the first  set of "1 1 1 " values that occurs per row). Any suggestions?

 

data have;
 input person $ month_01 month_02 month_03 month_04 month_05 month_06;
 cards;
A 1 1 1 1 1 1
B 1 0 1 1 1 1
C 0 0 1 1 1 1
D 0 0 0 0 0 1
E 1 1 0 1 1 1
;
run;


data want;
 input person $ month_01 month_02 month_03 month_04 month_05 month_06 full;
 cards;
A 1 1 1 1 1 1 3
B 1 0 1 1 1 1 5
C 0 0 1 1 1 1 5
D 0 0 0 0 0 1 .
E 1 1 0 1 1 1 6
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
data have;
 input person $ month_01 month_02 month_03 month_04 month_05 month_06;
 length m $6 p $3;
 m=cats(of month:);
 p='111';
 f=find(m,p);
 if f then full=f+length(p)-1;
 cards;
A 1 1 1 1 1 1
B 1 0 1 1 1 1
C 0 0 1 1 1 1
D 0 0 0 0 0 1
E 1 1 0 1 1 1
;
run;
proc print;
   run;

 Capture.PNG

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19
data have;
 input person $ month_01 month_02 month_03 month_04 month_05 month_06;
 length m $6 p $3;
 m=cats(of month:);
 p='111';
 f=find(m,p);
 if f then full=f+length(p)-1;
 cards;
A 1 1 1 1 1 1
B 1 0 1 1 1 1
C 0 0 1 1 1 1
D 0 0 0 0 0 1
E 1 1 0 1 1 1
;
run;
proc print;
   run;

 Capture.PNG

bkq32
Quartz | Level 8
Thank you!

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