I have been using SAS for a while, but my coding knowledge is still limited, particularly in regards to graphical aspects. I have just run some analyses based on a repeated measures design using proc mixed as per the code below (in SAS 9.4):
proc mixed data=heic;
class Time Fam IDs;
model drink = Time heic | Dep Age / solution CL ddfm=kr;
repeated Time / type=ar(1) subject=IDs;
random Fam;
store heic_drink;
run;
After extensive reading online, I managed to figure out how to create the contour plots using proc plm, as shown below:
proc plm source=heic_drink;
effectplot contour (x=Dep y=heic);
run;
The plots are great, and are excellent to graphically illustrate interactions between continuous variables. But I am not satisfied with the ranges for both x and y axes that the software selects by default. I've found that, for a number of the models, the values at the upper and lower ends of the range on both axes are somewhat misleading, as they are making major extrapolations that could not be robustly inferred from the data set. So I just want to manually define the range for each axis.
I thought this would be very simple to do, but after hours and hours searching online, and even contacting SAS support, I still don't know if it is possible to make such minor modifications to the plot. And just to clarify, I don't need to re-draw the plot using other procedures, as the contour plots created by proc plm are great. I am just hoping it is possible to add a line or two of coding to the proc plm syntax to manually re-set the ranges on both x and y axis.
I would be extremely grateful for any help with this issue!
🙂👍
I don't think it is possible "to add a line or two of coding to the proc plm syntax to manually re-set the ranges on both x and y axis."
I sometimes tell people that the goal of ODS graphics is to produce graphs that are appropriate 95% of the time for 95% of the users. The syntax in SAS procedures does not support all the options that are available in PROC SGPLOT (or the GTL language) for controlling things like axes, labels, and titles.
When you want to modify things like axes, labels, legends, etc, you should output the data to a SAS data set and use PROC SGPLOT or GTL to create the modifications that you need.
Hello @derraik and welcome to the SAS Support Communities (as a first-time poster)!
I was curious whether a minor change to the underlying ODS template could achieve what you want. Normally I don't edit these templates, but a successful attempt in 2020 (which did not damage the original templates) encouraged me (EDIT: see the warning at the bottom of this post, though).
First of all, I created the default contour plot using dataset pr from Example 79.2 Repeated Measures of the PROC MIXED documentation, but with an additional continuous variable x:
x=rand('normal');
(created before each of the four OUTPUT statements).
Here is the PROC MIXED code from the above example with the new model variable and your STORE statement added:
proc mixed data=pr method=ml; class Person Gender; model y = Gender Age x Gender*Age / s; repeated / type=ar(1) sub=Person r; store heic_drink; run;
Then I used x and age in the EFFECTPLOT statement of PROC PLM:
ods graphics on;
proc plm source=heic_drink;
effectplot contour (x=x y=age);
run;
Result:
The next steps are described in items 1 - 3 of the 2020 post mentioned above, except that the template to be edited is ContourFit in the Graphics subfolder of folder PLM (instead of Mixed).
I simply copied the whole PROC TEMPLATE step from there into the Enhanced Editor and edited just two lines according to Setting the Data Range and Tick Values on a Linear Axis: In order to limit the x-axis arbitrarily to the interval [-1.5, 1.5] and the y-axis to [9,13], I inserted the VIEWMIN= and VIEWMAX= options shown below.
... layout overlay / aspectratio=1 yaxisopts=(gridDisplay=auto_off label= _XLABEL2 shortlabel=_SHORTXLABEL2 offsetmin=0 offsetmax=0 linearopts=(viewmin=9 viewmax=13 thresholdmin=0 thresholdmax=0)) xaxisopts=(gridDisplay =auto_off label=_XLABEL1 shortlabel=_SHORTXLABEL1 offsetmin=0 offsetmax=0 linearopts=(viewmin=-1.5 viewmax=1.5 thresholdmin=0 thresholdmax=0)); ...
After submitting the modified PROC TEMPLATE step (which saved the customized template to WORK.TEMPLAT, i.e., a temporary location) the same PROC PLM step as above created this graph:
So the axes were modified as intended.
To return to the original template I deleted the customized version in the WORK library:
proc template;
delete Stat.Lmr.Graphics.ContourFit;
run;
and verified that PROC PLM now produced the original plot again.
Late edit (2022-03-09):
CAUTION: Thereafter, when I tried to open a second Templates window (View --> Templates) without a good reason as the first was still open, my SAS 9.4M5 session stopped responding, had to be terminated via "SAS System Close" and yet the Autosave file of the Enhanced Editor was deleted (luckily it didn't contain relevant code)! In a very similar situation this happened in March 2022 again. So, be careful and save everything before playing around with the ODS templates.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.