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

Hi all,

 

I have the following data structure from a big dataset with: DO1= date1- parity_date,

DO2= date2- parity_date,

 

data parity;

input animal parity_date date1 DO1 date2 DO2;

cards;

AM11024 16APR2012 15OCT2012 182 28APR2015 1107

AM11024 14MAR2013 15OCT2012 -150 28APR2015 775

AM11024 04FEB2014 15OCT2012 -477 28APR2015 448

AM11024 20JAN2015 15OCT2012 -827 28APR2015 98

run;

 

I would like to get this result:

animal parity_date date     DO

AM11024 16APR2012 15OCT2012 182

AM11024 20JAN2015 28APR2015 98

 

Grouping date1 and date2 into one variable (date) and DO1 and DO2 into DO with the following condition: with the mínimum value of DO1 and DO2.

 

Any help will be thankful.

Best regards.

1 ACCEPTED SOLUTION
6 REPLIES 6
PaigeMiller
Diamond | Level 26

Grouping date1 and date2 into one variable (date) and DO1 and DO2 into DO with the following condition: with the mínimum value of DO1 and DO2.

 

I don't understand what you mean by grouping date1 and date2 into one variable. Finding the minimum of DO1 and DO2 is done like this:

 

do = min(do1,do2);

 

--
Paige Miller
Chira85
Calcite | Level 5

I want to have only one column containing dates that correspond to the minimum values of DO1 and DO2. 

PaigeMiller
Diamond | Level 26
if do1<do2 then date=date1;
else date=date2;
--
Paige Miller
Chira85
Calcite | Level 5

Thank you for your response. I have another question, with 5 dates: date1 date2 date3 date4 date5, and 5 corresponding 5 DO: DO1, DO2, DO3, DO4, and DO5, how to do it?

 

Thank you in advance.

Chira85
Calcite | Level 5

Thank you so much for your help.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1014 views
  • 0 likes
  • 3 in conversation