BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

4 REPLIES 4
Reeza
Super User

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;
jonatan_velarde
Pyrite | Level 9

Thanks for your suggestion Reeza.

 

I will test this command .

 

Regards

Ksharp
Super User

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;

jonatan_velarde
Pyrite | Level 9
proc print noobs;run;

Very nice

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 838 views
  • 1 like
  • 3 in conversation