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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.