I am fairly new to using PROC TEMPLATE. I want to use it to plot multiple charts (scatter plots with other overlays), arranged in a grid pattern, and output to PDF. I have worked out how to plot to grids, and output to PDF, but I don't know how I can conditionally specify which rows in the data is used for each plot, so for example I want to plot a scatterplot of A, a separate scatterplot of B, and so on, arranging them in a 2 by 3 grid in landscape orientation.
I have tried using the GTL conditional logic with macros to generate multiple scatterplot statements conditional on Category, but couldn't get it to work. From what I gather I cannot use conditional statements to control which rows I want to plot. Is this correct? I then tried using conditional statements with macros on the PROC RENDER step, but it no longer gives me the grid pattern I specified in PROC TEMPLATE, and so I have concluded I need to have one PROC RENDER call. Is this correct?
Finally, this has led me to the conclusion that I have to transpose the data from a long file into a wide file. However, I have many Categories and it would make a data very wide. Am I on the right track at this stage, or are there more elegant solutions I have missed?
Thanks for your help
My data has the following general form:
Category X Y
A 1 10
A 2 15
... ... ...
B 1 100
B 2 150
... ... ...
etc etc etc
https://blogs.sas.com/content/graphicallyspeaking/2017/05/29/advanced-ods-graphics-gtl-expressions/
See this post. Rather than plotting a variable, I plot an expression that excludes some observations:
The DATA step reads the graph template from the file temp.temp. The CALL EXECUTE statements write code to a buffer and then submit that code to SAS when the DATA step concludes. In this case, the DATA step submits a PROC TEMPLATE statement, a statement that has two modified options, and all of the other statements that are stored in the template file. When the DATA step finds an X=CORRX option it replaces it with:
x=eval(ifn(corrgroup = 'Observation', ., corrx)) |
Similarly, it replaces y=CORRY with:
y=eval(ifn(corrgroup = 'Observation', ., corry)) |
Before you spend too much time on the GTL, ask yourself whether you can use PROC SGPANEL to create these scatter plots with overlays. For example, the following call creates a panel of scatter plots and overlays regression curves:
proc sgpanel data=sashelp.cars(where=(Type^='Hybrid'));
panelby Type;
scatter x=weight y=MPG_City;
reg x=weight y=MPG_City / degree=2 nomarkers;
run;
Thanks Rick. My plots (partial dependency plots) need to have independent axes (xaxis, yaxis, and yaxis2), while I understand PROC SGPANEL allows one axis to be independent at a time.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: