Goal: Create a chart for each year, where each chart x-axis is ordered according to a custom ordering.
Questions:
* I am close with SGPANEL, but I actually don't want a panel, I want one chart per year, how can I adjust this using the SG plot methods?
* How can I do this with PROC GChart? (I am learning SAS, so knowing both ways would be an advantage ... )
* Is it possible to get the unformatted value from a value formatted with a custom format (defined with PROC FORMAT)?
/* read in data */ data one; input State $2. Sales Year; datalines; GA 12500 2001 GA 12500 2002 GA 12500 2003 NC 7500 2001 NC 7500 2002 NC 7500 2003 NY 17600 2001 NY 17600 2002 NY 17600 2003 SC 9800 2001 SC 9800 2002 SC 9800 2003 VA 5200 2001 VA 5200 2002 VA 5200 2003 ; run; /* sort */ /* specify state order */ proc format; value $state_order "VA" = 1 "SC" = 2 "NC" = 3 "GA" = 4 "NY" = 5 ; run; data one; set one; Order = input(put(state, $state_order.), 2.); run; proc sort data = one; by Year Order; run; /* Method 1: SGPANEL - but I want to change this to one chart per year, ie. I want to do this with PROC SGPLOT and not PROC SGPANEL*/ proc sgpanel data=one; panelby Year/ novarname spacing=5 columns=1; vbar State /response=Sales; colaxis label = 'State'; rowaxis label = 'Year' discreteorder=data; run; /* METHOD 2: GCHART - I need the reverse of put(state, $state_order.) */ proc gchart data=one; vbar Order / discrete sumvar=Sales; by Year; label order ='State'; format order state_order.; /* This doesn't work - I need the reverse */ run;
Note: Example adapted from http://support.sas.com/kb/24/916.html
Here is the SGPLOT code to use with your data processing:
proc sgplot data=one;
by year;
xaxis label = 'State' discreteorder=data;
yaxis label = 'Sales';
vbar State / response=Sales;
run;
Here is the SGPLOT code to use with your data processing:
proc sgplot data=one;
by year;
xaxis label = 'State' discreteorder=data;
yaxis label = 'Sales';
vbar State / response=Sales;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.