Hi all,
I'm trying to create a horizontal stacked bar chart to eventually export into Excel. I have my data but I can't get the chart working. Here's what I have so far :
To get the 100% stacked bar chart, follow the article at https://blogs.sas.com/content/iml/2014/04/08/construct-a-stacked-bar-chart-in-sas-where-each-bar-equ...
To get the special colors, you can use the STYLEATTRS statement or a discrete attribute map. See Consistent Group Colors by Value - Graphically Speaking
Here is the creation of the stacked plot. You can use names or Hex values for assigning colors:
data new; input lead $ north south east west; datalines; Joe 29 5 1 3 Suzie 4 6 8 19 Fred 109 8 2 36 Chris 235 48 29 54 ; data Long; set new; Region = 1; Sales = north; output; Region = 2; Sales = south; output; Region = 3; Sales = east; output; Region = 4; Sales = west; output; keep Lead Region Sales; run; /* make a stacked bar chart with 100% https://blogs.sas.com/content/iml/2014/04/08/construct-a-stacked-bar-chart-in-sas-where-each-bar-equals-100.html */ proc sort data=Long; by Lead Region; run; proc freq data=Long noprint order=data; by Lead; /* X categories on BY statement */ tables Region / out=FreqOut; /* Y (stacked groups) on TABLES statement */ weight Sales; run; proc print; run; /* assign names and colors to regions */ proc format; value RegionFmt 1 = "North" 2 = "South" 3 = "East" 4 = "West"; run; %let MyColors = Green Yellow Red Cyan; title "Sales Progress"; proc sgplot data=FreqOut; format Region RegionFmt.; styleattrs datacolors=(&MyColors);
hbar Lead / response=Percent group=Region groupdisplay=stack outlineattrs=(color=darkgray);yaxis discreteorder=data;
xaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group"; run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.