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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.