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

Hi, I am relatively new to SAS and stuck with a problem. For a certain type of time-to-event analysis, I need to create a new dataset from the one that I'm working with. In the original dataset, each study participant has one row of data. Assume we have a patient X who has been in our study for 5 years and has developed the event of interest in the fourth year of the study. I need to create an array for this person T1 through T5 that has the values [0 0 0 1 1], respectively. That is zeros for the three years without the event and ones for the years 4 and 5 that the event occurred. I need a way to figure out how to code this in SAS so that the system automatically does this procedure for some 60,000 patients in the dataset. Each patient has a different follow-up time [1-24 years], may or may not have experienced the event [0 and 1] and may have the event of interest at any point in time during the follow-up. Can somebody please suggest how should I go about this problem?  

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Like this? 🙂

 

data work.sample;
input ID followup event event_occur;
datalines;
1 8  0 .
2 15 1 9
3 3  0 .
4 8  0 .
5 12 1 5
;

proc sort data = sample;
   by descending followup;
run;

data _NULL_;
   set sample;
   if _N_=1 then call symput('cols',followup);
run;

%put Additional Columns: &cols;

proc sort data = sample;   
   by ID;
run;

data want;
   set sample;

   array period[&cols];
   
   i = 1;
   do until (i > followup);
      period[i] = 0;
      i + 1;
   end;

   if not missing(event_occur) then do j = event_occur to followup;
      period[j] = 1;
   end;

   drop i j;
run;

View solution in original post

7 REPLIES 7
Sina
Fluorite | Level 6

Hi, 

This is a very simple dataset of what I have in mind: 

data work.sample;
input ID followup event event_occur;
datalines;
1 8 0 .
2 15 1 9
3 3 0 .
4 8 0 .
5 12 1 5
run;

There are four variables. ID indicates patient's unique ID. followup is the total amount of time in years that the person has been in the study. The variable event indicates whether the event of interest has happened. Finally, for patients with event=1, there is a time called event_occured that shows at which year the event has occurred. For instance in patient #2, she has been in the study for 15 years and then the event of interest occurred in year 9. The Binary array for her should be: 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1

On the other hand, patient #1 should have the following binary code of 8 zeros: 0 0 0 0 0 0 0 0

PeterClemmensen
Tourmaline | Level 20

And you want this in a dataset? If I understand you correctly, then in this case you want an output dataset with 15 additional variables (max(followup)) with 0/1?

Sina
Fluorite | Level 6
Exactly! The new dataset would have additional variables equal to the maximum of the follow-up years.
PeterClemmensen
Tourmaline | Level 20

Like this? 🙂

 

data work.sample;
input ID followup event event_occur;
datalines;
1 8  0 .
2 15 1 9
3 3  0 .
4 8  0 .
5 12 1 5
;

proc sort data = sample;
   by descending followup;
run;

data _NULL_;
   set sample;
   if _N_=1 then call symput('cols',followup);
run;

%put Additional Columns: &cols;

proc sort data = sample;   
   by ID;
run;

data want;
   set sample;

   array period[&cols];
   
   i = 1;
   do until (i > followup);
      period[i] = 0;
      i + 1;
   end;

   if not missing(event_occur) then do j = event_occur to followup;
      period[j] = 1;
   end;

   drop i j;
run;

Sina
Fluorite | Level 6
Oh my god! Yes! Exactly. Thank you so very much! Appreciate your help and time!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1725 views
  • 3 likes
  • 2 in conversation