gops11
gops11

Reputation: 73

Stalk bar chart in controlled order in SAS

I want to create stlak bar charts, The column WORKSCOPE having HSB,OHS,RES. but I want to reorder the WORKSCOPE in the order of OHS,HSB,RES in the stalk bar. Usually default its taking in alphabetical order. how can I achieve it.

goptions reset=all;
    goptions colors=(red blue green);
    legend1   label=none
     order=('OHS' 'HSB' 'RES');

    proc gchart data=FINALREPV3;
    vbar year / discrete type=sum sumvar=VALUE

    subgroup=WORKSCOPE legend=legend1 ;
    run;

Upvotes: 2

Views: 1519

Answers (1)

SRSwift
SRSwift

Reputation: 1710

You can create a sorting variable beforehand, use it to sort the input data and then plot using proc sgplot with xaxis discreteorder = data.

/* Create dummy sorting variable */
data want;
  set finalrepv3;
  if workscope = "OHS" then _sort = 1;
  if workscope = "HBS" then _sort = 2;
  if workscope = "RES" then _sort = 3;
run;

/* Put the data in the required order */
proc sort data = want;
  by _sort;
run;

/* Create the plot */
proc sgplot data = want;
  vbar year / group = workscope response = value stat = sum;
  /* Request that the x axis respect the data's order */
  xaxis discreteorder = data;
run;

Upvotes: 2

Related Questions