Hello,
I'm have a dataset with 3 columns of dates. What I would like to do is create one single column which prioritizes putting Date 1 in it, but if Date 1 is missing it places Date 2 into the new column and finally if both Date 1 and Date 2 are missing it places Date 3 into the new column.
Date 1 | Date 2 | Date 3 |
6/15/2017 | 6/14/2017 | |
6/12/2017 | ||
6/15/2017 | ||
6/14/2017 | 6/15/2017 | 6/20/2017 |
Output should look like this
Date |
6/15/2017 |
6/12/2017 |
6/15/2017 |
6/14/2017 |
Thank you!
proc sql;
select case
when date1 ne . then date1
when date1=. and date2 ne . then date 2
when date1=. and date2=. then date3
end as date from table;
quit;
date=coalesce (of date1--date3);
You can use IF THEN condition.
IF NOT MISSING(DATE1) THEN DATE=DATE1;
ELSE IF MISSING(DATE1) AND NOT MISSING(DATE2) THEN DATE=DATE2;
ELSE DATE=DATE3;
proc sql;
select case
when date1 ne . then date1
when date1=. and date2 ne . then date 2
when date1=. and date2=. then date3
end as date from table;
quit;
Thank you!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.