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

Hello all,

 

Can I use the "BLOCK" option with VBAR statement in PROC SGPLOT? The example below shows that it works with SCATTER but I could not make it work with VBAR?

 

Thanks a lot in advance!

 

Recep

 

DATA test;
INPUT Hospital $ age_group $ count level $;
CARDS;
Hosp1 0-16 0 Level1
Hosp1 17-74 10 Level1
Hosp1 75+ 1 Level1
Hosp2 0-16 14 Level1
Hosp3 0-16 1 Level1
Hosp3 17-74 16 Level1
Hosp4 0-16 1 Level2
Hosp4 17-74 4 Level2
Hosp5 17-74 7 Level2
Hosp6 17-74 80 Level2
Hosp6 75+ 2 Level2
Hosp7 17-74 4 Level3
Hosp8 17-74 9 Level3
Hosp9 17-74 95 Level3
Hosp9 75+ 1 Level3
Hosp10 0-16 1 Level3
Hosp10 17-74 27 Level3
;
RUN;

proc sgplot data=test;
block x=hospital block=level / filltype=alternate fillattrs=GraphAltBlock altfillattrs=GraphBlock transparency=0.7;
scatter x=hospital y=count/ group=age_group
grouporder=ascending
MARKERATTRS=(symbol=circlefilled size=10)
LEGENDLABEL= "Hospitalizations"
datalabel
datalabelpos=top;

xaxis display=all fitpolicy=rotate grid;
yaxis offsetmin=0.02 grid;
title ' ';
run;

proc sgplot data=test;
block x=hospital block=level / filltype=alternate fillattrs=GraphAltBlock altfillattrs=GraphBlock transparency=0.7;
vbar hospital / response=count
group=age_group
stat=sum
datalabel
datalabelattrs=(weight=bold)
nooutline
barwidth=0.5;
xaxis display=(nolabel);
yaxis grid label='Number of hospitalizations';
title ' ';
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Have a look here for the Plot Type Compatibility:
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p0yud64khw8fuin1xgr85dgxbb7t.ht...

 

So as @Reeza mentioned to combine SCATTER, BLOCK and a bar chart you have to use VBARPARM or VBARBASIC.

For VBARPARM you need to precalculate the values you want to plot.

 

Change VBAR to VBARBASIC  in your second SGPLOT and you should get what you need.

 

Also have a look at this blog post https://blogs.sas.com/content/iml/2021/04/14/overlay-graphs-basic-bar-chart.html by @Rick_SAS 

View solution in original post

4 REPLIES 4
Reeza
Super User
VBARPARM is usually required when you want to combine different graph types. Can you show a bit of what you're trying to do?
Recep
Quartz | Level 8

Thanks @Reeza ! I'm trying to replicate the BLOCK option in the first SGPLOT example with SCATTER in the second example with VBAR. If you run the examples you can see that hospitals are grouped by their "Levels" in the SGPLOT with SCATTER but not with the VBAR.

BrunoMueller
SAS Super FREQ

Have a look here for the Plot Type Compatibility:
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p0yud64khw8fuin1xgr85dgxbb7t.ht...

 

So as @Reeza mentioned to combine SCATTER, BLOCK and a bar chart you have to use VBARPARM or VBARBASIC.

For VBARPARM you need to precalculate the values you want to plot.

 

Change VBAR to VBARBASIC  in your second SGPLOT and you should get what you need.

 

Also have a look at this blog post https://blogs.sas.com/content/iml/2021/04/14/overlay-graphs-basic-bar-chart.html by @Rick_SAS 

Recep
Quartz | Level 8

Thanks @BrunoMueller ! Simply changing the VBAR statement to VBARBASIC helped what I wanted to do.

 

Best,

 

Recep

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 1572 views
  • 2 likes
  • 3 in conversation