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

Hi

I wrote this code to Construct a graph of the fitted model versus months. Also to plot the observed number of failures on this graph.

But the code results doesn't show this plot. Can you help with this please


data prog;
input nf month;
datalines;
5 18
3 15
1 14
4 23
0 10
0 5
1 8
0 7
0 12
0 3
1 7
0 2
7 30
0 9
proc genmod data = prog;
model nf= month / dist=Poisson type1 type3 ;
run;
proc logistic data=prog;
model nf=month / aggregate scale=none;
run;
ods graphics on;
proc sort data=prog;by month;run;
proc sgplot data=prog;
title "Problem 3.16.b";
yaxis label="Number of failures";
scatter x=month y=phat / name="points"
legendLabel="number of failures";
series x=month y=nf / name="line"
legendLabel="Predicted number of failures"
lineattrs = GRAPHFIT;
discretelegend "points" "line";
run;
proc genmod plots=all;
model nf = month;
run;
ods graphics off;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You didn't actually create an outputted data set, you need the OUT= portion.

This should get you started then. Your SGPLOT syntax was also wrong so I just simplified it to make it work for now. You can add back the pieces as you get it working. Good Luck. 

 

proc genmod data = prog plots;
model nf= month / dist=Poisson type1 type3 ;
output out=want predicted=p;
run;

proc sgplot data=want;
yaxis label="Number of failures";
scatter x=month y=p / name="points" ;
scatter x=month y=nf / name="line"  ;
run;

@shahd wrote:

still not working

 

data prog;
input nf month;
datalines;
5 18
3 15
1 14
4 23
0 10
0 5
1 8
0 7
0 12
0 3
1 7
0 2
7 30
0 9
proc genmod data = prog;
model nf= month / dist=Poisson type1 type3 ;
output predicted=p;
run;
ods graphics on;
proc sort data=prog;by month;run;
proc sgplot data=prog;
yaxis label="Number of failures";
scatter x=month y=p / name="points"
legendLabel="number of failures";
series x=month y=nf / name="line"
legendLabel="Predicted number of failures"
lineattrs = GRAPHFIT;
discretelegend "points" "line";
run;
proc genmod plots=all;
model nf = month;
run;
ods graphics off;


 

View solution in original post

5 REPLIES 5
Reeza
Super User
You didn't create any output data sets from the PROC GENMOD or LOGISTIC to use to drive those plots. Your PROG data set has no predictions or phat.
shahd
Quartz | Level 8

could you please help me to modify it

Reeza
Super User
Please try adding the OUTPUT statement to your PROC GENMOD and LOGISTIC. If you still can't get it after that attempt, post your code and I'll take a look.

PROC LOGISTIC OUTPUT statement
https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_logistic_syntax27.htm&docsetVersi...

PROC GENMOD output statement
https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_genmod_syntax24.htm&docsetVersion...
shahd
Quartz | Level 8

still not working

 

data prog;
input nf month;
datalines;
5 18
3 15
1 14
4 23
0 10
0 5
1 8
0 7
0 12
0 3
1 7
0 2
7 30
0 9
proc genmod data = prog;
model nf= month / dist=Poisson type1 type3 ;
output predicted=p;
run;
ods graphics on;
proc sort data=prog;by month;run;
proc sgplot data=prog;
yaxis label="Number of failures";
scatter x=month y=p / name="points"
legendLabel="number of failures";
series x=month y=nf / name="line"
legendLabel="Predicted number of failures"
lineattrs = GRAPHFIT;
discretelegend "points" "line";
run;
proc genmod plots=all;
model nf = month;
run;
ods graphics off;

Reeza
Super User

You didn't actually create an outputted data set, you need the OUT= portion.

This should get you started then. Your SGPLOT syntax was also wrong so I just simplified it to make it work for now. You can add back the pieces as you get it working. Good Luck. 

 

proc genmod data = prog plots;
model nf= month / dist=Poisson type1 type3 ;
output out=want predicted=p;
run;

proc sgplot data=want;
yaxis label="Number of failures";
scatter x=month y=p / name="points" ;
scatter x=month y=nf / name="line"  ;
run;

@shahd wrote:

still not working

 

data prog;
input nf month;
datalines;
5 18
3 15
1 14
4 23
0 10
0 5
1 8
0 7
0 12
0 3
1 7
0 2
7 30
0 9
proc genmod data = prog;
model nf= month / dist=Poisson type1 type3 ;
output predicted=p;
run;
ods graphics on;
proc sort data=prog;by month;run;
proc sgplot data=prog;
yaxis label="Number of failures";
scatter x=month y=p / name="points"
legendLabel="number of failures";
series x=month y=nf / name="line"
legendLabel="Predicted number of failures"
lineattrs = GRAPHFIT;
discretelegend "points" "line";
run;
proc genmod plots=all;
model nf = month;
run;
ods graphics off;


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 2624 views
  • 1 like
  • 2 in conversation