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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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