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! 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1481 views
  • 5 likes
  • 3 in conversation