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

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 1Date 2Date 3
6/15/20176/14/2017 
  6/12/2017
 6/15/2017 
6/14/20176/15/20176/20/2017

 

Output should look like this

Date
6/15/2017
6/12/2017
6/15/2017
6/14/2017

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
vsing154
Calcite | Level 5

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;

 

View solution in original post

4 REPLIES 4
SuryaKiran
Meteorite | Level 14

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;

Thanks,
Suryakiran
vsing154
Calcite | Level 5

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3570 views
  • 4 likes
  • 4 in conversation