BookmarkSubscribeRSS Feed
Jennys
Calcite | Level 5
Hello

I have a grouped barchart that I want to sort by the group variable. In the example below the graph starts with the lowest value on variable group (1949-1953) , but I want it to start with the highest value. Ie it should start with group 1959-1963. I have tried to use the discreteorder = data on the colaxis, but that option affects the values within each group. Is this possible?

I also want to have only ONE label on the reference line, in this case 3 labels are printed...

tks
jenny

/* ---------- Code ---------------------*/
proc format;
value sex
1 = 'Male'
2 = 'Female';
run;
proc format;
value group
1 = '1949-1953'
2 = '1954-1958'
3 = '1959-1963';
run;

data chartds;
medel = 150; group = 1; sex = 1;output;
medel = 180; group = 1; sex = 2;output;
medel = 200; group = 2; sex = 2;output;
medel = 100; group = 2; sex = 1;output;
medel = 80; group = 3; sex = 2;output;
medel = 130; group = 3; sex = 1;output;
run;

/* Order the data by group */
proc sort data = chartds;
by descending group;
run;


proc sgpanel data=chartds;
panelby group / layout=columnlattice
onepanel noborder novarname
colheaderpos=bottom;
vbar sex / response=medel group=sex;
rowaxis grid offsetmax=0.05 ;
colaxis display=none discreteorder=data ;
refline 110 /label=("Test refline") lineattrs=(pattern=2 thickness=2px color=black);
format sex sex. group group. ;label medel = 'eu/hour';
label group = "Age class";
keylegend /position=bottom title="Salary";
run;
2 REPLIES 2
DanH_sas
SAS Super FREQ
Currently, the values for the panel variable are always sorted ascending. You can work around this by assigning your numeric tags in reverse numerical order. As for the reference line, the reference line specification is replaced in each cell, which is why you get the label three time. Another way to label is to put the reference line label in a legend. Try the modified code below and see if that labeling works for you.

Thanks!
Dan

proc sgpanel data=chartds;
panelby group / layout=columnlattice
onepanel noborder novarname
colheaderpos=bottom;
vbar sex / response=medel group=sex name="bar";
rowaxis grid offsetmax=0.05 ;
colaxis display=none discreteorder=data ;
refline 110 / legendlabel="Test refline" name="ref"
lineattrs=(pattern=2 thickness=2px color=black);
format sex sex. group group. ;
label medel = 'eu/hour';
label group = "Age class";
keylegend "bar" "ref" /position=bottom title="Salary"; run;
Jennys
Calcite | Level 5
Thank you Dan. I was hoping for a nice option for this, since i have a lot of variables and formats for my graphs. Well, well.

I will put the text in the label instead, as you suggested.

Tks
jenny

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1345 views
  • 0 likes
  • 2 in conversation