BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASplebe
Calcite | Level 5

Hello!

I am trying to add statistics columns to a GPLOT hbar chart.  In ODS using the code below I can make a nice looking hbar chart using the following code:

HBAR TESTVAR / RESPONSE=COUNT CATEGORYORDER=RESPDESC
STAT=SUM DATALABELPOS=LEFT DATALABEL ;              
XAXIS LABEL='MONTHLY TOTAL' ;                       

SAS example 1.png

 

I can also get the need frequency statistics by a simple  PROC FREQ:

 

PROC FREQ DATA=PLOT ORDER=FREQ NOPRINT ;
TABLES TESTVAR/OUT=PRINT OUTCUM ;       
WEIGHT COUNT;   

Annotation (2).png

But what I really want is to combine these two to make a chart/table like the one I created by cutting and pasting the above together (slightly different data):

Annotation (3).png

 

Possible with GPLOT?  I do not have SAS Graphics.    

 

Thank you.

                      

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@SASplebe wrote:

I have base SAS graphics (e.g. GPLOT, etc.) but not SAS/GRAPH.   Apologies, I should have been clearer in that last sentence. 


Basically the rule is show a complete procedure or data step, from the first line through the Run statement.

Sometimes people ask "why is value X not showing" and then after getting the entire code we find something like:

Where somevar ne "X";

which means they specifically excluded the value.

Many statements interact and the graphic procedures may be more of that than others because you can overlay one graph on top of another and if the values are "not nice" one bit of the graph isn't seen at all.

 

See if this gives you enough to get further:

proc freq data=sashelp.class noprint;
  tables age /out=summary outcum;
run;

proc sgplot data=summary;
   HBAR age / RESPONSE=COUNT CATEGORYORDER=RESPDESC
    STAT=SUM DATALABELPOS=LEFT DATALABEL ;              
   XAXIS LABEL='MONTHLY TOTAL' ;    
   yaxistable count percent cum_freq cum_pct/ 
       location=inside position=right 
   ;
run; 

Note that I provided a data set you should have available to test code with and complete procedures.

 

Not really sure why you want count twice though.

 

Use LABEL Statements to change the text of the yaxistable labels.

 

 

View solution in original post

7 REPLIES 7
Reeza
Super User
Are you sure you don't have SGPLOT? It's been included in Base for a while now so that would mean either you're on a supremely old version of SAS or using WPS or something similar.

Use the following to see your version and licensing.

proc product_status;run;
SASplebe
Calcite | Level 5

I have base SAS graphics (e.g. GPLOT, etc.) but not SAS/GRAPH.   Apologies, I should have been clearer in that last sentence. 

ballardw
Super User

@SASplebe wrote:

I have base SAS graphics (e.g. GPLOT, etc.) but not SAS/GRAPH.   Apologies, I should have been clearer in that last sentence. 


Basically the rule is show a complete procedure or data step, from the first line through the Run statement.

Sometimes people ask "why is value X not showing" and then after getting the entire code we find something like:

Where somevar ne "X";

which means they specifically excluded the value.

Many statements interact and the graphic procedures may be more of that than others because you can overlay one graph on top of another and if the values are "not nice" one bit of the graph isn't seen at all.

 

See if this gives you enough to get further:

proc freq data=sashelp.class noprint;
  tables age /out=summary outcum;
run;

proc sgplot data=summary;
   HBAR age / RESPONSE=COUNT CATEGORYORDER=RESPDESC
    STAT=SUM DATALABELPOS=LEFT DATALABEL ;              
   XAXIS LABEL='MONTHLY TOTAL' ;    
   yaxistable count percent cum_freq cum_pct/ 
       location=inside position=right 
   ;
run; 

Note that I provided a data set you should have available to test code with and complete procedures.

 

Not really sure why you want count twice though.

 

Use LABEL Statements to change the text of the yaxistable labels.

 

 

Reeza
Super User

@SASplebe wrote:

I have base SAS graphics (e.g. GPLOT, etc.) but not SAS/GRAPH.   Apologies, I should have been clearer in that last sentence. 


SAS/GRAPH is GPLOT + GCHART and that family of procedures.

 

ODS GRAPHICS includes the SG family of graphics.

 

SG graphics are supported in all the newer versions since 9.3 so that's what you should be using moving forward, not GCHART or GPLOT.

SASplebe
Calcite | Level 5
Ballardw,
Thank you so much, once I saw your yaxistable statement the proverbial light bulb turned on. Besides adding that statement I had to move my PROC FREQ statement above the SGPLOT procedure. Complete working code is below. Note that I XX'd out some title info and changed variable names to remove identifiable data, though this has no effect on the code logic. Very happy with the result, thanks again.

DATA PLOT;
%LET REP_VAL=1 ;
%LET YEAR_DT= %SYSFUNC(YEAR("&SYSDATE"D));
%LET PREVMTH= %SYSFUNC( PUTN( %SYSFUNC( DATE() )-10, MONNAME10. ));
SET PDB.APITOT;
REP_MTH=MONTH(DDD) ;
IF REP_MTH=&REP_VAL ;
ODS LISTING CLOSE;
ODS GRAPHICS ON/
MAXOBS=20000000
WIDTH=15.5IN
HEIGHT=25IN ;
ODS NOPTITLE;
ODS PDF FILE=OUTPDF NOTOC;
PROC FREQ DATA=PLOT ORDER=FREQ NOPRINT ;
TABLES TESTVAR/OUT=OUTPUT OUTCUM;
WEIGHT COUNT;
PROC SGPLOT DATA=OUTPUT;
HBAR TESTVAR / RESPONSE=COUNT CATEGORYORDER=RESPDESC
DATALABELATTRS=(SIZE=6PT COLOR=BLUE)
STAT=SUM DATALABELPOS=LEFT DATALABEL ;
YAXIS LABEL='SERVICE NAME'
VALUEATTRS=(COLOR=GREEN SIZE=8PT) ;
XAXIS LABEL='API MONTHLY TOTAL'
VALUEATTRS=(COLOR=GREEN SIZE=10PT) ;
YAXISTABLE PERCENT CUM_FREQ CUM_PCT/
LOCATION=INSIDE POSITION=RIGHT ;
TITLE "XXXXXXXX MONTHLY SUMMARY" ;
TITLE2 "TOTAL BY XXXX XXXX PRODUCTION PLEX";
TITLE3 "&PREVMTH &YEAR_DT" ;
TITLE4 "DATA SOURCE: XXXXXXX RECORDS" ;
FORMAT COUNT CUM_FREQ COMMA12. PERCENT CUM_PCT 5.2 ;
LABEL
PERCENT='PERCENT OF TOTAL'
CUM_FREQ='CUMULATIVE FREQUENCY' ;
RUN ;
ODS PDF CLOSE ;
ODS LISTING ;
SASplebe
Calcite | Level 5

Here is the report output:  

Annotation (4).png

SASplebe
Calcite | Level 5

Reeza, you are correct.  My question/problem had to do with SGPLOT - doh!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 968 views
  • 4 likes
  • 3 in conversation