Hello Community,
I recently started learning SAS, completed my certification, But never exposed to the Graphs before. I got little familar with SGPLOT/ SGPANEL. I am looking to learn proc template. I googled alot and looked on the SAS website I did not got much luck. My professor said, try this website. I am new here , forgive for my mistakes.
My questions is How to display the counts inside the Graph? How to display '0' when there is no count? My case make 'custom' is zero count.
I have the following Graph, I want to display the counts Inside the graph for each make. I see on SAS website to use the Inner margin and axistable options When I tried I am getting Errors. Can you please help how I can achieve this using Proc template. I am not sure how this website work. if I posted in wrong place please forgive me and guide me to right place. Thank you.
Reference Code for inner margin :https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatgraph/p0v5nj3waz75w4n1s2y70echq6im.htm#...
data cars;
set sashelp.cars;
where origin = 'USA' and make in ('Saturn' 'Jeep' 'Mercury');
output;
run;
data xx;
make = 'custom';
origin = 'USA';
Run;
data cars1;
set cars xx;
run;
proc freq data = cars;
table make/out = freq;
run;
proc template;
define statgraph boxplot;
begingraph;
entrytitle "City Mileage for Vehicle Types";
layout overlay /
xaxisopts=(offsetmin=0.1 offsetmax=0.1);
boxplot y=mpg_city x=make /
datalabel=make spread=true;
/* Wrong in my code what to enter?*/
innermargin / align=bottom opaque=true backgroundcolor=cxf5f5f5;
axistable x= @@@ value=@@@ /
stat=Sum display=(label)
headerlabel="Counts"
headerlabelattrs=GraphLabelText
valueattrs=(size=9pt weight=bold)
;
endinnermargin;
endlayout;
endgraph;
end;
run;
proc sgrender data=cars1 template=boxplot;
label type="Vehicle Type";
run;
Why not use PROC SGPLOT ? Since your grahic is not too complicated.
data cars; set sashelp.cars; where origin = 'USA' and make in ('Saturn' 'Jeep' 'Mercury'); output; run; data xx; make = 'custom'; origin = 'USA'; Run; data cars1; set cars xx; run; proc freq data = cars; table make/out = freq; run; data cars2; merge cars1 freq(keep=make count); by make; run; proc template; define statgraph boxplot; begingraph; entrytitle "City Mileage for Vehicle Types"; layout overlay / xaxisopts=(offsetmin=0.1 offsetmax=0.1); boxplot y=mpg_city x=make / datalabel=make spread=true; /* Wrong in my code what to enter?*/ innermargin / align=bottom opaque=true backgroundcolor=cxf5f5f5; axistable x=make value=count/ stat=mean valueattrs=(size=9pt weight=bold) labelattrs=(weight=bold) ; endinnermargin; endlayout; endgraph; end; run; options missing=0; proc sgrender data=cars2 template=boxplot; label type="Vehicle Type" count='Counts'; run;
Why not use PROC SGPLOT ? Since your grahic is not too complicated.
data cars; set sashelp.cars; where origin = 'USA' and make in ('Saturn' 'Jeep' 'Mercury'); output; run; data xx; make = 'custom'; origin = 'USA'; Run; data cars1; set cars xx; run; proc freq data = cars; table make/out = freq; run; data cars2; merge cars1 freq(keep=make count); by make; run; proc template; define statgraph boxplot; begingraph; entrytitle "City Mileage for Vehicle Types"; layout overlay / xaxisopts=(offsetmin=0.1 offsetmax=0.1); boxplot y=mpg_city x=make / datalabel=make spread=true; /* Wrong in my code what to enter?*/ innermargin / align=bottom opaque=true backgroundcolor=cxf5f5f5; axistable x=make value=count/ stat=mean valueattrs=(size=9pt weight=bold) labelattrs=(weight=bold) ; endinnermargin; endlayout; endgraph; end; run; options missing=0; proc sgrender data=cars2 template=boxplot; label type="Vehicle Type" count='Counts'; run;
You are genius. Thanks. saved lot of time , I was still searching in internet for that like two days..
While this does not help with your specific question, if you are new to ODS Graphics, the SG procedures, and the template language, my free book might help. https://support.sas.com/documentation/prod-p/grstat/9.4/en/PDF/odsbasicg.pdf
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.