Data visualization with SAS programming

discrete order on grouped barchart

Reply
Contributor
Posts: 33

discrete order on grouped barchart

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;
SAS Super FREQ
Posts: 890

Re: discrete order on grouped barchart

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;
Contributor
Posts: 33

Re: discrete order on grouped barchart

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
Ask a Question
Discussion stats
  • 2 replies
  • 154 views
  • 0 likes
  • 2 in conversation