Solved
Contributor
Posts: 47

# Time to event?

[ Edited ]

I have the following data:

ID  Wk1q1  Wk1q2  wk1q3  Wk1resp  Wk8q1   Wk8q2  wk8q3 Wk8resp  Wk12q1  Wk12q2  wk12q3 Wk16q1....

1         3             2         2            0              4            4            2           1                1              1          1          0

2         2             2         5            0              3            4            2           1                1              1          1         0

3         3             1         3            0              4            6            2           0                0              1          1         0

4         3             2         5            0              4            4            2           1                0              1          1         0

5         5             3        5            0             6            3            2            1                 0              1         1           0

6         3             2        2            0              4            4            2            1                1             0          1           0

Scores for three questions are collected for at Week 1 Week 8 Week 12 Week 16, I would like to know how long does it takes a subject to get to a score of 0 for each question (q1 q2 q3...)? How long does it take a patient to get to resp=1? Which question reaches 0 first and which one reaches last? Does q1+q2 reach 0 before q3?

Need the SAS codes to answer these questions! Thanks!

Accepted Solutions
Solution
‎08-11-2016 12:54 AM
PROC Star
Posts: 2,370

## Re: Time to event?

This may be what you want:

``````data HAVE;
input ID    Wk1q1  Wk1q2  wk1q3  Wk1resp  Wk8q1   Wk8q2  wk8q3 Wk8resp  Wk12q1  Wk12q2  wk12q3   Wk16q1    ;
cards;
1       3       2       2       0       4       4       2       1       1       1       1       0
2       2       2       5       0       3       4       2       1       1       1       1       0
3       3       1       3       0       4       6       2       0       0       1       1       0
4       3       2       5       0       4       4       2       1       0       1       1       0
5       5       3       5       0       6       3       2       1       0       1       1       0
6       3       2       2       0       4       4       2       1       1       0       1       0
run;

data WANT;
set HAVE;
WEEK_Q1   = whichn(0,WK1Q1,WK8Q1,WK12Q1,WK16Q1);
if WEEK_Q1 then LENGTH_Q1 = choosen(WEEK_Q1,1,8,12,16);

WEEK_Q2   = whichn(0,WK1Q2,WK8Q2,WK12Q2,WK16Q2);
if WEEK_Q2 then LENGTH_Q2 = choosen(WEEK_Q2,1,8,12,16);

WEEK_Q3   = whichn(0,WK1Q3,WK8Q3,WK12Q3,WK16Q3);
if WEEK_Q3 then LENGTH_Q3 = choosen(WEEK_Q3,1,8,12,16);
putlog ID= LENGTH_Q1= LENGTH_Q2= LENGTH_Q3=;
run;``````

ID=1 LENGTH_Q1=16 LENGTH_Q2=. LENGTH_Q3=.

ID=2 LENGTH_Q1=16 LENGTH_Q2=. LENGTH_Q3=.

ID=3 LENGTH_Q1=12 LENGTH_Q2=. LENGTH_Q3=.

ID=4 LENGTH_Q1=12 LENGTH_Q2=. LENGTH_Q3=.

ID=5 LENGTH_Q1=12 LENGTH_Q2=. LENGTH_Q3=.

ID=6 LENGTH_Q1=16 LENGTH_Q2=12 LENGTH_Q3=.

All Replies
Contributor
Posts: 47

## Time to event?

I have the following data:

ID  Wk1q1  Wk1q2  wk1q3  Wk1resp  Wk8q1   Wk8q2  wk8q3 Wk8resp  Wk12q1  Wk12q2  wk12q3 Wk16q1....

1         3             2         2            0              4            4            2           1                1              1          1          0

2         2             2         5            0              3            4            2           1                1              1          1         0

3         3             1         3            0              4            6            2           0                0              1          1         0

4         3             2         5            0              4            4            2           1                0              1          1         0

5         5             3        5            0             6            3            2            1                 0              1         1           0

6         3             2        2            0              4            4            2            1                1             0          1           0

Scores for three questions are collected for at Week 1 Week 8 Week 12 Week 16, I would like to know how long does it takes a subject to get to a score of 0 for each question (q1 q2 q3...)? How long does it take a patient to get to resp=1? Which question reaches 0 first and which one reaches last? Does q1+q2 reach 0 before q3?

Need the SAS codes to answer these questions! Thanks!

Super User
Posts: 13,583

## Re: Time to event?

What have you attempted so far?

Contributor
Posts: 47

## Re: Time to event?

Well i was thinking that I would need to create three new variables that indicate the time frame in association with the scores

so like:

wk1    wk8   wk12    wk16

1           8        12       16

1           8        12       16

1           8        12       16

and use a proc lifetest at where q1 reaches 0, q2 and so on...

proc lifetest data=dataset(where=(q1=1)) plots=hazard(bw=200);
time wk1*q1(0);
run;

PROC Star
Posts: 2,370

## Re: Time to event?

What would the output look like for the sample posted?

Please ensure the result you are posting is perfectly correct.

Contributor
Posts: 47

## Re: Time to event?

If I am not mistaken, the result will be a Kaplan meier curve (Cox proportional hazard model)....

I am just unsure how to create the code based off my variables to acheive the curve...

PROC Star
Posts: 2,370

## Re: Time to event?

Sorry, let me rephrase.

What would the columns and calculated values be for the desired calculations on the sample provided?

Contributor
Posts: 47

## Re: Time to event?

length_q1     length_q2    length_q3.......length_resp

8                  8                  16                     16

8                 12                 .                         8

12                 .                  16                        .

8                 8                  16                       8

So basically for each question....I would need to know for each patient in what week they got a score of 0, as well as, when they got resp=1. Of course there will be times where the subjects did not acheive 0 by the end of the 16 weeks for 1 or more of the questions or achieve resp=1. Perhaps doing a kaplan meier model (with median achieving responding times) is the best analysis for answering my questions? But with the way by data is set up I am lost on how to SAS code it....

PROC Star
Posts: 2,370

## Re: Time to event?

There is no ID column in the output provided.

If the first row is for ID=1, why isn't length_q1=16 since it seems that's the outcome (value =0) in the provided sample?

ID Wk1q1 Wk1q2 wk1q3 Wk1resp Wk8q1 Wk8q2 wk8q3 Wk8resp Wk12q1 Wk12q2 wk12q3 Wk16q1

1     3     2    2            4      4      2      1         1      1      0

Contributor
Posts: 47

## Re: Time to event?

you are correct. it is 16. the example of my output did not correspond accuratly to my dataset. apologies .

so  subj          length_q1

1               16

2                16

3                12

4                12

Solution
‎08-11-2016 12:54 AM
PROC Star
Posts: 2,370

## Re: Time to event?

This may be what you want:

``````data HAVE;
input ID    Wk1q1  Wk1q2  wk1q3  Wk1resp  Wk8q1   Wk8q2  wk8q3 Wk8resp  Wk12q1  Wk12q2  wk12q3   Wk16q1    ;
cards;
1       3       2       2       0       4       4       2       1       1       1       1       0
2       2       2       5       0       3       4       2       1       1       1       1       0
3       3       1       3       0       4       6       2       0       0       1       1       0
4       3       2       5       0       4       4       2       1       0       1       1       0
5       5       3       5       0       6       3       2       1       0       1       1       0
6       3       2       2       0       4       4       2       1       1       0       1       0
run;

data WANT;
set HAVE;
WEEK_Q1   = whichn(0,WK1Q1,WK8Q1,WK12Q1,WK16Q1);
if WEEK_Q1 then LENGTH_Q1 = choosen(WEEK_Q1,1,8,12,16);

WEEK_Q2   = whichn(0,WK1Q2,WK8Q2,WK12Q2,WK16Q2);
if WEEK_Q2 then LENGTH_Q2 = choosen(WEEK_Q2,1,8,12,16);

WEEK_Q3   = whichn(0,WK1Q3,WK8Q3,WK12Q3,WK16Q3);
if WEEK_Q3 then LENGTH_Q3 = choosen(WEEK_Q3,1,8,12,16);
putlog ID= LENGTH_Q1= LENGTH_Q2= LENGTH_Q3=;
run;``````

ID=1 LENGTH_Q1=16 LENGTH_Q2=. LENGTH_Q3=.

ID=2 LENGTH_Q1=16 LENGTH_Q2=. LENGTH_Q3=.

ID=3 LENGTH_Q1=12 LENGTH_Q2=. LENGTH_Q3=.

ID=4 LENGTH_Q1=12 LENGTH_Q2=. LENGTH_Q3=.

ID=5 LENGTH_Q1=12 LENGTH_Q2=. LENGTH_Q3=.

ID=6 LENGTH_Q1=16 LENGTH_Q2=12 LENGTH_Q3=.

Contributor
Posts: 47