BookmarkSubscribeRSS Feed
ARLewis
Calcite | Level 5
Hi I keep getting this error and I can't figure out why...

This is the code I'm using... notice the axis2 is the same for both Plot and Plot2 statements. I'm using the Plot statements because each graph has it's own annotation. Each plot runs fine by itself, but together the horiz statements are seen as different. I tried just taking out the haxis statement in the second plot but that gives me the same problem. Any help is appreciated. Thanks

title1 'State CL for PT-Math';

axis1 label=none
minor=none
offset=(.1,.10);

axis2 order=(0 to 50 by 5)
label=('%Time spent in Subject')
minor=none;

symbol1 interpol=none color=black value=dot height=1.5;

proc gplot data=test ;
plot yvar*Trate /annotate=Tanno nolegend haxis=axis2 vaxis=axis1 ;
plot2 yvar*Prate / overlay annotate=Panno nolegend haxis=axis2 vaxis=axis1 ;
run;

ERROR: Horizontal axis variables on PLOT and PLOT2 statements must be the same. Variables do not match in plot pair 0.
7 REPLIES 7
ballardw
Super User
The horizontal axis need to use the same X variable. Your code uses two, TRATE and PRATE.

One approach to getting what I believe you are attempting is to create a single X variable and a categorical variable to differentiate.

Quick and dirty example:

data newtest (keep=yvar rate ratetype);
set test;
rate=trate;ratetype="T";output;
rate=prate;ratetype="P";output;
run;

proc gplot data=newtest;
plot yvar*rate=ratetype /haxis=axis2 vaxis=axis1;
run;
quit;

Since you don't have any details on the annotate I'm not including it.
ARLewis
Calcite | Level 5
Thanks Ballardw,

That does give me the plots on one chart, but what I need is to get two confidence limits on one chart! I've inserted the code with data (not all the states for brevity!) - so you can simply run it and see what I mean. I'd like both plots to be annotated. Would I try and do the same trick you gave me with the annotate code, so there is only one annotation for all the data instead of 2?

/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;

/* Create sample data for forest plot. */
data test;
input yvar $ 1-3 Tlower_limit Trate Tupper_limit Plower_limit Prate Pupper_limit;
datalines;
VT 13.90 16.23 18.56 13.92 15.69 17.46
WA 15.98 17.63 19.29 16.21 18.31 20.41
WI 14.02 14.92 15.81 13.54 14.91 16.28
WV 14.72 15.37 16.03 14.88 17.19 19.51
WY 15.75 16.97 18.19 14.74 16.04 17.34
;
run;

/* Create an annotate data set to draw the lines for Teacher CL. */
data Tanno;
length function style color $8;
retain xsys ysys '2' when 'a';
set test;

/* Draw the horizontal line from lower_limit to upper_limit */
function='move'; xsys='2'; ysys='2'; yc=yvar; x=Tlower_limit; color='black'; output;
function='draw'; x=Tupper_limit; color='black'; size=1; output;

/* Draw the tick line for the lower_limit value */
function='move';xsys='2'; ysys='2';yc=yvar; x=Tlower_limit; color='black'; output;
function='draw';x=Tlower_limit; ysys='9'; y=+1; size=1; output;
function='draw';x=Tlower_limit; y=-2; size=1;output;

/* Draw the tick line for the upper_limit value */
function='move';xsys='2'; ysys='2'; yc=yvar; x=Tupper_limit; color='black'; output;
function='draw';x=Tupper_limit; ysys='9'; y=+1; size=1; output;
function='draw';x=Tupper_limit; y=-2; size=1; output;
run;

/* Create an annotate data set to draw the lines for Principal CL. */
data Panno;
length function style color $8;
retain xsys ysys '2' when 'a';
set test;

/* Draw the horizontal line from lower_limit to upper_limit */
function='move'; xsys='2'; ysys='2'; yc=yvar; x=Plower_limit; color='black'; output;
function='draw'; x=Pupper_limit; color='black'; size=1; output;

/* Draw the tick line for the lower_limit value */
function='move';xsys='2'; ysys='2';yc=yvar; x=Plower_limit; color='black'; output;
function='draw';x=Plower_limit; ysys='9'; y=+1; size=1; output;
function='draw';x=Plower_limit; y=-2; size=1;output;

/* Draw the tick line for the upper_limit value */
function='move';xsys='2'; ysys='2'; yc=yvar; x=Pupper_limit; color='black'; output;
function='draw';x=Pupper_limit; ysys='9'; y=+1; size=1; output;
function='draw';x=Pupper_limit; y=-2; size=1; output;
run;

title1 'State CL for PT-Math';

axis1 label=none
minor=none
offset=(.1,.10);

axis2 order=(0 to 50 by 5)
label=('%Time spent in Subject')
minor=none;

symbol1 interpol=none color=black value=dot height=1.5;

/* Ballardw code entered here */
data newtest (keep=yvar rate ratetype);
set test;
rate=trate;ratetype="T";output;
rate=prate;ratetype="P";output;
run;

proc gplot data=newtest;
plot yvar*rate=ratetype / haxis=axis2 vaxis=axis1;
run;
quit;

*proc gplot data=test ;
* plot yvar*Trate /annotate=Tanno nolegend haxis=axis2 vaxis=axis1 ;
* plot2 yvar*Prate / overlay annotate=Panno nolegend haxis=axis2 vaxis=axis1 ;
*run;



quit;
ballardw
Super User
Have you tried the I=R type symbols?

I think 2 symbol statments with i=RLCLI95 or i=RLCLM95 depening on whether you're looking for limits of individual or mean estimators.

The online help for Gplot should have an example called Plotting Two Variables which does a regression and confidence limits around one set of variable pairs.

Two separate symbol statements with different colors and symbols should overlay.

One big advantage is you just drop the data in and let the regression be handled by Gplot. If you're confidence limits come from some thing other than linear, quadratic or cubic regression, then I'm out of ideas. I think a properly constructed annotate data set shoulc still work but I haven't time to figure out how to display it at the moment.
ARLewis
Calcite | Level 5
Thanks - yes I have to use the limits from the data set since I used 80 plus replicate weight samples from the data to derive the CL. I'll give your suggestions a whirl - thanks so much for taking the time to share your thoughts. At least I have a direction to try now.
ballardw
Super User
If the data are more complicated then I understand.

It may be that the better idea would become to create additional "rate" variables if you have the confidence limits for the X values.

(Pseudo code).
rate=trate;ratetype="T";output;
rate=trateuppercl;ratetype='TCU';output;
rate=tratelowercl;ratetype='TCL';output;
rate=prate;ratetype="P";output;
rate=prateuppercl;ratetype='PCU';output;
rate=pratelowercl;ratetype='PCL';output;


And appropriate symbol statements to join the limits.
ARLewis
Calcite | Level 5
Hi Ballardw,

Just for closure, I thought I'd give you an update... I used your suggestion plus did something quick and dirty which got the results I needed, but it ain't pretty! Sometime I may go back and do this right, but for now it works and I can move on. Below is the end program that gives me what I want. Thanks again for your help!

/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;

/* Create sample data for forest plot. */
data test;
input yvar $ 1-3 Tlowercl Trate Tuppercl Plowercl Prate Puppercl;
datalines;
UT 16.97 18.54 20.10 14.44 15.85 17.25
VA 14.78 16.19 17.60 13.93 15.55 17.18
VT 13.90 16.23 18.56 13.92 15.69 17.46
WA 15.98 17.63 19.29 16.21 18.31 20.41
WI 14.02 14.92 15.81 13.54 14.91 16.28
WV 14.72 15.37 16.03 14.88 17.19 19.51
WY 15.75 16.97 18.19 14.74 16.04 17.34
;
run;
data newtest (keep=yvar rate ratetype Tlowercl Tuppercl Plowercl Puppercl);
set test;
rate=trate;ratetype="T";output;
rate=prate;ratetype="P";output;
run;


/* Create an annotate data set to draw the lines for CL. */
data Tanno;
length function style color $8;
retain xsys ysys '2' when 'a';
set newtest;

/* Draw the horizontal line from lower_limit to upper_limit */
function='move'; xsys='2'; ysys='2'; yc=yvar; x=Tlowercl; color='blue'; output;
function='draw'; x=Tuppercl; color='blue'; size=1; output;

/* Draw the tick line for the lower_limit value */
function='move';xsys='2'; ysys='2';yc=yvar; x=Tlowercl; color='blue'; output;
function='draw';x=Tlowercl; ysys='9'; y=+1; size=1; output;
function='draw';x=Tlowercl; y=-2; size=1;output;

/* Draw the tick line for the upper_limit value */
function='move';xsys='2'; ysys='2'; yc=yvar; x=Tuppercl; color='blue'; output;
function='draw';x=Tuppercl; ysys='9'; y=+1; size=1; output;
function='draw';x=Tuppercl; y=-2; size=1; output;
run;

/* Create an annotate data set to draw the lines for CL. */
data Panno;
length function style color $8;
retain xsys ysys '2' when 'a';
set newtest;

/* Draw the horizontal line from lower_limit to upper_limit */
function='move'; xsys='2'; ysys='2'; yc=yvar; x=Plowercl; color='orange'; output;
function='draw'; x=Puppercl; color='orange'; size=1; output;

/* Draw the tick line for the lower_limit value */
function='move';xsys='2'; ysys='2';yc=yvar; x=Plowercl; color='orange'; output;
function='draw';x=Plowercl; ysys='9'; y=+1; size=1; output;
function='draw';x=Plowercl; y=-2; size=1;output;

/* Draw the tick line for the upper_limit value */
function='move';xsys='2'; ysys='2'; yc=yvar; x=Puppercl; color='orange'; output;
function='draw';x=Puppercl; ysys='9'; y=+1; size=1; output;
function='draw';x=Puppercl; y=-2; size=1; output;
run;



title1 'State CL for PT-Math';

axis1 label=none
minor=none
offset=(.1,.10);

axis2 order=(0 to 50 by 5)
label=('%Time spent in Subject')
minor=none;

symbol1 interpol=none color=orange value=dot height=1.5;
symbol2 interpol=none color=blue value=dot height=1.5;
symbol3 interpol=none color=orange value=dot height=1.5;
symbol4 interpol=none color=blue value=dot height=1.5;


proc gplot data=newtest;
plot yvar*rate=ratetype / annotate = Tanno haxis=axis2 vaxis=axis1;
plot2 yvar*rate=ratetype / annotate = Panno haxis=axis2 vaxis=axis1 nolable;
run;
quit;
ARLewis
Calcite | Level 5
oops last statement group should be... (take out the nolable and make it nolegend)


proc gplot data=newtest;
plot yvar*rate=ratetype / annotate = Tanno haxis=axis2 vaxis=axis1 nolegend;
plot2 yvar*rate=ratetype / annotate = Panno haxis=axis2 vaxis=axis1 nolegend;
run;
quit; Message was edited by: ARLewis

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1878 views
  • 0 likes
  • 2 in conversation