BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jimhorne
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

View solution in original post

9 REPLIES 9
ballardw
Super User

@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.

jimhorne
Obsidian | Level 7

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.

DanH_sas
SAS Super FREQ

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
Obsidian | Level 7

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.

DanH_sas
SAS Super FREQ

Unlitmately, the SGPANEL is using the DATAPANEL or DATALATTICE layouts of GTL, so this solution would work there as well.

jimhorne
Obsidian | Level 7

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

DanH_sas
SAS Super FREQ

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.

jimhorne
Obsidian | Level 7

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.

DanH_sas
SAS Super FREQ

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: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 2102 views
  • 0 likes
  • 3 in conversation