I have used proc template and layout lattice to create two horizontal barchart panels side by side.
I have two consecutive Layout Overlay Barchart lines to create the two barcharts.
layout overlay
barchart
endlayout
layout overlay
barchart
endlayout
I also have the correct datarange union so that there is only one set of tick values on the left hand side. So far so good.
My problems begin when i have different numbers of bars in different datasets (the two panels will always have the same number of bars per dataset).
If i have fewer bars, the cells and barwidth expand to fill the space. If i have more bars, the barwidth shrinks to fit in the space. This i can often fix with ODS Graphics height.
I also have a second problem. In one dataset, the tick values on the left are very short and in another dataset the tick values are very long. For the short tick values, the panel width expands to fill the space. And for the longer tick values the panel width shrinks to fit the space.
Can i set the panel widths (and height) in stone so that SAS will not change it?
If i need to switch to sgpanel or layout datapanel, that should not be a problem.
Thank you for your help.
Strong suggestion with any question related to graphics programming: Provide the entire Proc Template and associated Proc Sgrender code. And since your issue involves differing behaviors with different data sets, at least two data sets to demonstrate your current behavior. The example data sets should be small and provided in the form of data step code.
If your code uses any custom formats or macro variables then please include the definitions of the formats in proc format code and how the macro variables are created or at least appropriate values.
There are so many options that interact within Proc Template that a skeleton and short description is usually going to be insufficient to diagnose and will generally require asking for the details of your code anyway.
IF you have something in your code that you think reveals too much about your sensitive data then reduce things to generic variable names and labels.
How about something like this:
/* Two original data sets with different bar counts and value lengths */
data one;
do x=1 to 5;
y=ranuni(123);
group="Group 1";
output;
y=ranuni(123);
group="Group 2";
output;
end;
run;
data two;
do x=1000 to 3000 by 1000;
y=ranuni(321);
group="Group 1";
output;
y=ranuni(321);
group="Group 2";
output;
end;
run;
/* Merge the two data datasets with a classifier column */
data one_prime;
set one;
name = "one";
run;
data two_prime;
set two;
name = "two";
run;
data merged;
merge one_prime two_prime;
by name;
run;
proc sgpanel data=merged;
panelby group name / layout=lattice onepanel proportional uniscale=column novarname;
hbar x / response=y;
run;
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.