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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1021 views
  • 0 likes
  • 2 in conversation