Good night my friends:
After many days obtaining results, thank to all of you, i continue some research looking for answers and complete some information to use.
i have this dataset:
Animal | DAM | ANIMAL_BIRTH_DATE |
6191 | 5495 | 7/26/2007 |
6191.1 | 5495 | 7/26/2007 |
6393 | 5501 | 8/15/2007 |
6394 | 5501 | 8/15/2007 |
6563 | 5501 | 8/5/2008 |
6564 | 5501 | 8/5/2008 |
6844 | 5501 | 10/10/2009 |
6845 | 5501 | 10/10/2009 |
7361.1 | 5501 | 1/4/2012 |
7362 | 5501 | 1/4/2012 |
6463.1 | 5757 | 7/24/2008 |
6843.1 | 5757 | 10/10/2009 |
6843 | 5757 | 10/10/2009 |
You can see in the column 1 (Animal), column 2 (DAM) and column 3 (Date of birth of the animal), here is the question:
i need to obtain one more colum, this new colum will be called as Perturition_Number, and i will explain how it will be creatd this,
In this example i'll use the head of our data set:
Animal | DAM | ANIMAL_BIRTH_DATE |
6191 | 5495 | 7/26/2007 |
6191.1 | 5495 | 7/26/2007 |
Here the animal, 6191 was born as 7/26/2007, from the DAM 5495, is means the year 2007 the DAM had 2 offprings, and just this year, the objective is obtain this table:
Parturition_Order | Animal | DAM | ANIMAL_BIRTH_DATE |
1 | 6191 | 5495 | 7/26/2007 |
1 | 6191.1 | 5495 | 7/26/2007 |
based in this little example; the full data set to obtain would be like this:
Parturition_Order | Animal | DAM | ANIMAL_BIRTH_DATE |
1 | 6191 | 5495 | 7/26/2007 |
1 | 6191.1 | 5495 | 7/26/2007 |
1 | 6393 | 5501 | 8/15/2007 |
1 | 6394 | 5501 | 8/15/2007 |
2 | 6563 | 5501 | 8/5/2008 |
2 | 6564 | 5501 | 8/5/2008 |
3 | 6844 | 5501 | 10/10/2009 |
3 | 6845 | 5501 | 10/10/2009 |
4 | 7361.1 | 5501 | 1/4/2012 |
4 | 7362 | 5501 | 1/4/2012 |
1 | 6463.1 | 5757 | 7/24/2008 |
2 | 6843.1 | 5757 | 10/10/2009 |
2 | 6843 | 5757 | 10/10/2009 |
Hopeing to obtain your advices and help, i send big hugs from Brazil
Thank You
data have;
input Animal DAM ANIMAL_BIRTH_DATE :anydtdte.;
format ANIMAL_BIRTH_DATE mmddyy10.;
datalines;
6191 5495 7/26/2007
6191.1 5495 7/26/2007
6393 5501 8/15/2007
6394 5501 8/15/2007
6563 5501 8/5/2008
6564 5501 8/5/2008
6844 5501 10/10/2009
6845 5501 10/10/2009
7361.1 5501 1/4/2012
7362 5501 1/4/2012
6463.1 5757 7/24/2008
6843.1 5757 10/10/2009
6843 5757 10/10/2009
;
data want;
set have;
by dam ANIMAL_BIRTH_DATE notsorted;
if first.dam and first.ANIMAL_BIRTH_DATE then Parturition_Order=0;
if ANIMAL_BIRTH_DATE ne lag(ANIMAL_BIRTH_DATE) then Parturition_Order+1;
run;
data want ;set have;
retain Parturition_Order;
by DAM ANIMAL_BIRTH_DATE notsorted;
If first.DAM then Parturition_Order=1;
Else if first.ANIMAL_BIRTH_DATE then Parturition_Order = Parturition_Order +1;
run;
data have;
infile cards dsd;
informat ANIMAL_BIRTH_DATE mmddyy10.;
format ANIMAL_BIRTH_DATE mmddyy10.;
input Animal DAM ANIMAL_BIRTH_DATE;
cards;
6191,5495,7/26/2007
6191.1,5495,7/26/2007
6393,5501,8/15/2007
6394,5501,8/15/2007
6563,5501,8/5/2008
6564,5501,8/5/2008
6844,5501,10/10/2009
6845,5501,10/10/2009
7361.1,5501,1/4/2012
7362,5501,1/4/2012
6463.1,5757,7/24/2008
6843.1,5757,10/10/2009
6843,5757,10/10/2009
;
run;
proc sort data=have;by dam animal_birth_date animal;
data want;
set have;
by dam animal_birth_date animal;
if first.animal_birth_date then count +1;
if first.dam then count = 1;
run;
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.