BookmarkSubscribeRSS Feed
Reeza
Super User

 

I have some survey response data that I'd like to graph before receiving an intervention. I'm about half way there, but there are somethings I'd like but can't find a way to implement. 

 

1. Add a space between each bar 'pair'. It works for the first one, but not the second unless I made a stupid mistake (highly likely).

2. Customize the legend with the colour entries for each version. 

3. Change colours for second bar, grey in middle but different colour scheme on outsides. 

 

Details:

To separate the bars, I'd like to group them in pairs. Each Bbar is part of a pair - before/after comparison. So I'd like to graph them side by side, BUT have space between the items to help separate the topics and increase the ease of interpreting the charts.  

Second, I'd like to add a customized legend that itemizes the colours in the graph - haven't touched this item yet in my sample code. And last, but not least, if possible I'd like the second graph to have different colours than the top bar, except grey for the middle on both. I'm open to suggestions on better ways to present this data by the way, but this was the best I could come up with. I also realize this may put me into the GTL world, but I'd like to determine what's even possible in SAS. I have SAS 9.4 TS1M3 but can get 4 if there's a valid reason to push for the new install.

 

Thanks in advance!

 

*Generate sample data;
data have;
infile cards dlm = '09'x truncover;
input Bars $1.	Group	Positive	Negative;
cards;
1	1	10	-10
1	2	15	-15
1	3	35	-15
2	1	10	-10
2	2	15	-15
2	3	35	-15
3	1		
4	1	10	-10
4	2	15	-15
4	3	35	-15
5	1	10	-10
5	2	15	-15
5	3	35	-15
6	1		
7	1	10	-10
7	2	15	-15
7	3	35	-15
8	1	10	-10
8	2	15	-15
8	3	35	-15	
;
run;

*Formats for positive percent and labels for bars;
proc format ;
picture positive_fmt low-high = '099%';
value $ label_fmt
'1' = 'My category number 1 V1'
'2' = 'My category number 1 V2'
'3' = " "
'4' = 'My category number 2 V1'
'5' = 'My category number 2 V2'
'6' = " "
'7' = 'My category number 3 V1'
'8' = 'My category number 3 V2';
*'9' = " "
;
run;

*colors for first bar;
%let color1=3182bd;
%let color2=9ecae1;
%let color3=bdbdbd;
%let color4=bdbdbd;
%let color5=fdae6b;
%let color6=e6550d;

*colors for second bar;
%let color7=bdbdbd;
%let color8=bcbddc;
%let color9=756bb1;
%let color10=bdbdbd;
%let color11=a1d99b;
%let color12=31a354;


*Create graphs;
ods pdf file='/folders/myfolders/Sample Graphs.pdf' style=meadow dpi=300;
options orientation=portrait nodate nonumber;
ods graphics on / noborder;

proc sgplot data=have;
*where positive ne .; *FOR TESTING;
styleattrs datacolors=(CX&color4. CX&color5. CX&color6.   CX&color3.  CX&color1.  CX&color2. CX&color7. CX&color8. cx&color9. CX&color10. CX&color11. cx&color12.  );
hbarparm category = bars response=positive / group = group nooutline dataskin=none barwidth=0.8 ;
hbarparm category = bars response=negative / group = group nooutline dataskin=none barwidth=0.8 ;
xaxis values=(-100 -75 -50 -25 0 25 50 75 100) grid gridattrs=(color=lightgrey);
format bars $label_fmt. positive negative positive_fmt.;
yaxis display=(nolabel) ;
run;quit;

ods pdf close;
2 REPLIES 2
Jay54
Meteorite | Level 14

To create gaps in the data on the category axis, the "gap" value cannot all be " ".  The same values are aggregated as a aingle " ".  Also, multiple blanks will appear as 1 blank.  To illustrate, format 3 as "." and 6 as "..".  Now you will see both the gaps, of course they are labeled "." and "..".  To get clean blanks, use nbsp ('A0'x) instead of blanks.

 

See:  http://blogs.sas.com/content/graphicallyspeaking/2012/09/03/doing-more-with-nbsp/

 

Not sure I understand the other issues. 

ballardw
Super User

Is this similar to what you wanted for the breaks:

proc sgplot data=have;
*where positive ne .; *FOR TESTING;
   styleattrs datacolors=(CX&color4. CX&color5. CX&color6.   CX&color3.  CX&color1.  CX&color2. CX&color7. CX&color8. cx&color9. CX&color10. CX&color11. cx&color12.  );
   hbarparm category = bars response=positive / group = group nooutline dataskin=none barwidth=0.8 ;
   hbarparm category = bars response=negative / group = group nooutline dataskin=none barwidth=0.8 ;
   xaxis values=(-100 -75 -50 -25 0 25 50 75 100) grid gridattrs=(color=lightgrey);
   format /*bars $label_fmt.*/ positive negative positive_fmt.;
   yaxis display=(nolabel) valuesformat=$label_fmt. ;
run;quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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