Hello Team,
I want to display 'Number of subjects'(nsubjs) in legend level with each grade but iam trying to work on the below code in text statement but none of the option is working. Will be there any solution to display subjects in legend with each grade by removing subjects on top of the bar. For reference i am attaching figure and code. Please provide your insights which would help me.
DATA:
Figure:
proc sgpanel data=final dattrmap=attrmap ;
by rowlbl;
panelby tptn / layout=columnlattice onepanel noborder novarname colheaderpos=bottom headerattrs=(size=7.5) spacing=10;
format tptn tptf.;
vbarparm category=trtn response=percent/ group=grade displaybaseline=auto;
text x=trtn y=percent text=nsubjs / position=left pad=(bottom=25px) contributeoffsets=none ;
format trtn trt2f.;
colaxistable nsubjs ;
rowaxis values=(0 to 100 by 10) label='Percentage of Subjects with Reactions' ;
keylegend /exclude = ("PERCENT") border;
run;
I want the figure to be displayed as below figure image highlighted in yellow:
I think that perhaps you want an COLAXISTABLE statement. Without data can't make specific code suggestions though.
It might be as simple as replacing your Text statement with
Colaxistable nsubjs;
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
The XAXISTABLEs and YAXISTABLEs in the SGPLOT procedure can be either inside or outside of the data area; but the equivalent ROWAXISTABLEs and COLAXISTABLEs in the SGPANEL procedure can only be in the inside, since classification panels can have multiple rows and columns. If you absolutely want external axis tables, one approach you could take would be to use SGPLOT with a BY-group, use the UNIFORM option to create uniform axes and groups, and use ODS LAYOUT to lay them out in a panel fashion. If you are interested in that approach and need more information, let me know.
Here is a little example comparable to your scenario:
ods _all_ close;
ods html path="." file="sales.html";
ods layout gridded advance=bygroup columns=2;
proc sort data=sashelp.prdsale out=sales; by quarter; run;
ods layout start;
proc sgplot data=sales uniform=all;
by quarter;
vbar product / response=actual group=region;
xaxistable actual / class=region location=outside;
run;
ods layout end;
ods html close;
Hi Danh_sas,
Thank you so much it worked. I need a small update i want to display 'severe' grade as highlighted in yellow in a key legend even though if it is not in data. Is there any way to display by using any options:
or i should a create a dummy dataset to insert 'severe' column into data to represent in graph? please provide your insights
The best way for you to do that is to use a Discrete Attributes Map, with a SHOW value of ATTRMAP. This option tells the procedure to let the attrmap dictate the content of the grouped legend instead of the group column in the data. If you've never used an attrmap, notice the DATTRMAP option on the procedure statement and the ATTRID on the VBAR statement to bind the plot to the correct attrmap. I also removed the CLASS option from the XAXISTABLE, which was not needed here.
ods _all_ close;
ods html path="." file="sales.html";
ods layout gridded advance=bygroup columns=2;
data attrmap;
retain id "myid" show "attrmap";
length value $ 5 fillstyleelement $ 10;
input value $ fillstyleelement $;
cards;
East GraphData1
West GraphData2
North GraphData3
South GraphData4
;
run;
proc sort data=sashelp.prdsale out=sales; by quarter; run;
ods layout start;
proc sgplot data=sales uniform=all dattrmap=attrmap;
by quarter;
vbar product / response=actual group=region attrid=myid;
xaxistable actual / location=outside;
run;
ods layout end;
ods html close;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.