BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
nwang5
Obsidian | Level 7

Hi SAS community,

I hope you are doing well. When conducting survival analysis, I used two ways to define the endpoint of the study period:

1. Individuals who are diagnosed with depression during the study period can be defined as the endpoint.
2. Alternatively, individuals who do not have depression at the end of the study period can be defined as the endpoint.
I was wondering how I could calculate my survival time.

Thanks for all your help! 

 

This is original data:

idauniq depression wave
100052 0 3
100052 0 4
100052 0 5
100052 0 6
100052 0 7
100052 0 8
100052 0 9
100055 0 3
100055 0 4
100055 0 5
100055 0 6
100055 0 7
100055 0 8
100057 0 3
100057 0 4
100057 0 5
100057 0 6
100057 0 7
100057 0 8
100057 0 9
100059 0 3
100059 0 4
100059 1 5
100061 0 3
100061 1 4
100061 0 5
100061 0 6
100068 0 3
100068 0 5
100068 0 6
100068 1 7
100080 0 3
100080 0 5
100081 0 3
100081 0 4
100081 0 5
100081 0 6
100081 1 7

 

This is results what is expect:

idauniq depression wave Time censor
100052 0 9 12 0
100055 0 8 10 0
100057 0 9 12 0
100059 1 5 4 1
100061 0 4 2 0
100068 1 7 8 1
100080 0 5 4 0
100081 1 7 8 1

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
Jade | Level 19

You can follow a SET statement with

  by idauniq ;

which allows you to determine if the observation-in-hand is the first (or last) obs for a given idauniq.

 

You will output one obs per idauniq.  It will be either the last obs (if there are no preceding depression obs) or else the first obs with depressio=1:

 

data have;
  input idauniq	depression	wave;
datalines;
100052	0	3
100052	0	4
100052	0	5
100052	0	6
100052	0	7
100052	0	8
100052	0	9
100055	0	3
100055	0	4
100055	0	5
100055	0	6
100055	0	7
100055	0	8
100057	0	3
100057	0	4
100057	0	5
100057	0	6
100057	0	7
100057	0	8
100057	0	9
100059	0	3
100059	0	4
100059	1	5
100061	0	3
100061	1	4
100061	0	5
100061	0	6
100068	0	3
100068	0	5
100068	0	6
100068	1	7
100080	0	3
100080	0	5
100081	0	3
100081	0	4
100081	0	5
100081	0	6
100081	1	7
run;
data want (drop=n_dep);
  set have ;
  by idauniq ;
  if first.idauniq then n_dep=0;
  n_dep+depression;
  if (n_dep=1 and depression=1) or (n_dep=0 and last.idauniq=1);
  time=2*(wave-3);
run;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

3 REPLIES 3
mkeintz
Jade | Level 19

And what is the rule by which you calculate the TIME variable?

 

For instance, for ID 100052, you start with 

idauniq depression wave
100052 0 3
100052 0 4
100052 0 5
100052 0 6
100052 0 7
100052 0 8
100052 0 9

 

From that you get

idauniq depression wave Time censor
100052 0 9 12 0

 

How did you get time=12?

 

 

Also, if an individual has depression=1 in a given wave, does that mean you will ignore subsequent waves for that individual?  For instance, see

 

 

idauniq depression wave
100061 0 3
100061 1 4
100061 0 5
100061 0 6
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
nwang5
Obsidian | Level 7
Thanks for your questions.
I am sorry that I did not mention that this study was conducted every two years. I started using wave 3. The time between wave3 to wave 4 is two years. (Wave9- wave3) *2=12

Yes, if an individual has depression=1 in a given wave, I will ignore subsequent waves for that individual.

Thanks!
mkeintz
Jade | Level 19

You can follow a SET statement with

  by idauniq ;

which allows you to determine if the observation-in-hand is the first (or last) obs for a given idauniq.

 

You will output one obs per idauniq.  It will be either the last obs (if there are no preceding depression obs) or else the first obs with depressio=1:

 

data have;
  input idauniq	depression	wave;
datalines;
100052	0	3
100052	0	4
100052	0	5
100052	0	6
100052	0	7
100052	0	8
100052	0	9
100055	0	3
100055	0	4
100055	0	5
100055	0	6
100055	0	7
100055	0	8
100057	0	3
100057	0	4
100057	0	5
100057	0	6
100057	0	7
100057	0	8
100057	0	9
100059	0	3
100059	0	4
100059	1	5
100061	0	3
100061	1	4
100061	0	5
100061	0	6
100068	0	3
100068	0	5
100068	0	6
100068	1	7
100080	0	3
100080	0	5
100081	0	3
100081	0	4
100081	0	5
100081	0	6
100081	1	7
run;
data want (drop=n_dep);
  set have ;
  by idauniq ;
  if first.idauniq then n_dep=0;
  n_dep+depression;
  if (n_dep=1 and depression=1) or (n_dep=0 and last.idauniq=1);
  time=2*(wave-3);
run;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 266 views
  • 0 likes
  • 2 in conversation