I'm trying to create some stacked barcharts by page number of percentages. Each page number has a different number of parameters included (each page is grouped by number of potential response options) - the page with the most parameters has 14 bars, the remaining pages have less. I want the bars on each page to be the same width. I couldn't see any option that did this (SAS automatically makes the bars wider on the pages with fewer parameters) so as a workaround I am creating dummy parameters and using different numbers of dummy parameters to make up the total number of parameters on each page to be 14. This works fine when I plot PARAMN as the rowaxis without a format and the bars have the same width on every page. If I assign a format to the rowaxis so it is the parameter label for the true parameters I am plotting, and blank for the dummy parameters, it then changes the graph so it only plots the first of the dummy parameters. If I assign different labels for each dummy parameter it plots fine, but I want the row axis values to be missing for every dummy parameter so it's essentially just blank space. Any idea of how I can do this? Code below (so it works outside of the macro)
proc sgpanel data=final;
where pageno=1;
panelby avisitn / novarname;
hbar paramn / response=percent group=aval name="plot" ;
colaxis label='Percent of Total Frequency';
rowaxis label=' ';
keylegend "plot"/ title="Item Response";
format avisitn avisitn. paramn param. aval grp1_.;
run;It would be very helpful if you could post some data and desired output to replicate your issue.
Create some dummy variables to make bar has the same width is a good idea. If you do not want to display the special level which is the value you created in your data, could try option VALUESDISPLAY= .
proc sort data=sashelp.heart out=x;
by weight_status;
run;
data x;
set x;
if weight_status='Normal' and bp_status='Normal' then weight=0;
run;
proc sgpanel data=x;
where weight_status='Normal';
panelby status / novarname;
hbar bp_status / response=weight group=sex name="plot" nozerobars nooutline ;
colaxis label='Percent of Total Frequency';
rowaxis label=' ' values=('High' 'Normal' 'Optimal') valuesdisplay=('High' ' ' 'Optimal') ;
keylegend "plot"/ title="Item Response";
run;
How about some example data in the form of a working data set then demonstrates the issue, which I think means the example needs to have a couple different Pageno values as well as the definition code for the three custom formats.
May need to go into some detail on the nature of the "dummy" variables as well. If multiple values get mapped to the same value then all the values only get one bar in the graph.
Since you mention "outside of a macro" then if your variable names, such as Paramn, or formats actually differ inside the macro then perhaps you need to supply the macro code as well as some working data.
It would also likely help if you could show an example of what your graph(s) are supposed to resemble. Sometimes the data needs to be rearranged for some types of plots.
It would be very helpful if you could post some data and desired output to replicate your issue.
Create some dummy variables to make bar has the same width is a good idea. If you do not want to display the special level which is the value you created in your data, could try option VALUESDISPLAY= .
proc sort data=sashelp.heart out=x;
by weight_status;
run;
data x;
set x;
if weight_status='Normal' and bp_status='Normal' then weight=0;
run;
proc sgpanel data=x;
where weight_status='Normal';
panelby status / novarname;
hbar bp_status / response=weight group=sex name="plot" nozerobars nooutline ;
colaxis label='Percent of Total Frequency';
rowaxis label=' ' values=('High' 'Normal' 'Optimal') valuesdisplay=('High' ' ' 'Optimal') ;
keylegend "plot"/ title="Item Response";
run;
valuesdisplay worked - thanks so much!
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.