I want to plot mean and confidence intervals in gplot. I have tried modifying a code found in the community (see below) for my data but it only produces the Means with a joined line and no error bars and I get the error message:
NOTE: ERROR DETECTED IN ANNOTATE= DATASET WORK.ANNO.
VARIABLE SHOWN IS NOT OF THE PROPER DATATYPE YC
NOTE: ERROR LIMIT REACHED IN ANNOTATE PROCESS. PROCESSING IS TERMINATED.
NOTE: PROCESSING TERMINATED BY INDIVIDUAL ERROR COUNT.
NOTE: 1 TOTAL ERRORS.
Could anyone please tell me how to solve the issue?
Thanks,
Anna
proc summary data=PAwPDAPFO;
by dage;
var CO;
output out=means (drop=_:) mean=mean lclm=lclm uclm=uclm;
run;
data anno;
length function color $8;
retain when 'a';
set means;
/*draw horisontal line from limit to limit*/
function='move'; yc=var; xsys='2'; ysys='2'; x=lclm; color='black'; output;
function='draw'; x=uclm; size=1; output;
/*draw tick line for lower*/
function='move'; xsys='2'; ysys='2'; yc=var; y=.; x=lclm; color='black'; output;
function='draw'; x=lclm; y=+1; ysys='9'; size=1; output;
function='draw'; x=lclm; y=-2; size=1; output;
/*draw tick line for upper*/
function='move'; xsys='2'; ysys='2'; yc=var; y=.; x=uclm; color='black'; output;
function='draw'; x=uclm; y=+1; ysys='9'; size=1; output;
function='draw'; x=uclm; y=-2; size=1; output;
run;
symbol1 value=dot height=1 color=black;
proc gplot data=means;
plot mean*dage/annotate=anno nolegend;
run; quit;
Try this instead. It's a lot less code 🙂
proc sgplot data=PAwPDAPFO noautolegend;
vline dage / response=CO stat=mean limitstat=clm markers;
run;
Hope this helps!
Dan
According to the error message:
VARIABLE SHOWN IS NOT OF THE PROPER DATATYPE YC
You have the wrong variable type for YC. It is expecting a character variable, and you have provided a numeric variable. But if you are trying to draw confidence intervals, you probably want to use variable Y and not YC.
Thank you. Changing the variable to character helped me a lot along the way!
@pakiprinsesse wrote:
Thank you. Changing the variable to character helped me a lot along the way!
Just in case there's any interest in the PROC GPLOT solution ... I didn't advise to change the variable to character. I advised that you use Y instead of YC, with a numeric variable.
Try this instead. It's a lot less code 🙂
proc sgplot data=PAwPDAPFO noautolegend;
vline dage / response=CO stat=mean limitstat=clm markers;
run;
Hope this helps!
Dan
Thank you!.
That worked as well.
In the mean time I succeeded with plot and the following code:
procsortdata=PAwPDAPFO;
bydage;
run;
procsummarydata=PAwPDAPFO;
bydage;
varCO;
outputout=means (drop=_:) mean=meanlclm=lclmuclm=uclm;
run;
/*CONVERT DAGE FROM NUMERIC TO CHARACTER*/
datameansCO; setmeans;
char_dage=put(dage,$2.);
dropdage;
renamechar_dage=dage;
run;
/*GRAPH*/
dataanno;
lengthfunction color $8;
retain/*xsys ysys '2' */when 'a';
setmeansco;
/*draw VERTICAL line from limit to limit (=ERROR BARS)*/
function='move'; Xc=dage; xsys='2'; ysys='2'; Y=lclm; color='black'; output;
function='draw'; Y=uclm; size=1; output;
/*draw tick line for lower CONFIDENCE LIMIT*/
function='move'; xsys='2'; ysys='2'; Xc=dage; X=.; Y=lclm; color='black';output;
function='draw'; Y=lclm; X=+1; Xsys='9'; size=1;output;
function='draw'; Y=lclm; X=-2; size=1; output;
/*draw tick line for upper CONFIDENCE LIMIT*/
function='move'; xsys='2'; ysys='2'; Xc=dage; X=.; Y=uclm; color='black';output;
function='draw'; Y=uclm; X=+1; Xsys='9'; size=1;output;
function='draw'; Y=uclm; X=-2; size=1; output;
run;
/*SET AXIS AND SYMBOLS*/
symbol1value=dot height=1color=black;
axis1order=0to28by1;
axis2order=0.4to1.75by0.1;
/*PLOT*/
procgplotdata=meansco;
plotMEAN*DAGE/annotate=anno nolegendhaxis=axis1 vaxis=axis2;
run;quit;
/******************************************************************************************************/
/******************************************************************************************************/
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.