BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
always-good
Obsidian | Level 7

Hello SAS community!

I'm working on fitting the lactation curve of dairy cows according to the calving season (1=winter, 2= spring and 3= summer) using the model of Wood for fitting.

My question here is that I want to draw the three curves together as one curve according to the three seasons and not each curve separately.

Can anyone please correct the code for me. I really need help! 

Here is the data and the tried code: 

data curves;

input season days Milk;

datalines;

1 22 7.63

1 54 7.25

1 85 8.40

1 113 8.10

1 142 5.75

1 174 6.00

1 208 5.00

1 230 4.00

1 263

1 299

2 17 8.54

2 46 8.71

2 75 7.27

2 107 5.46

2 140 5.82

2 167 6.22

2 187 6.60

2 219 3.00

2 258

2 285

3 16 7.00

3 50 9.00

3 84 7.00

3 107 9.50

3 140 8.00

163

;

proc nlin data = curves plots = fit;

parms A = 15 B = 0.19 C = -0.0012 ;

bounds A B C > 0;

by season;

model PL = A * days **b * exp(-C*days);

output out = Fit predicted = Pred;

by season;

run;

title1' lactation curve ';

proc gplot data=fit; plot pred*days milk*days/overlay;

by season;

run;

Thank you, the community!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I suggest you use the "missing value trick" to create an evenly spaced set of Jours for scoring. Then run the model and use PROC SGPLOT to overlay the data and curves. You do this by using the GROUP=saison option:

 

/* to improve the visualization, add a sequence of evenly spaced
values to the data. This is the scoring set. */
data Score;
Score = 1;
do saison = 1 to 3;
   do Jours = 15 to 250 by 5;
      output;
   end;
end;
run;

data All;
set curves Score;
run;

proc sort data=All;
by saison Jours;
run;

proc nlin data = All plots = fit;
parms A = 15 B = 0.19 C = -0.0012 ;
bounds A B C > 0;
by saison;
model PL = A * Jours **b * exp(-C*Jours);
output out = Fit predicted = Pred ;
run;

title1' courbe de lactation ';
proc sgplot data=fit;
scatter y=PL x=Jours / group=saison;
series y=pred x=Jours / group=saison;
run;

View solution in original post

17 REPLIES 17
PaigeMiller
Diamond | Level 26

Please look at the log for this code and fix the error. (That could be why you can't get a plot; or it may be there are additional errors)

--
Paige Miller
always-good
Obsidian | Level 7
Thank you for your reply!
The code is running well, but that's not exactly the result I'm asking for.
I want to plot three curves in the same curve and I'm not familiar with that.
PaigeMiller
Diamond | Level 26

Maybe you are running different code than what you showed above? When I copy and paste that code into SAS, there is an error in PROC NLIN.

--
Paige Miller
always-good
Obsidian | Level 7
Please try this code. It is running:
data curves;
input saison Jours PL;
datalines;
1 22 7.63
1 54 7.25
1 85 8.40
1 113 8.10
1 142 5.75
1 174 6.00
1 208 5.00
1 230 4.00
1 263
1 299
2 17 8.54
2 46 8.71
2 75 7.27
2 107 5.46
2 140 5.82
2 167 6.22
2 187 6.60
2 219 3.00
2 258
2 285
3 16 7.00
3 50 9.00
3 84 7.00
3 107 9.50
3 140 8.00
3 163
;
proc nlin data = curves plots = fit;
parms A = 15 B = 0.19 C = -0.0012 ;
bounds A B C > 0;
by saison;
model PL = A * Jours **b * exp(-C*Jours);
output out = Fit predicted = Pred ;
by saison;
run;
title1' courbe de lactation ';
proc gplot data=fit;
plot pred*Jours PL*Jours/overlay;
by saison;
run;

PaigeMiller
Diamond | Level 26

Thank you, your code now works. However, I don't really understand this part:

 

I want to draw the three curves together as one curve according to the three seasons and not each curve separately.

 

Does this mean you want values 1 2 and 3 on the horizontal axis? If so, what should go on the vertical axis? Or do you want something else? I really need a more clear explanation.

--
Paige Miller
always-good
Obsidian | Level 7
Yes this is what I mean, values 1,2 and 3 on the horizontal axis and the same vertical axis for all curves like in the code, I means "Jours".
I want to fit the curve of Milk production "PL" (horizontal axis) for the three seasons 1,2 and 3, according to the days "Jours" (vertical axis).
PaigeMiller
Diamond | Level 26

@always-good wrote:
Yes this is what I mean, values 1,2 and 3 on the horizontal axis and the same vertical axis for all curves like in the code, I means "Jours".
I want to fit the curve of Milk production "PL" (horizontal axis) for the three seasons 1,2 and 3, according to the days "Jours" (vertical axis).

I'm still not grasping what you want. What "curves"? What is the value on the Y-axis? Can you show me a similar plot that is on the internet somewhere?

--
Paige Miller
always-good
Obsidian | Level 7

Please check this out

PaigeMiller
Diamond | Level 26

Please include a screen capture of this plot by clicking on the "Insert Photos" icon. I refuse to download files; and furthermore Microsoft Office documents can be a security threat.

--
Paige Miller
always-good
Obsidian | Level 7

lactation curves according to different season of calvinglactation curves according to different season of calving

PaigeMiller
Diamond | Level 26

This does not look anything like what you said earlier "Yes this is what I mean, values 1,2 and 3 on the horizontal axis"


This doesn't seem to match your original description of the plot "My question here is that I want to draw the three curves together as one curve", this plot shows separate curves and does not draw the three curves together as one curve.

--
Paige Miller
always-good
Obsidian | Level 7
Please if you understand what I mean, you can help me! I think it is the same thing meant:
The "PL" for the three seasons 1,2 and 3 are in the horizontal axis. I think it is clear with the picture.
what is the thing that you didn't understand? we can find a solution?
PaigeMiller
Diamond | Level 26

Not clear. The plot shows a horizontal axis going from 5 to 305. Do you want a horizontal axis that has only values 1, 2 and 3? (Because that's what you said earlier) And do you want ""My question here is that I want to draw the three curves together as one curve", or do you want three curves?

--
Paige Miller
always-good
Obsidian | Level 7
I'm sorry you are right.
the PL values for season1,2 and 3 are in the vertical axis.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 3191 views
  • 4 likes
  • 3 in conversation