BookmarkSubscribeRSS Feed
Nobody
Calcite | Level 5
I am attempting to create a 2 row x 1 column layout using proc template and proc sgrender.

proc template;
define statgraph allgrafs ;
begingraph / designwidth=800px designheight=800px ;
EntryTitle halign=center "&titlbl" ;
layout lattice / columns = 1 rows=2
columngutter=5 rowgutter=50
;
cell ;
cellheader ;
entry "XXX vs. Time" ;
endcellheader ;
layout overlay / cycleattrs=true
xaxisopts=(...)
yaxisopts=( );
ReferenceLine... ;
SeriesPlot X=nomtime Y=grafval / group=grpval LegendLabel="Mean" NAME="mean";
DiscreteLegend "mean" / Location=Inside across=1 valueattrs=(size=6pt) valign=top halign=left ;
endlayout;
endcell ;

cell ;
cellheader ;
entry "XXX vs. Time" ;
endcellheader ;
layout overlay / cycleattrs=true
xaxisopts=(...)
yaxisopts=( );
ReferenceLine... ;
SeriesPlot X=nomtime Y=grafval / group=grpval LegendLabel="Median" NAME="med";
DiscreteLegend "med" / Location=Inside across=1 valueattrs=(size=6pt) valign=top halign=left ;
endlayout;
endcell ;

endlayout ;
Entryfootnote halign=left "Output File: &prog._&ref..rtf" ;
Entryfootnote halign=left "&source" ;
endgraph ;
end ;
run ;

proc sgrender data=graphdat
template = allgrafs ;
run ;

The GRAPHDAT data set is created by merging two data sets from different sources (but with identical structure and variable names) together just prior to the proc template step. To get this to work I have had to rename variables from the second data set. What I would like to do is simply concatenate the two data sets together and use the same variable names in both cell blocks. But to do this I would have to conditionally execute each block based on the value of a source data set variable contained in the concatenated data set. I have tried placing a if (), endif; block at various levels within each cell block but have not been able to get the 2 x 1 layout. Is there a GTL solution to this problem?

Thank you
4 REPLIES 4
Jay54
Meteorite | Level 14
You seem to be looking for a "where clause" for each cell, and want to include only the right subset in each cell. GTL does not support such where clauses in the syntax, as it essentially duplicates this feature from SAS data step. So, your first approach is the right one. The "IF" conditional syntax in GTL is not designed for this.

Alternatively, you can use classification panels with the concatenated data, as long as the two sets are classified using another colunn. You can create a classification panel using DATALATTICE or a DATAPANEL. As long as the plots in each cell are identical, and use the simple plots such as ScatterPlot, SeriesPlot, BarChart, etc, you can do this. This is defined in the embedded LAYOUT PROTOTYPE.

You will need to assign another classifier variable (say TYPE) for the two different set of observations. In LAYOUT DATAPANEL use classvars=(type). If values for type are "MEAN" and "MEDIAN" you will get two cells with the subsets of the data. Each cell will have a cell header automatically, with the class value in it. If the cells are stacked (two rows, 1 column) the X axis will be uniform. If you don't want this, then the lattice structure should be 1 row, 2 columns.

You can probably use PROC SGPANEL to do this. SGPANEL is preferred as it will allow you to use all plot statements in the prototype, and the syntax will be very simple:

proc sgpanel data=data;
panelby type / columns=2;
series x= y= / options;
refline < options >
rowaxis < options >;
colaxis < options >
run;
Nobody
Calcite | Level 5
Thank you very much for your help Sanjay. I will definitely read up on DATALATTICE/DATAPANEL, but your statement "As long as the plots in each cell are identical" tells me that I should stick with the current method.

As a follow-up, there is the possibilty that the two original data sets will not have the same number of records so that after the rename and merge there are "extra" records with missing x,y and group values in the data for either the top or bottom graph. While this does not appear to effect the graphs, it does generate a phantom line in the graph legend that has no label value attached (I assume because these are the records where group is missing). Is there a way to get rid of this phantom value in the legend box if the data set being graphed cannot be conditionally executed via GTL?
DanH_sas
SAS Super FREQ
Yes, just repeat the last group value through the remaining observations. It will have no effect on the plot but the legend will be happy 🙂

Thanks!
Dan
Nobody
Calcite | Level 5
Thank you Dan. I was hoping to avoid that since it feels a lot like hard-coding.

So just to confirm in the following example,

SeriesPlot X=nomtime Y=grafval / group=grpval LegendLabel="&tstatlbl" NAME="&tstat";

if NOMTIME, GRAFVAL, and GRPVAL are all missing for one or more records there is no way to suppress the printing of a blank line in the graph legend. Is that correct?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 884 views
  • 0 likes
  • 3 in conversation