BookmarkSubscribeRSS Feed
Bryan
Obsidian | Level 7

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;

1 REPLY 1
Jay54
Meteorite | Level 14

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 795 views
  • 0 likes
  • 2 in conversation