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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 799 views
  • 0 likes
  • 3 in conversation