Help using Base SAS procedures

number of cycles and length of each cycle

Reply
Occasional Contributor
Posts: 13

number of cycles and length of each cycle

How is it possible to determine the number of estrous cycles in dogs when the occurrence of the cycle is given.

For instance, when the determinants of the cycle is given by DI,PR,ES,ME,S,P where DI=diestrus,PR=Proestrus,ES=estrus,ME=metestrus,S=sperm,P=plug.

The occurrence of estrus is only that matters and the cycle is given by EST DI DI DI MET EST -- here the length of the cycle is 5 until the occurrence of next estrus.

A cycle is calculated from one estrus to another estrus. The length of the cycle is the period until next estrus occurs which is 5 in the above case.

How do I write a code to calculate this in Statistics. The endpoint is to calculate the number of cycles and length of each cycle.

The output has to look like this:
animal_id cycle1 cycle2 cycle3
101 5 3 2
102 2 3 1
103 3 1 2
Super User
Posts: 10,028

Re: number of cycles and length of each cycle

What does your origin dataset look like?


Ksharp
Occasional Contributor
Posts: 13

Re: number of cycles and length of each cycle

It has many variables. But the variable of interest has observations that look like this

Est
Di
Met
Sp
Est

and so on
Super User
Posts: 10,028

Re: number of cycles and length of each cycle

Whether is The following code what you want.
I have to leave now,Sorry. If you have some problems ,I will be here tomorrow this time.


[pre]


data temp;
input id $ x $;
cards;
101 Est
101 Di
101 Met
101 Sp
101 Est
101 Met
101 Sp
101 Met
101 Est
102 Est
102 Met
102 Sp
102 Est
;
run;
data have;
set temp;
if x='Est' then do;
cycle+1;
duration=0;
end;
if id ne lag(id) then cycle=0;
duration+1;
run;
data _want(keep=id lag_dur cycle_no);
set have;
lag_dur=lag(duration);
if id ne lag(id) then call missing(lag_dur);
if x='Est' then do;
cycle_no=cats('cycle',cycle);
output;
end;
run;
proc transpose data=_want out=want;
by id;
id cycle_no;
var lag_dur;
run;
[/pre]


Ksharp
Ask a Question
Discussion stats
  • 3 replies
  • 149 views
  • 0 likes
  • 2 in conversation