BookmarkSubscribeRSS Feed
JacquesR
Quartz | Level 8

I am battling to get the right proportional representation I need.

I am trying to plot the median number of patients and the median number of beds for different hospital types in different study arms.

data demo;
  infile datalines dsd truncover;
  input @1 Hospital_Type $2. @4 Rx $1. @6 NHospitals 2. @9 NPatients 5.1 Beds 5.1;
  format Beds BEST.;
  label Hospital_Type="Hospital Type" Rx="Study Arm" NPatients="Frequency Count" Beds="Beds";
datalines;
BH E 1  291   117
BH T 1  567   287
BH G 4  655   265
DH E 8  196.5 109
DH T 10 290.5 113.5
DH G 10 217.5 99.5
PU E 12 89    50
PU T 7  47    60
PU G 9  61    48
RH E 7  37    34
RH T 10 47.5  32.5
RH G 5  30    16
;;;;
run;
proc print data=demo;run;
proc sgplot
	noautolegend
	noborder
	data=demo;
	y2axis display=none;
	bubble x=Hospital_Type y=Rx size=Beds
	/nofill proportional datalabel=Beds datalabelattrs=(color=black size=8 weight=bold) datalabelpos=center;
	bubble x=Hospital_Type y=Rx size=NPatients
	/y2axis nofill proportional lineattrs=(pattern=2) datalabel=NPatients datalabelattrs=(color=black size=8 weight=bold style=italic) datalabelpos=top;
run;

This is what I got:

SGPlot48.png

Absscale does not work, because the axes are discrete.

I tried mucking around with bradiusmax, and got this:

	bubble x=Hospital_Type y=Rx size=Beds
	/nofill proportional bradiusmax=28.7 datalabel=Beds datalabelattrs=(color=black size=8 weight=bold) datalabelpos=center;
	bubble x=Hospital_Type y=Rx size=NPatients
	/y2axis nofill proportional bradiusmax=65.5 lineattrs=(pattern=2) datalabel=NPatients datalabelattrs=(color=black size=8 weight=bold style=italic) datalabelpos=top;

SGPlot49.png

I'm not entirely convinced that that is right, but my eyes might be fooling me. I need each bubble to represent the proportional surface area of the actual value it represents.

Also, I need the spacing on the y axis to be greater, so that the bubbles do not overlap and the labels are accordingly easier to interpret.

 

Any help would be greatly appreciated.

4 REPLIES 4
Ksharp
Super User

You could try to change data structure and make graph bigger to avoid overlap problem.

 

data demo;
  infile datalines dsd truncover;
  input @1 Hospital_Type $2. @4 Rx $1. @6 NHospitals 2. @9 NPatients 5.1 Beds 5.1;
  format Beds BEST.;
  label Hospital_Type="Hospital Type" Rx="Study Arm" NPatients="Frequency Count" Beds="Beds";
datalines;
BH E 1  291   117
BH T 1  567   287
BH G 4  655   265
DH E 8  196.5 109
DH T 10 290.5 113.5
DH G 10 217.5 99.5
PU E 12 89    50
PU T 7  47    60
PU G 9  61    48
RH E 7  37    34
RH T 10 47.5  32.5
RH G 5  30    16
;;;;
run;

data demo1;
 set demo;
 label='Beds';size=Beds;output;
 label='NPatients'; size=NPatients;output;
run;

ods graphics/ height=600px width=800px;
proc sgplot 
 noautolegend
 noborder
 data=demo1;
 
 bubble x=Hospital_Type y=Rx size=size
 /group=label nofill proportional bradiusmax=65.5 datalabel=size
     datalabelattrs=(color=black size=8 weight=bold) datalabelpos=top;
run;
JacquesR
Quartz | Level 8

Thanks @Ksharp 

 

You forgot about the variable length for label (which I named PlotGroup below), and the data labels were superimposed, but overall, your suggestion got me more or less what I wanted. This is how I tweaked it:

data demo;
    set demo;
    PlotGroup='Beds    ';Size=Beds;OUTPUT;
    PlotGroup='Patients'; size=NPatients;output;
run;
proc sgplot
	noautolegend
	noborder
	data=demo;
	y2axis display=none;
	bubble x=Hospital_Type y=Rx size=Size /group=PlotGroup nofill proportional bradiusmax=65.5 name="bubble";
    text x=Hospital_Type y=Rx text=size /position=center group=PlotGroup groupdisplay=cluster textattrs=(size=10 weight=bold);
    keylegend "bubble";
run;
GraphGuy
Meteorite | Level 14

I think you need to first work on your input statement - I believe it is reading in some values incorrectly. For example, I believe it is reading in the DH E number of beds as 10.9, rather than 109.

JacquesR
Quartz | Level 8

Nope, sorry, it's not that.

What I mean is that the underlying data are sound, even though you have correctly spotted an error.

I have the data as PROC FREQ output from a larger dataset and wanted to provide working data for whoever might want to take this on.

I generated the data step from the actual underlying dataset with https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/ 

It didn't do a perfect job, so I modified it a bit, and messed it up.

Apologies for that.

Here is the correct data step:

data demo;
  infile datalines dsd truncover;
  input @1 Hospital_Type $2. @4 Rx $1. @6 NHospitals 2. @9 NPatients 5.1 @15 Beds 5.1;
  label Hospital_Type="Hospital Type" Rx="Study Arm" NPatients="Frequency Count" Beds="Beds";
datalines;
BH E 1  291.0 117.0  
BH T 1  567.0 287.0  
BH G 4  655.0 265.0  
DH E 8  196.5 109.0  
DH T 10 290.5 113.5
DH G 10 217.5  99.5
PU E 12  89.0  50.0  
PU T 7   47.0  60.0  
PU G 9   61.0  48.0  
RH E 7   37.0  34.0  
RH T 10  47.5  32.5
RH G 5   30.0  16.0  
;;;;
run;
proc print data=demo;run;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 565 views
  • 2 likes
  • 3 in conversation