Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proc Gchart - order of columns

Status
Not open for further replies.

OUSteve

Programmer
Jan 12, 2007
2
0
0
GB
Hi,

I've got the following SAS code creating a graph for me:

proc gchart data=output.monthcount2;
vbar strmonth1/
group=yr
subgroup=txnid
sumvar=_FREQ_
name='outiswk'
maxis=axis1;
label _FREQ_ = 'Transactions';

format txnid $txnname.;
format strmonth1 $smon.;

run;

The months are being selected by a user from a web page, so you can't guarentee which ones they will choose, but they can only choose a start and an end month, and the stats are generated for all those months between.

My problem is that this graph is ordering the months alphabetically once the $smon format function has been performed (it changes the string value of the month into a 3 char description, e.g. '1' = 'Jan', '2' = 'Feb' etc). The only way I can find round it is to change the month descriprions to '01Jan', '02Feb' etc, but this looks poor, plus people may be confused the column means 1st Jan, 2nd Feb etc.

Is there any way to order the columns by the month numerical value, before that value becomes formatted?

As I say, not all 12 months will be chosen.

Thanks very much,

Steve
 
I have been having the exact same problem this week, and I found a note in the SAS doco that basically said that for GCHART ordering takes place after the formatting. For one of the other chart types, it takes place before ordering. Not useful.

There is one way around this, and that is to specify the columns to be displayed.
First you put the "HAXIS = AXIS2" in vbar options, then after that statement add in an Axis statement like this:-
Code:
Axis2 LABEL=( "Month" )
      order=("JAN","FEB","MAR");
      ;
Now, as you don't know which months are being selected until runtime, I would use the data produced to create a macro variable containing all the months selected. IE
Code:
proc sort data=output.monthcount2 out=months nodupkey;
  by strmonth1;
run;

data _null_;
  retain months end=eof;
  month_qt = '"' !! put(strmonth1,$smon.) !! '"'
  if _n_ = 1 then months = month_qt ;
  else months = months !! ',' !! month_qt;
  if eof then
      call symput('MONTHS',months);
run;
Replace the list of values in the ORDER= option in your graph with &MONTHS and you should be sorted.



Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks very much Chris, I'll give that a try.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top