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.
Transpose to a long layout, sort by DO, and keep the first observation for each group.
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);
I want to have only one column containing dates that correspond to the minimum values of DO1 and DO2.
if do1<do2 then date=date1;
else date=date2;
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.
Transpose to a long layout, sort by DO, and keep the first observation for each group.
Thank you so much for your help.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.