Hello SAS community,
I wonder if there is a way to create a panel of graphs with n-columns and m-rows, with a common x-axis. I also want to add the slope of the regression lines. I expand below.
I used the following code:
ods graphics / reset height=7.5in width=8.925in;
proc sgscatter data=data;
plot Y1*X Y2*X Y3*X Y4*X Y5*X Y6*X Y7*X Y8*X Y9*X Y10*X Y11*X Y12*X / group=tto reg rows=4 columns=3 ;
run;
and I obtained the panel below (let's call it Panel A):
I would like to have the output panel to look like the one I show next (I edited Panel A by using mspaint) (let's call it Panel B):
Panel B saves space. Also, is there any way to add the slopes for the regression lines per TTO in Panel B (for example, at the bottom right corner of each graph)?
Thank you for any suggestion.
Marcel
Here is some code to get you started. Hope this helps.
data have;
do group = 1 to 12;
do _N_ = 1 to 100;
tto = (rand('uniform') > .5);
x = rand('uniform') * 120;
y = rand('uniform') * 120 + 2;
output;
end;
end;
run;
proc sort data=have;
by group tto;
run;
ods graphics off;
proc reg data=have;
model y = x;
by group tto;
ods output ParameterEstimates=PE(where=(Variable = 'x'));
run;
data help;
length est $ 200;
do until (last.group);
set PE;
by group;
est = catx('', est, 'tto', tto, ': ', put(Estimate, best5.));
end;
run;
data plot;
merge have help;
by group;
run;
ods graphics on / width=15in;
ods graphics on / height=20in;
proc sgpanel data=plot;
panelby group / columns=3 rows=4;
reg x=x y=y / group=tto;
inset est / position=se nolabel;
run;
You can use Proc SGPanel and do something like this.
For the slopes, you can edit the code a bit from the blog post How to use PROC SGPLOT to display the slope and intercept of a regression line and use the Inset Statement in Proc SGPanel.
data have;
do group = 1 to 12;
do _N_ = 1 to 100;
tto = (rand('uniform') > .5);
x = rand('integer', 30, 120);
y = rand('integer', 0, 1500);
output;
end;
end;
run;
proc sgpanel data=have;
panelby group / rows=4 columns=3;
reg x=x y=y / group=tto;
run;
Here is some code to get you started. Hope this helps.
data have;
do group = 1 to 12;
do _N_ = 1 to 100;
tto = (rand('uniform') > .5);
x = rand('uniform') * 120;
y = rand('uniform') * 120 + 2;
output;
end;
end;
run;
proc sort data=have;
by group tto;
run;
ods graphics off;
proc reg data=have;
model y = x;
by group tto;
ods output ParameterEstimates=PE(where=(Variable = 'x'));
run;
data help;
length est $ 200;
do until (last.group);
set PE;
by group;
est = catx('', est, 'tto', tto, ': ', put(Estimate, best5.));
end;
run;
data plot;
merge have help;
by group;
run;
ods graphics on / width=15in;
ods graphics on / height=20in;
proc sgpanel data=plot;
panelby group / columns=3 rows=4;
reg x=x y=y / group=tto;
inset est / position=se nolabel;
run;
Dear Draycut,
Nice SAS coding and a beautiful output.
It is just what I need.
Regards,
Marcel
Glad to help 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.