My SAS friends:
I come to claim your help, to solve this problem:
Our Coleage PGstat, helped me a lot, and he haz constructed this command to solve the first part of the problem:
The data set is here:
data pn;
input ANIMAL DAM SIRE DAM_BORN_DATE:mmddyy. ANIMAL_BIRTH_DATE:mmddyy. ANIMAL_BIRTH_TYPE ANIMAL_BIRTH_WEIGHT SEX$ ;
format animal_birth_date yymmdd10.;
format DAM_BORN_DATE yymmdd10.;
cards;
6561 4597 5982 06/13/2002 08/05/2008 1 4.8 M
6870 6561 5878 08/05/2008 10/13/2009 1 3.9 M
6971 6561 6626 08/05/2008 10/27/2010 3 2.3 M
6972 6561 6626 08/05/2008 10/27/2010 3 1.9 F
6973 6561 6626 08/05/2008 10/27/2010 3 2.2 F
7284 6561 6467 08/05/2008 12/21/2011 2 3.6 M
7285 6561 6467 08/05/2008 12/21/2011 2 3.3 F
7603 6561 7069 08/05/2008 05/07/2014 2 4 M
7603.1 6561 7069 08/05/2008 05/07/2014 2 3.2 M
;
proc sql;
/* Create table of number of offsprings for each parturition */
create table offsprings2 as
select
dam,
animal_birth_date,
ANIMAL_BIRTH_WEIGHT,
SEX,
mean(distinct animal) as Animal
from pn
group by
dam,
ANIMAL_BIRTH_WEIGHT;
quit;
/* Create table of number of parturitions, mean number of offsprings per female
and parturition interval (in years) */
proc sql;
create table part_nb as
select
dam,
count(ANIMAL_BIRTH_WEIGHT) as Total_Lamb_Delivered,
mean(ANIMAL_BIRTH_WEIGHT) as Mean_kg_Birth_by_Offpring format=4.1,
case
when count(animal_birth_date) > 1 then
range(animal_birth_date) / (count(animal_birth_date)-1) / 365
else .
end as parturition_inte format=4.1
from offsprings2
group by dam;
quit;
proc print data = part_nb style(column) = [just=center];
where dam = 6561;
run;
And the Result is as follows:
Obs | DAM | Total_Lamb_Delivered | Mean_kg_Birth_by_Offpring | parturition_inte |
2 | 6561 | 8 | 3.1 | 0.7 |
The next issue is about to describe the percentage and number of MALES and FEMALES produced by DAM, and the result would be as follows:
Obs | DAM | Total_Lamb_Delivered | Mean_kg_Birth_by_Offpring | parturition_inte | N_Males | Porc_Males | N_Females | Porc_Females |
2 | 6561 | 8 | 3.1 | 0.7 | 5 | 62.5 | 3 | 37.5 |
Thank you for your help my Friends.
Atte
I'm going to suggest you should calculate your percentages outside and merge them in.
You should be able to run a proc freq to get the data initially, but then you may need to reformat it.
proc freq data=have noprint;
table dam*sex/out=summary_want outpct;
run;
I'm going to suggest you should calculate your percentages outside and merge them in.
You should be able to run a proc freq to get the data initially, but then you may need to reformat it.
proc freq data=have noprint;
table dam*sex/out=summary_want outpct;
run;
Thanks for your suggestion Reeza.
I will test this command .
Regards
I will do it for PG.
data pn;
input ANIMAL DAM SIRE DAM_BORN_DATE:mmddyy. ANIMAL_BIRTH_DATE:mmddyy. ANIMAL_BIRTH_TYPE ANIMAL_BIRTH_WEIGHT SEX$ ;
format animal_birth_date yymmdd10.;
format DAM_BORN_DATE yymmdd10.;
cards;
6561 4597 5982 06/13/2002 08/05/2008 1 4.8 M
6870 6561 5878 08/05/2008 10/13/2009 1 3.9 M
6971 6561 6626 08/05/2008 10/27/2010 3 2.3 M
6972 6561 6626 08/05/2008 10/27/2010 3 1.9 F
6973 6561 6626 08/05/2008 10/27/2010 3 2.2 F
7284 6561 6467 08/05/2008 12/21/2011 2 3.6 M
7285 6561 6467 08/05/2008 12/21/2011 2 3.3 F
7603 6561 7069 08/05/2008 05/07/2014 2 4 M
7603.1 6561 7069 08/05/2008 05/07/2014 2 3.2 M
;
run;
proc sql;
/* Create table of number of offsprings for each parturition */
create table offsprings2 as
select
dam,
animal_birth_date,
ANIMAL_BIRTH_WEIGHT,
SEX,
mean(distinct animal) as Animal
from pn
group by
dam,
ANIMAL_BIRTH_WEIGHT;
quit;
/* Create table of number of parturitions, mean number of offsprings per female
and parturition interval (in years) */
proc sql;
create table part_nb as
select
dam,
count(ANIMAL_BIRTH_WEIGHT) as Total_Lamb_Delivered,
mean(ANIMAL_BIRTH_WEIGHT) as Mean_kg_Birth_by_Offpring format=4.1,
case
when count(animal_birth_date) > 1 then
range(animal_birth_date) / (count(animal_birth_date)-1) / 365
else .
end as parturition_inte format=4.1,sum(SEX='M') as N_Males,sum(SEX='M')/count(*) as Porc_Males ,sum(SEX='F') as N_Females,sum(SEX='F')/count(*) as Porc_Females
from offsprings2
group by dam;
quit;
proc print noobs;run;
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!
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.