Data:
id | month1 | month2 | month3 | month4 | month5 | month6 |
---|---|---|---|---|---|---|
01 | 0 | 1 | 0 | 1 | 1 | 0 |
02 | 0 | 0 | 0 | 1 | 1 | 0 |
03 | 0 | 1 | 1 | 0 | 1 | 0 |
04 | 0 | 0 | 1 | 1 | 1 | 0 |
05 | 0 | 1 | 1 | 1 | 1 | 0 |
06 | 0 | 1 | 1 | 1 | 1 | 0 |
Output:
# of spells: 8
Avg. Length: 2.375
Median: 2
Max: 4
Min: 1
Frequency Table
Freq | # |
---|---|
1 | 2 |
2 | 3 |
3 | 1 |
4 | 2 |
The idea is that I want to treat this as survival data but I don't have a count of time. Thank you all in advance!
Change your data structure as a starting point:
data have;
input id $2 month1 month2 month3 month4 month5 month6;
cards;
01 0 1 0 1 1 0
02 0 0 0 1 1 0
03 0 1 1 0 1 0
04 0 0 1 1 1 0
05 0 1 1 1 1 0
06 0 1 1 1 1 0
;
run;
data spells;
set have;
array months (6) month1-month6;
spell=0; duration=0;
do i=1 to 6;
if months(i)=1 then duration+1;
else if months(i)=0 and duration>0 then do;
spell+1;
output;
duration=0;
end;
end;
keep id spell duration;
run;
Change your data structure as a starting point:
data have;
input id $2 month1 month2 month3 month4 month5 month6;
cards;
01 0 1 0 1 1 0
02 0 0 0 1 1 0
03 0 1 1 0 1 0
04 0 0 1 1 1 0
05 0 1 1 1 1 0
06 0 1 1 1 1 0
;
run;
data spells;
set have;
array months (6) month1-month6;
spell=0; duration=0;
do i=1 to 6;
if months(i)=1 then duration+1;
else if months(i)=0 and duration>0 then do;
spell+1;
output;
duration=0;
end;
end;
keep id spell duration;
run;
Thank you. I now better understand how to use arrays; they are a powerful tool!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.