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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: