From my extensive Google searching, I have not been able to find a solution to this problem. I am wondering if what I want to do is possible in SAS.
I need to create a rather large graph. I basically have 3 grouping variables. The first is number of variants (0 or 1). This variable determines the bars. The second group is investigator site. This clusters the bars together. The third is country. This is a panelby variable. Below is the code that I am using (sample data attached).
ods graphics / reset width=10in height=4in;
proc sgpanel data=site;
/* where country in ('BR','CO'); */
panelby country / onepanel layout=columnlattice colheaderpos=bottom noborder novarname;
vbar siteid / group=nvariants groupdisplay=cluster grouporder=data;
rowaxis display=(nolabel);
colaxis display=(nolabel);
run;
I am running into 2 issues:
Subgroup of my graph:
Basically, I want to swap what is happening in both issues. I want NVARIANTS to create a spot for each possibilitiy, even if it's not there, but I want it to NOT create a spot for each site unless it is found in that country.
This is what I get on my full data (very cluttered):
But this is what I want the graph to look like (generated manually in Excel, butI have been asked to automate in SAS):
How about this one ?
proc import datafile='c:\temp\BarChartSampleData.xlsx' out=have dbms=xlsx replace;
run;
ods graphics /width=1200px height=600px;
proc sgplot data=have;
where NVARIANTS ne '.';
styleattrs datacolors=(darkred grey);
vbarbasic INVNAME/group=NVARIANTS stat=freq groupdisplay=cluster nooutline ;
block x=INVNAME block=COUNTRY/nofill labelattrs=(size=40 weight=bold);
xaxis fitpolicy=rotate VALUESROTATE=VERTICAL label='Country/PI';
yaxis grid label='Subject Counts';
keylegend /title='' noborder autooutline;
quit;
How about this one ?
proc import datafile='c:\temp\BarChartSampleData.xlsx' out=have dbms=xlsx replace;
run;
ods graphics /width=1200px height=600px;
proc sgplot data=have;
where NVARIANTS ne '.';
styleattrs datacolors=(darkred grey);
vbarbasic INVNAME/group=NVARIANTS stat=freq groupdisplay=cluster nooutline ;
block x=INVNAME block=COUNTRY/nofill labelattrs=(size=40 weight=bold);
xaxis fitpolicy=rotate VALUESROTATE=VERTICAL label='Country/PI';
yaxis grid label='Subject Counts';
keylegend /title='' noborder autooutline;
quit;
You are a genius. I don't think I would have figured all this out even after weeks of researching online. This saved me a ton of time. I used to be very proficient in SAS graphs, but after I left my first employer 8 years ago, I haven't used graphs much, and I have lost a lot of my skills. Thank you so much for the refresher course.
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.
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.