BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
StudentSASLearn
Obsidian | Level 7

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;

StudentSASLearn_0-1736223553077.pngStudentSASLearn_1-1736223592426.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

Ksharp_0-1736231214653.png

 

View solution in original post

3 REPLIES 3
Ksharp
Super User

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;

Ksharp_0-1736231214653.png

 

StudentSASLearn
Obsidian | Level 7

You are genius. Thanks. saved lot of time , I was still searching in internet for that like two days..

WarrenKuhfeld
Ammonite | Level 13

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1233 views
  • 2 likes
  • 3 in conversation