BookmarkSubscribeRSS Feed
Calcite | Level 5

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

Rhodochrosite | Level 12


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^='Hybrid'));
panelby Type;
scatter x=weight y=MPG_City;
reg x=weight y=MPG_City / degree=2 nomarkers;


Calcite | Level 5

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.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3 in conversation