I have a 3x3 Layout Lattice graph but I only have 7 graphs I produce for it. How can I make the only graph on the third row appear on the right or in the center instead of on the left as it will normally?
Here is one way to do it using the SPARSE option on the PANELBY statement, which will render cells that contain no observations:
/* Your data */
data example;
do p = 1 to 7;
do x=1 to 10;
y=ranuni(123);
output;
end;
end;
/* Add something that will sort */
/* before the last cell. */
data movecell;
set example end=eof;
output;
if eof then do;
p=6.5;
x=.;
y=.;
output;
end;
/* Clear the header */
proc format;
value clear 6.5=" ";
run;
proc sgpanel data=movecell;
format p clear.;
panelby p / sparse columns=3 onepanel novarname;
scatter x=x y=y;
run;
@jimhorne wrote:
I have a 3x3 Layout Lattice graph but I only have 7 graphs I produce for it. How can I make the only graph on the third row appear on the right or in the center instead of on the left as it will normally?
It would help to show the code you are currently using.
To control that kind of order you may want to investigate LAYOUT DATALATTICE or DATAPANEL where the row/column positions are controlled by the values of one or two classification variables.
I didn't show code because I am really looking for a generic solution. And while DATALATTICE or DATAPANEL might work, they require the classification variables to be the same across cells. The overwhelming majority of graphs I build consist of independent cells and unfortunately those layouts will not work in that circumstance.
Here is one way to do it using the SPARSE option on the PANELBY statement, which will render cells that contain no observations:
/* Your data */
data example;
do p = 1 to 7;
do x=1 to 10;
y=ranuni(123);
output;
end;
end;
/* Add something that will sort */
/* before the last cell. */
data movecell;
set example end=eof;
output;
if eof then do;
p=6.5;
x=.;
y=.;
output;
end;
/* Clear the header */
proc format;
value clear 6.5=" ";
run;
proc sgpanel data=movecell;
format p clear.;
panelby p / sparse columns=3 onepanel novarname;
scatter x=x y=y;
run;
Thanks Dan. That is an elegant solution to the question I asked. It also points out to me that I really asked the wrong question because what I really need is how to do it in GTL not in SGPANEL. Unfortunately for my peace of mind that is not the question I meant to ask.
Unlitmately, the SGPANEL is using the DATAPANEL or DATALATTICE layouts of GTL, so this solution would work there as well.
So it sounds as if there is not a good way to insert empty cells if each cell is independent of the others, but only if they share common classification variables. While it's not the answer I wanted it's good to know. Thanks
In GTL, you can use a LATTICE layout for independent plots, but a DATALATTICE is for classification variables. Sound like you really want a LATTICE, which would require you to use GTL.
And LAYOUT LATTICE is what I use today. I was just hoping for a way in it where I could control the position of blank cells instead of having it done for me. Sometimes I would like to group cells different than the default orfer. It's only an issue for me when I have rows with not enough cells to fill them up.
The way you do that in GTL with a LAYOUT LATTICE is to put a blank ENTRY in the cell. Here is a simple example:
proc template;
define statgraph layout_test;
begingraph;
layout lattice / columns=3;
layout overlay;
barchart x=age y=weight / stat=mean;
endlayout;
entry " ";
layout overlay;
barchart x=age y=height / stat=mean;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.class template=layout_test;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.