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!

SAS Innovate 2025: Register Now

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!

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