Data visualization with SAS programming

Place bar graph data in group order

Reply
Contributor
Posts: 28

Place bar graph data in group order

Cannot seem to figure out how to place the group bars in order of red yellow green and blue, places by data magnitude instead of data sort or group name.  Is there a way to do it by group name or data sort.

 

 

data Data_Tbl;
attrib
SntmntType informat=$20.
Source informat=$20.
;
infile datalines delimiter='09'x dsd firstobs=1;
input SntmntType $ Source $ Column1;
datalines;
Ovrll StsfctnPrcnt_1 -0.384
Ovrll StsfctnPrcnt_2 -0.046
Ovrll StsfctnPrcnt_3 0.224
Ovrll StsfctnPrcnt_4 0.346
;
run;

proc template;
define statgraph StkdClstrBr;
begingraph / datacolors=(verylightred verylightyellow verylightgreen lightblue);
entrytitle '';
layout overlay / xaxisopts=(Label=" ") yaxisopts=(Label=" ");
barchart x=SntmntType y=Column1 / orient=horizontal grouporder=data group=Source
name='a';
discretelegend 'a';
endlayout;
endgraph;
end;
run;
proc sgrender data=Data_Tbl template=StkdClstrBr;
run;

SAS Super FREQ
Posts: 1,077

Re: Place bar graph data in group order

I see a few issues with your code.  I had to change the attributes to read in the data correctly.  Your data has only 1 category value (X=SntmntType) and 4 groups.  Default GroupDisplay is STACK.  If you want these side by side, use GroupDisplay=CLUSTER.  To get them in the order you want, you have to order the values yourself in the data, using grouporder=data.

 

data Data_Tbl;
attrib
/*SntmntType informat=$15.*/
Source informat=$15.
;
/*infile datalines delimiter='09'x dsd firstobs=1; */
input SntmntType $ Source $ Column1;
datalines;
Ovrll StsfctnPrcnt_1 -0.384
Ovrll StsfctnPrcnt_2 -0.046
Ovrll StsfctnPrcnt_3 0.224
Ovrll StsfctnPrcnt_4 0.346
;
run;
proc print;run;

proc template;
define statgraph StkdClstrBr;
begingraph / datacolors=(verylightred verylightyellow verylightgreen lightblue);
entrytitle '';
layout overlay / xaxisopts=(Label=" ") yaxisopts=(Label=" ");
barchart x=SntmntType y=Column1 / orient=horizontal grouporder=data group=Source
name='a';
discretelegend 'a';
endlayout;
endgraph;
end;
run;

ods listing close;
ods listing;
proc sgrender data=Data_Tbl template=StkdClstrBr;
run;

Ask a Question
Discussion stats
  • 1 reply
  • 238 views
  • 0 likes
  • 2 in conversation