Multiple
classifiers sometimes have a hierarchical relationship, which results
in very sparse data when the classifier values are crossed. For example,
consider the following LAYOUT DATAPANEL statement:
layout datapanel classvars=(state city) / rows=4 columns=5;
Assume
that the data for the STATE and CITY classifiers contains information
for 20 states and their capitals. How many panels would you expect
to produce? One, or twenty? Or 400?
The answer
is one panel, which is the desired result. A single panel is produced
because even though the default DATAPANEL layout attempts to generate
a complete Cartesian product of the crossing values (400 STATE*CITY
crossings in this case), it does not create panel cells for crossings
that have no data. The SPARSE= option controls whether panel cells
are created when you have no observations for a crossing, and by default
SPARSE=FALSE.
The DATALATTICE
layout does not support a SPARSE= option. The DATALATTICE creates
a row / column for each unique value of the ROWVAR / COLUMNVAR. So
a cell is created for all crossings of the two variable values, thus
creating 400 cells.
Sometimes
there are unexpected gaps in the data when classification variables
are crossed. For example, suppose you are conducting a study where
a number of subjects each receives over time four treatments that
might lower the subject's heart rate after various amounts of physical
activity. However, assume that Subject 101 didn't get Treatment 3,
and Subject 102 didn't get Treatment 2. In this case, when you create
a DATAPANEL layout presenting four treatments for three subjects per
panel, the expected alignment of the columns does not work:
In this
situation, you can generate a placeholder cell whenever a subject
misses a treatment. To do so, specify SPARSE=TRUE for the layout panel.
proc template;
define statgraph sparse;
begingraph / designwidth=490px designheight=450px;
entrytitle "Heart Rates for Subjects";
layout datapanel classvars=(subject treatment) /
columns=4 rows=3
cellheightmin=50 cellwidthmin=50
skipemptycells=true
sparse=true
columnaxisopts=(display=(tickvalues))
rowaxisopts=(display=(label) offsetmin=0);
layout prototype;
barchart x=task y=heartrate / barlabel=true;
endlayout;
endlayout;
endgraph;
end;
run;
The SPARSE=
option does not apply to DATALATTICE layouts because they are inherently
sparse. When you specify two classifiers, the DATALATTICE layout manages
this situation automatically.
proc template;
define statgraph datalattice;
begingraph / designwidth=490px designheight=400px;
entrytitle "Heart Rates for Subjects";
layout datalattice rowvar=subject columnvar=treatment /
rows=3 rowgutter=5px
cellheightmin=50 cellwidthmin=50
rowheaders=left
skipemptycells=true
columnaxisopts=(display=(tickvalues))
rowaxisopts=(display=none displaysecondary=(label) offsetmin=0);
layout prototype;
barchart x=task y=heartrate / barlabel=true;
endlayout;
endlayout;
endgraph;
end;
run;