BookmarkSubscribeRSS Feed
asumsie
Obsidian | Level 7

Updated

Hello, Trying to create a barchart that has statistics printed at the bottom.  The below template is close to what I need but the gridded layout gives each row the same area in the graph, creating a lot of white space and causing the graph itself to be very small.  I tried switching to a lattice in order to assign row weights since I receive an error (ERROR 685-580: This statement cannot be used in this block. - which I believe is caused by nesting a datalattice within a lattice.  Any ideas?  I am using SAS 9.2 2M3. Thanks.

proc template;        
define statgraph cmtrix;  
begingraph / includeMissingDiscrete=true border=false;

layout gridded;

layout datalattice columnvar = qstest/ ;

layout prototype;

barchart X=week y=mean / group=week barlabel=false orient=vertical name='a';

scatterplot X=week y=mean / yerrorlower=lclm markerattrs=(size=0) errorbarattrs=(thickness=1) datatransparency=0.6;

endlayout;

endlayout;

entry halign=left 'N';

blockplot x=qstest block=n12 / display=(values label) valuehalign=center label='Week 12' repeatedvalues=true;

blockplot x=qstest block=n24 / display=(values label) valuehalign=center label='Week 24' repeatedvalues=true;

blockplot x=qstest block=n36 / display=(values label) valuehalign=center label='Week 36' repeatedvalues=true;

discretelegend 'a' / title='Week: ' across=3 border=false;

endlayout;

endgraph;
end;      

run;

data means;

input qstest $ week mean n12 n24 n36;

datalines;

a 12 3 3 4 6

b 12 2 2 5 4

c 12 3 4 6 6

d 12 3 8 5 3

a 24 8 3 8 5

b 24 4 9 9 6

c 24 6 8 3 7

d 24 9 9 2 9

a 36 8 3 8 5

b 36 4 9 9 6

c 36 6 8 3 7

d 36 9 9 2 9

;

run;

ods listing close;

ods rtf style=GraphRTF startpage=no;

ods select sgrender; 

ods noptitle;

ods graphics on;

proc sgrender data=means template="cmtrix"; run;

ods graphics off;

ods rtf close;

ods listing;

Update:

In case it is unclear - I am trying to produce a graph that is similar to:

http://support.sas.com/kb/39/166.html

But with summary statistics printed underneath the graph like in:

http://support.sas.com/kb/39/132.html

6 REPLIES 6
asumsie
Obsidian | Level 7

Update - Merged into original post to simplify.

asumsie
Obsidian | Level 7

Is there something I am not providing in order to facilitate help?  I have simplified and rephrased the problem to hopefully make things more clear.

Jay54
Meteorite | Level 14

Are you using SAS 9.2 or SAS 9.3?

AncaTilea
Pyrite | Level 9

I assume something is not quite right with your data, but maybe I don't understand it.

The reason for me saying this is because I can't figure out what the n12, n24 and n36 variables represent.

Anyhow, here is a code that will create a table of your data below the plot.

proc template;       

define statgraph cmtrix; 
begingraph / includeMissingDiscrete=true border=false;

layout gridded;

layout datalattice columnvar = qstest/ ;
layout prototype;
barchart X=week y=mean / group=week barlabel=false orient=vertical name='a';

endlayout;
endlayout;
layout lattice / columns = 1 rowweights = (.15 .25);

blockplot x=qstest block=n12 /class = week repeatedvalues=true display=(values label outline) valuehalign=center label='Week 12' valueattrs=graphdata1 labelattrs=graphdata1;
blockplot x=qstest block=n24 /class = week repeatedvalues=true display=(values label outline) valuehalign=center label='Week 24' valueattrs=graphdata2 labelattrs=graphdata2;
blockplot x=qstest block=n36 /class = week repeatedvalues=true display=(values label outline) valuehalign=center label='Week 36' valueattrs=graphdata3 labelattrs=graphdata3;
discretelegend 'a' / title='Week: ' across=3 border=false;
endlayout;

endlayout;

endgraph;
end;     

run;

Let me know if this makes any sense to you.

(It hardly does to me)

Good luck!

asumsie
Obsidian | Level 7

AncaTilea - the nXX variables are to summarize the number of subjects at a given timepoint.  I did try your code - thanks for it - it comes close but not quite in terms of spacing/weighting, much like my own attempts.  I did end up talking to SAS tech support directly and they indicated in order to really get what I wanted I needed to upgrade to 9.3 (a difficult proposition working in a clinical environment mid-study) so they provided an alternative of placing the subject counts within the graph itself using a scatterplot.  This had its own drawbacks, but it was close to what was being asked for working under 9.2.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1950 views
  • 0 likes
  • 4 in conversation