BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
id       date_1           date_2              date_3
1    .                     02/02/2012     01/01/2001    
2     01/11/2009     2/10/2011     01/01/2004    
3     01/08/2013      .                      2/10/2012
4    11/10/2015     01/01/1998     26/12/2014

I am trying to the find the minimum of three dates but I have some missing information so I want to retain the minmum among the one that is avaiable:

output

1 01/01/2001

2 01/01/2004

3 02/10/2012

4 01/01/1998

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

The MIN function already handles this issue? So the following will do

 

data have;
informat date_1 date_2 date_3 ddmmyy10.;
input id date_1 date_2 date_3;
format date_1 date_2 date_3 ddmmyy10.;
datalines;
1 .          02/02/2012 01/01/2001
2 01/11/2009 2/10/2011  01/01/2004
3 01/08/2013 .          02/10/2012
4 11/10/2015 01/01/1998 26/12/2014
;

data want;
   set have;

   newvar = min(date_1,date_2,date_3);
   format newvar  ddmmyy10.;
run;

 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

The MIN function already handles this issue? So the following will do

 

data have;
informat date_1 date_2 date_3 ddmmyy10.;
input id date_1 date_2 date_3;
format date_1 date_2 date_3 ddmmyy10.;
datalines;
1 .          02/02/2012 01/01/2001
2 01/11/2009 2/10/2011  01/01/2004
3 01/08/2013 .          02/10/2012
4 11/10/2015 01/01/1998 26/12/2014
;

data want;
   set have;

   newvar = min(date_1,date_2,date_3);
   format newvar  ddmmyy10.;
run;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just to add, functions like min() can also accept ranges of variables which can make typing much easier when you have lots of variables:

newvar=min(of date_:);

Assumes of course all variables have same prefix (or you setup and array of them before).

lillymaginta
Lapis Lazuli | Level 10

Thank you! 

sas-innovate-2024.png

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.

 

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
  • 3 replies
  • 808 views
  • 5 likes
  • 3 in conversation