Here is y2axis to to 2 Y. ANYWAY to 3 Y-axis with any PROC in SINGLE plot? Thanks,
Here is a post on this, but quite out-of-date, The more the merrier - Graphically Speaking
Anyway new and convenient?!
You can not get job done by the url you mentioned ? and why ?
https://blogs.sas.com/content/graphicallyspeaking/2012/01/16/the-more-the-merrier/
You want this ?
data have;
do i=1 to 100;
x1=sin(i/10)+5;x2=cos(i/10);
dif=x1-x2; output;
end;
run;
proc sql noprint;
select min(x1),max(x1) into :min_x1,:max_x1 from have;
select min(x2),max(x2) into :min_x2,:max_x2 from have;
select floor(min(x1)),ceil(max(x1)) into :min_y,:max_y from have;
quit;
/*specify the Y axis tick value*/
data axis;
do x1=&min_y to &max_y by 0.5;
label_x1=x1;
label_x2=&min_x2 + (&max_x2-&min_x2) * (x1-&min_x1)/(&max_x1-&min_x1);
output;
end;
format label_x1 label_x2 10.2;
run;
proc sort data=have;by x1;run;
data want;
merge have axis;
by x1;
_x2=&min_x1+ (&max_x1-&min_x1)* (x2-&min_x2)/(&max_x2-&min_x2) ;
run;
proc sort data=want;by i;run;
options missing=' ';
proc sgplot data=want;
series x=i y=x1/lineattrs=(color=red);
series x=i y=_x2/lineattrs=(color=blue);
series x=i y=dif/lineattrs=(color=green) y2axis;
yaxis values=(&min_y to &max_y by 0.5) display=(novalues nolabel) ;
yaxistable label_x1/label='x1' position=left labelattrs=(color=red size=10) valueattrs=(color=red size=10) ;
yaxistable label_x2/label='_x2' position=left labelattrs=(color=blue size=10) valueattrs=(color=blue size=10);
y2axis labelpos=top labelattrs=(color=green size=10) valueattrs=(color=green size=10);
run;
Simply to let x1 x2 and dif have own Y-axis. Thanks
data _temp;
do i=1 to 100;
x1=sin(i/10)+5;x2=cos(i/10);
dif=x1-x2; output;
end;
run;quit;
proc sgplot data=_temp;
series x=i y=x1;
series x=i y=x2;
series x=i y=dif/y2axis;
run;quit;
Additional axis such as you propose would require you to rescale the data of the 3rd (or 4th or 5th) to one of the existing Y or Y2 axis and then basically draw the desired axis as a separate graphic element to have these graphs appear in a single panel using the SGPlot procedure.
If having the separate series appear in separate panels would be acceptable the Proc SGPanel with some data reshaping to add a variable for the Panelby statement with options Columns=1 and Uniscale=Column and use a single Y variable might work.
Example:
data _temp; do i=1 to 100; x1=sin(i/10)+5; x2=cos(i/10); dif=x1-x2; output; end; run; proc transpose data=_temp out=temp_trans (rename=(_name_=panel)) prefix=y ; by i; var x1 x2 dif; run; proc sgpanel data=temp_trans; panelby panel/columns=1 uniscale=column; series x=i y=y1; label panel='Y variable'; run;quit;
Which would be extendable to more y values.
Proc Transpose used here for a quick reshape of the data.
You can not get job done by the url you mentioned ? and why ?
https://blogs.sas.com/content/graphicallyspeaking/2012/01/16/the-more-the-merrier/
You want this ?
data have;
do i=1 to 100;
x1=sin(i/10)+5;x2=cos(i/10);
dif=x1-x2; output;
end;
run;
proc sql noprint;
select min(x1),max(x1) into :min_x1,:max_x1 from have;
select min(x2),max(x2) into :min_x2,:max_x2 from have;
select floor(min(x1)),ceil(max(x1)) into :min_y,:max_y from have;
quit;
/*specify the Y axis tick value*/
data axis;
do x1=&min_y to &max_y by 0.5;
label_x1=x1;
label_x2=&min_x2 + (&max_x2-&min_x2) * (x1-&min_x1)/(&max_x1-&min_x1);
output;
end;
format label_x1 label_x2 10.2;
run;
proc sort data=have;by x1;run;
data want;
merge have axis;
by x1;
_x2=&min_x1+ (&max_x1-&min_x1)* (x2-&min_x2)/(&max_x2-&min_x2) ;
run;
proc sort data=want;by i;run;
options missing=' ';
proc sgplot data=want;
series x=i y=x1/lineattrs=(color=red);
series x=i y=_x2/lineattrs=(color=blue);
series x=i y=dif/lineattrs=(color=green) y2axis;
yaxis values=(&min_y to &max_y by 0.5) display=(novalues nolabel) ;
yaxistable label_x1/label='x1' position=left labelattrs=(color=red size=10) valueattrs=(color=red size=10) ;
yaxistable label_x2/label='_x2' position=left labelattrs=(color=blue size=10) valueattrs=(color=blue size=10);
y2axis labelpos=top labelattrs=(color=green size=10) valueattrs=(color=green size=10);
run;
Many Thanks. This is what I need.
"Label_x1 Label_x2" takes too much spade. SO I switch to "_x1 _x2".
But somehow _x2 comes with mess.
data have;
do i=1 to 100;
x1=sin(i/10)+5;x2=cos(i/10);
dif=x1-x2; output;
end;
run;
proc sql noprint;
select min(x1),max(x1) into :min_x1,:max_x1 from have;
select min(x2),max(x2) into :min_x2,:max_x2 from have;
select floor(min(x1)),ceil(max(x1)) into :min_y,:max_y from have;
quit;
/*specify the Y axis tick value*/
data axis;
do x1=&min_y to &max_y by 1.0;
_x1=x1;
_x2=&min_x2 + (&max_x2-&min_x2) * (x1-&min_x1)/(&max_x1-&min_x1);
output;
end;
format _x1 _x2 10.1;
run;
proc sort data=have;by x1;run;
data want;
merge have axis;
by x1;
_x2=&min_x1+ (&max_x1-&min_x1)* (x2-&min_x2)/(&max_x2-&min_x2) ;
format _x2 10.1;
run;
proc sort data=want;by i;run;
options missing=' ';
proc sgplot data=want;
series x=i y=x1/lineattrs=(color=red);
series x=i y=_x2/lineattrs=(color=blue);
series x=i y=dif/lineattrs=(color=green) y2axis;
yaxis values=(&min_y to &max_y by 1) display=(novalues nolabel) ;
yaxistable _x1/position=left labelattrs=(color=red size=10) valueattrs=(color=red size=10) ;
yaxistable _x2/position=left labelattrs=(color=blue size=10) valueattrs=(color=blue size=10);
y2axis labelpos=top labelattrs=(color=green size=10) valueattrs=(color=green size=10);
run;
I use SQL to stitch. It comes up clean now.
Notice I changed the code.
You are using my old code .
Did you try my updated code ?
data have; do i=1 to 100; x1=sin(i/10)+5;x2=cos(i/10); dif=x1-x2; output; end; run; proc sql noprint; select min(x1),max(x1) into :min_x1,:max_x1 from have; select min(x2),max(x2) into :min_x2,:max_x2 from have; select floor(min(x1)),ceil(max(x1)) into :min_y,:max_y from have; quit; /*specify the Y axis tick value*/ data axis; do x1=&min_y to &max_y by 0.5 ; label_x1=x1; label_x2=&min_x2 + (&max_x2-&min_x2) * (x1-&min_x1)/(&max_x1-&min_x1); output; end; format label_x1 label_x2 10.1; run; proc sort data=have;by x1;run; data want; merge have axis; by x1; _x2=&min_x1+ (&max_x1-&min_x1)* (x2-&min_x2)/(&max_x2-&min_x2) ; format _x2 10.1; run; proc sort data=want;by i;run; options missing=' '; proc sgplot data=want; series x=i y=x1/lineattrs=(color=red); series x=i y=_x2/lineattrs=(color=blue); series x=i y=dif/lineattrs=(color=green) y2axis; yaxis values=(&min_y to &max_y by 0.5) display=(novalues nolabel) ; yaxistable label_x1/label='x1' position=left labelattrs=(color=red size=10) valueattrs=(color=red size=10) ; yaxistable label_x2/label='_x2' position=left labelattrs=(color=blue size=10) valueattrs=(color=blue size=10); y2axis labelpos=top labelattrs=(color=green size=10) valueattrs=(color=green size=10); run;
OK NOW. Thanks.
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.