BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Annie_Fréchette
Obsidian | Level 7

Hi!

I wondering if there is a way to calculate the number of days between first jr test and second test, and between second and third, etc. Knowing that some jrtest will be ".".

data have;
input cow$ jrtest:ddmmyy10. scc;
cards;
daisy 10/7/2017 200
maggy 10/7/2017 120
lily 10/7/2017 98
daisy . 89
maggy 11/8/2017 120
lily 11/8/2017 98
daisy 13/9/2017 102
maggy 13/9/2017 154
lily 13/9/2017 232
;

Not sure if it helps, but after that I'm transposin my jrtest and I don't want to keep the dates so I'm going with this

proc sort data=have;
format jrtest date9.;
by cow jrtest;
run;

data want;
set have;
by cow jrtest;
retain no_test;
if first.cow then no_test=1;
else no_test+1;
run;

So, I want to know how many days are between test 1 and test 2, test 2 and test 3 etc.....

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

please try  the below code

 

data have;
input cow$ jrtest:ddmmyy10. scc;
format jrtest date9.;
cards;
daisy 10/7/2017 200
maggy 10/7/2017 120
lily 10/7/2017 98
daisy . 89
maggy 11/8/2017 120
lily 11/8/2017 98
daisy 13/9/2017 102
maggy 13/9/2017 154
lily 13/9/2017 232
;

proc sort data=have;
by cow jrtest;
run;

data want;
set have;
by cow jrtest;
duration=dif(jrtest);
if first.cow then duration=.;
run;
Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

please try  the below code

 

data have;
input cow$ jrtest:ddmmyy10. scc;
format jrtest date9.;
cards;
daisy 10/7/2017 200
maggy 10/7/2017 120
lily 10/7/2017 98
daisy . 89
maggy 11/8/2017 120
lily 11/8/2017 98
daisy 13/9/2017 102
maggy 13/9/2017 154
lily 13/9/2017 232
;

proc sort data=have;
by cow jrtest;
run;

data want;
set have;
by cow jrtest;
duration=dif(jrtest);
if first.cow then duration=.;
run;
Thanks,
Jag