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:
Update - Merged into original post to simplify.
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.
Are you using SAS 9.2 or SAS 9.3?
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!
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.
If you're stuck at 9.2, and need a non-SG-proc solution, here are a few traditional SAS/Graph charts where I annotate a "table" of data below the bars. Perhaps this will give you some ideas you can combine with what you learned from Tech Support...
Subprime Mortgage Channel Portfolio (SAS/Graph chart)
http://robslink.com/SAS/democd33/subprime_info.htm
Average Monthly Temperature - SAS/Graph chart
http://robslink.com/SAS/democd18/temper_info.htm
Rugby Chart (a SAS/Graph proof-of-concept)
http://robslink.com/SAS/democd33/rugby_info.htm
Kaplan-Meier Curves - Created with SAS/Graph
http://robslink.com/SAS/democd19/kaplan_info.htm
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!
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.