Data visualization with SAS programming

Custom ordering of categorical axis - SGPLOT, PROC GCHART

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 79
Accepted Solution

Custom ordering of categorical axis - SGPLOT, PROC GCHART

 

 

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

 


Accepted Solutions
Solution
‎03-01-2016 10:37 PM
SAS Super FREQ
Posts: 925

Re: Custom ordering of categorical axis - SGPLOT, PROC GCHART

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;

View solution in original post


All Replies
Solution
‎03-01-2016 10:37 PM
SAS Super FREQ
Posts: 925

Re: Custom ordering of categorical axis - SGPLOT, PROC GCHART

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 508 views
  • 1 like
  • 2 in conversation