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

I have a data have 4 REGION A,B,C,D  AND 22 different measures.

A have 6 measure, B have 8 measure ; c have 5 measure , d have 3 measures

 

 

Gender REGION measure  avedose

F                A         1            50  

F                A         2            53 

F                A         3            55  

F                A         4            52  

F                A         5            51  

F                A         6            53  

F                b         7            54  

F                b         8            49  

F                b         9            44  

F                b         10            32  

F                b         11            70  

……….

F                d         22            70  

…….

 

M               A         1            50  

…..

M               d         22            80  

 

 

I want compare mean of dose in different gender for each measure also can display the measures by REGION.

 

How to do sub plot with shared x -axis and legend and each plot use their own title?

 

title 'average dose by Measure and gender Groups';

title 'A';

  proc sgplot data=data(where=(REGION='A')) noborder nowall;

  hbar measure / response=dose stat=mean group=gender groupdisplay=cluster

           dataskin=pressed filltype=gradient baselineattrs=(thickness=0);

  xaxis display=(noline noticks nolabel) grid;

  yaxis display=(nolabel);

run;

  title ‘B’;

proc sgplot data=data(where=( REGION='B')) noborder nowall;

  hbar measure / response=dose stat=mean group=gender groupdisplay=cluster

           dataskin=pressed filltype=gradient baselineattrs=(thickness=0);

  xaxis display=(noline noticks nolabel) grid;

  yaxis display=(nolabel);

run;

run;

title 'C;

  proc sgplot data=data(where=( REGION='C')) noborder nowall;

  hbar measure / response=dose stat=mean group=gender groupdisplay=cluster

           dataskin=pressed filltype=gradient baselineattrs=(thickness=0);

  xaxis display=(noline noticks nolabel) grid;

  yaxis display=(nolabel);

run;

title 'C;

proc sgplot data=data(where=( REGION='D')) noborder nowall;

  hbar measure / response=dose stat=mean group=gender groupdisplay=cluster

           dataskin=pressed filltype=gradient baselineattrs=(thickness=0);

  xaxis display=(noline noticks nolabel) grid;

  yaxis display=(nolabel);

run;

 

 

 

or sgplot:

 

ods graphics / reset=all outputfmt=png height=3in width=7in;

title 'average dose by Measure and gender Groups';

title 'A';

proc sgpanel data=DATA;

  panelby MEASURE/ layout=columnlattice onepanel

          colheaderpos=bottom rows=1 novarname noborder;

  vbar GENDER/ group=GENDER response=DOSE stat=MEAN group=GENDER nostatlabel;

  colaxis display=none;

  rowaxis grid;

  where REGION='A';

  run;

  title ‘B’;

proc sgpanel data=DATA;

  panelby MEASURE/ layout=columnlattice onepanel

          colheaderpos=bottom rows=1 novarname noborder;

  vbar GENDER/ group=GENDER response=DOSE stat=MEAN group=GENDER nostatlabel;

  colaxis display=none;

  rowaxis grid;

  where REGION='B;

  run;

  title 'C;

proc sgpanel data=DATA;

  panelby MEASURE/ layout=columnlattice onepanel

          colheaderpos=bottom rows=1 novarname noborder;

  vbar GENDER/ group=GENDER response=DOSE stat=MEAN group=GENDER nostatlabel;

  colaxis display=none;

  rowaxis grid;

  where REGION=C';

  run;

  title 'D;

proc sgpanel data=DATA;

  panelby MEASURE/ layout=columnlattice onepanel

          colheaderpos=bottom rows=1 novarname noborder;

  vbar GENDER/ group=GENDER response=DOSE stat=MEAN group=GENDER nostatlabel;

  colaxis display=none;

  rowaxis grid;

  where REGION='D';

  run;

ods _all_ close;

ods preferences;

 

 

or  

https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/255-2008.pdf

 

this article had code below how can I wisely use this code to my case?

title1 "Product Sales";

proc sgpanel data=sashelp.prdsale; 

by year;  panelby quarter; 

rowaxis label="Sales"; 

vbar product / response=predict                 transparency=0.3;

 vbar product / response=actual barwidth=0.5                 transparency=0.3; run;

 

 Thank you so much for your helping!

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

You can use a FORMAT statement to force the DATALABEL to be integer:

 

proc sgplot data=data noborder nowall;
  format dose 2.0;
  by region;
  hbar measure / response=dose stat=mean  datalabel  group=gender groupdisplay=cluster dataskin=pressed filltype=gradient baselineattrs=(thickness=0);
  xaxis display=(noline noticks nolabel) grid;
  yaxis display=(nolabel);
run;

Hope this helps!

Dan

View solution in original post

7 REPLIES 7
DanH_sas
SAS Super FREQ

I think the best way to do this graph is by using PROC SGPANEL:

 

title 'average dose by Measure and gender Groups';
  proc sgpanel data=data;
  by region;
  panelby measure;
  hbar gender / response=dose stat=mean   dataskin=pressed 
          filltype=gradient baselineattrs=(thickness=0);
  colaxis display=(nolabel) grid;
  rowaxis display=(nolabel);
run;

 

Hope this helps!

Dan 

xinyao
Fluorite | Level 6
Dan, Thank you for your helping!
It worked pretty good! but any way can combine all subplot into one. Then can see all region in one graph.
DanH_sas
SAS Super FREQ

You might find this funny, but I was thinking about your example this morning when I was getting ready for work :-). I realized that I might have over-thought your original request. All you really needed to do was add a BY statement to SGPLOT. Try something like this:

 

title 'average dose by Measure and gender Groups';

proc sort data=data; by region; run;

proc sgplot data=data noborder nowall;
  by region;
  hbar measure / response=dose stat=mean group=gender groupdisplay=cluster
           dataskin=pressed filltype=gradient baselineattrs=(thickness=0);
  xaxis display=(noline noticks nolabel) grid;
  yaxis display=(nolabel);
run;

Hope this helps!

Dan

xinyao
Fluorite | Level 6
It's also worked well,
I want to find the best way to display results.Thank you so much! 🙂
xinyao
Fluorite | Level 6

Thank you Dan,

 

One more question, How can I use the datalabel option to request integer of mean values at each bar.

 

proc sort data=data; by region; run;

proc sgplot data=data noborder nowall;
 
by region;
  hbar measure
/ response=dose stat=mean  datalabel group=gender groupdisplay=cluster dataskin=pressed filltype=gradient baselineattrs=(thickness=0);
 
xaxis display=(noline noticks nolabel) grid;
 
yaxis display=(nolabel);
run;

 

 

DanH_sas
SAS Super FREQ

You can use a FORMAT statement to force the DATALABEL to be integer:

 

proc sgplot data=data noborder nowall;
  format dose 2.0;
  by region;
  hbar measure / response=dose stat=mean  datalabel  group=gender groupdisplay=cluster dataskin=pressed filltype=gradient baselineattrs=(thickness=0);
  xaxis display=(noline noticks nolabel) grid;
  yaxis display=(nolabel);
run;

Hope this helps!

Dan

xinyao
Fluorite | Level 6

Thank you so much!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1528 views
  • 1 like
  • 2 in conversation