Data visualization with SAS programming

SAS/GRAPH: Subgroup ordering

Reply
Contributor
Posts: 55

SAS/GRAPH: Subgroup ordering

Hi,

Please find the below code for the graph. I need subgroup in this order if prodnum >=40 then this should come first and if prodnum <40 then second.

Currently prodnum in subgroup is ordered that is 2 14 18 40 44 50 60 70

Desired Output: 40 44 50 60 70 2 14 18

Also note that prodnum is dynamic after 18 you may expect 28 30 35 or any another value which is in chronological order.

Please help me in getting the desired output. Thanks in Advance.

  /* Set the graphics environment */                                                                                                     

goptions reset=all cback=white border htitle=12pt htext=10pt;                                                                          

/* Define the title */                                                                                                                 

title1 "Side-by-Side Subgrouped Bar Chart";                                                                                          

/* Define the axis characteristics */                                                                                                  

axis1 value=none label=none;                                                                                                         

axis2 label=(angle=90 "Actual Sales");                                                                                               

axis3 label=none;                                                                                                                    

/* Define the legend options */                                                                                                        

legend1 frame;                                                                                                                       

/* Generate the graph */                                                                                                               

proc gchart data=prodsale1;                                                                                                      

   vbar prodnum / subgroup=prodnum group=country sumvar=actual                                                                          

                  legend=legend1 space=0 gspace=4                                                                                       

                  maxis=axis1 raxis=axis2 gaxis=axis3;                                                                                  

run;                                                                                                                                   

quit;

Attachment
SAS Employee
Posts: 963

SAS/GRAPH: Subgroup ordering

"(Almost) any problem can be solved by a layer of indirection"  Smiley Happy

You can include some numeric values in your data, that are in the desired order, and then create a user-defined format to make those numeric values print as the desired text/numbers.  Here's a stripped-down example, with just the essentials:

data mydata;

input bar $ 1 desired_order desired_text value;

datalines;

A 1 40 1

A 2 44 1

A 3 50 1

A 4 60 1

A 5 70 1

A 6 2 1

A 7 14 1

A 8 18 1

;

run;

/* User-defined format to get subgroups in desired order */

proc sql; create table foo as select unique desired_order, desired_text from mydata; quit; run;

data control; set foo (rename = ( desired_order=start desired_text=label));

fmtname = 'subfmt';

type = 'N';

end = START;

run;

proc format lib=work cntlin=control;

run;

proc gchart data=mydata;

format desired_order subfmt.;

vbar bar / type=sum sumvar=value

subgroup=desired_order;

run;

Contributor
Posts: 55

SAS/GRAPH: Subgroup ordering

Hi,

Thanks for your code.

Post a Question
Discussion Stats
  • 2 replies
  • 200 views
  • 1 like
  • 2 in conversation