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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.