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
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;
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;
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).
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.