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!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.