BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mduarte
Quartz | Level 8

 

 

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

1 REPLY 1
DanH_sas
SAS Super FREQ

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;

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
  • 1 reply
  • 5437 views
  • 1 like
  • 2 in conversation