BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
brettmullga
Calcite | Level 5

Data:

idmonth1month2month3month4month5month6
01010110

02

000110
03011010
04001110
05011110
06011110

Output:

# of spells: 8

Avg. Length: 2.375

Median: 2

Max: 4

Min: 1

Frequency Table

Freq#
12
23
31
42

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

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;

brettmullga
Calcite | Level 5

Thank you. I now better understand how to use arrays; they are a powerful tool!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

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