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

I am working with a dataset that has a about 10 variables for different treatments. If a patient underwent a particular treatment, then that treatment's variable has a date and the rest of the treatment variables are null. I want to make a new variable so that whichever treatment a patient underwent, the corresponding value is posted to a new variable. 

 

Example:

Obs  TrtA     TrtB3           TrtGh     TrtE8

1         .       01/01/2019       .          .

2         .             .           01/04/2019   .

3         .       01/12/2019       .          .

 

I want the output to look like:

Obs         Trt_date

1              01/01/2019

2              01/04/2019              

3              01/12/2019

 

I am completely stuck after trying multiple if statements, treating each variable individually and together, and nothing is working. Please help!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Have you tried the COALESCE() function?

 


@dikshar wrote:

I am working with a dataset that has a about 10 variables for different treatments. If a patient underwent a particular treatment, then that treatment's variable has a date and the rest of the treatment variables are null. I want to make a new variable so that whichever treatment a patient underwent, the corresponding value is posted to a new variable. 

 

Example:

Obs  TrtA     TrtB3           TrtGh     TrtE8

1         .       01/01/2019       .          .

2         .             .           01/04/2019   .

3         .       01/12/2019       .          .

 

I want the output to look like:

Obs         Trt_date

1              01/01/2019

2              01/04/2019              

3              01/12/2019

 

I am completely stuck after trying multiple if statements, treating each variable individually and together, and nothing is working. Please help!


 

View solution in original post

2 REPLIES 2
Reeza
Super User

Have you tried the COALESCE() function?

 


@dikshar wrote:

I am working with a dataset that has a about 10 variables for different treatments. If a patient underwent a particular treatment, then that treatment's variable has a date and the rest of the treatment variables are null. I want to make a new variable so that whichever treatment a patient underwent, the corresponding value is posted to a new variable. 

 

Example:

Obs  TrtA     TrtB3           TrtGh     TrtE8

1         .       01/01/2019       .          .

2         .             .           01/04/2019   .

3         .       01/12/2019       .          .

 

I want the output to look like:

Obs         Trt_date

1              01/01/2019

2              01/04/2019              

3              01/12/2019

 

I am completely stuck after trying multiple if statements, treating each variable individually and together, and nothing is working. Please help!


 

ballardw
Super User

If your description that only one of the trt variables has value then this should work:

 

data want;
  set have;
  array t{10} trtb3 trtgh trte8 <finish the list>;
  trt_date = max( of t(*));
  format trt_date mmddyy10.;
run;