Hi Folks:
I have two issues that I greatly appreciate your help on my SGpanel.
1. How to show vertical axis scales on the left and right sides of the plot as shown in the plot below?
2. How to show the value (variable 'percent') associated with the maximum of interval=60 (variable 'fu') by 'stage' and 'agegrp' so that the end of each lines (red, green and blue) in each panel will have values appear on the plot. Example shown in the panel A1 and b1 in the image below.
Sample data attached.
ods graphics/width=12in height=10in;
proc sgpanel data=four1;
panelby SORT/ novarname columns=4 rows=4;
styleattrs DATACONTRASTCOLORS=(BLUE green red);
series x=FU y=cr/lineattrs=(pattern=solid thickness=2) GROUP=STAGE;
colaxis label='label' min=1 max=100 grid values=(0 to 60 by 1);
rowaxis label='my-stat'
fitpolicy=thin grid values=(0 to 1.0 by 0.01);
keylegend/ title=" " position=top;
title ' ';
run;
There are two keys for your request:
1. Use the REFTICKS option to mirror the axis.
2. Overlay another SCATTER plot using only the data points for fu=60 (see data step).
Here is the code:
libname local ".";
data tempfour;
set local.four1;
if fu=60 then y2=cr;
else y2=.;
run;
ods graphics/width=12in height=10in;
proc sgpanel data=tempfour;
panelby SORT/ novarname columns=4 rows=4;
styleattrs DATACONTRASTCOLORS=(BLUE green red);
series x=FU y=cr/lineattrs=(pattern=solid thickness=2) GROUP=STAGE;
scatter x=FU y=y2/markerattrs=(size=0) datalabel=y2;
colaxis label='label' min=1 max=100 grid values=(0 to 60 by 1);
rowaxis label='my-stat' refticks=(values)
fitpolicy=thin grid values=(0 to 1.0 by 0.01);
keylegend/ title=" " position=top;
title ' ';
run;
Hope this helps!
Dan
There are two keys for your request:
1. Use the REFTICKS option to mirror the axis.
2. Overlay another SCATTER plot using only the data points for fu=60 (see data step).
Here is the code:
libname local ".";
data tempfour;
set local.four1;
if fu=60 then y2=cr;
else y2=.;
run;
ods graphics/width=12in height=10in;
proc sgpanel data=tempfour;
panelby SORT/ novarname columns=4 rows=4;
styleattrs DATACONTRASTCOLORS=(BLUE green red);
series x=FU y=cr/lineattrs=(pattern=solid thickness=2) GROUP=STAGE;
scatter x=FU y=y2/markerattrs=(size=0) datalabel=y2;
colaxis label='label' min=1 max=100 grid values=(0 to 60 by 1);
rowaxis label='my-stat' refticks=(values)
fitpolicy=thin grid values=(0 to 1.0 by 0.01);
keylegend/ title=" " position=top;
title ' ';
run;
Hope this helps!
Dan
Hi @DanH_sas
Thank you very much. Both issues are resolved. Any hints as to how to display percent=cr*100 instead cr itself? cr worked perfectly with format 5.2 for two decimal places. But it didn't display when I replace cr by percent in the preceding data step with various combinations of format and datalebelpos options.
I appreciate any hints.
set local.four1;
percent=cr*100;
if fu=60 then y2=percent;
else y2=.;
run;
ods graphics/width=12in height=10in;
proc sgpanel data=tempfour;
panelby SORT/ novarname columns=4 rows=4;
styleattrs DATACONTRASTCOLORS=(BLUE green red);
series x=FU y=cr/lineattrs=(pattern=solid thickness=2) GROUP=STAGE;
scatter x=FU y=y2/markerattrs=(size=0) datalabel=y2;
colaxis label='label' min=1 max=100 grid values=(0 to 60 by 1);
rowaxis label='my-stat' refticks=(values)
fitpolicy=thin grid values=(0 to 1.0 by 0.01);
keylegend/ title=" " position=top;
title ' ';
format y2 5.2;
run;
The VALUES option on the ROWAXIS statement might conflict with PERCENT being assigned to Y2. Make sure your "* 100" is factored into your tick value list.
Thanks!
Dan
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.