I found a number of examples online for sorting the y-axis using the word descending but not for sgpanel / vbar, hbar.
In some cases sorting the data first helped in others descending just needed to be used with the hbar line.
Can this be done?
My objective is
Year
2005 2004 2003 | 2005 bar group1 2004 bar group1 2003 bar group1
| 2005 bar group2 2004 bar group2 2003 bar group2
|
proc sort data=enrollment;
by descending FOUR_DIGIT_YEAR;
run;
proc sgpanel data=enrollment;
panelby residency_desc/ novarname uniscale=row layout=columnlattice;
hbar FOUR_DIGIT_YEAR / response=STUDENTS_ENROLLED stat=sum group=degree_level /*descending*/;
keylegend / position=right noborder;
run;
Nevermind, I just saw in another of your posts that you are running SAS 9.2. I think the REVERSE option was added in SAS 9.3. As an alternative, if you presort *all* of the "class" variables in sgpanel, then SGPANEL will not auto sort the data. In addition, you'll need to tell the axis to stay in data order. The code will look something like this:
proc sort data=enrollment;
by residency_desc descending FOUR_DIGIT_YEAR;
run;
proc sgpanel data=enrollment;
panelby residency_desc/ novarname uniscale=row layout=columnlattice;
rowaxis discreteorder=data;
hbar FOUR_DIGIT_YEAR / response=STUDENTS_ENROLLED stat=sum group=degree_level /*descending*/;
keylegend / position=right noborder;
run;
Drop the PROC SORT and see if this works for you. If it doesn't, please post a picture of your current result:
proc sgpanel data=enrollment;
panelby residency_desc/ novarname uniscale=row layout=columnlattice;
hbar FOUR_DIGIT_YEAR / response=STUDENTS_ENROLLED stat=sum group=degree_level /*descending*/;
rowaxis reverse;
keylegend / position=right noborder;
run;
That should have been ROWAXIS, not YAXIS. I fixed the code.
When I use reverse I receive an error. It is not an option…
proc sql noprint;
CREATE TABLE enrollment (
FOUR_DIGIT_YEAR varchar(50),
STUDENTS_ENROLLED int,
residency_desc varchar(50)
);
/*panel one data*/
INSERT INTO enrollment
(FOUR_DIGIT_YEAR, STUDENTS_ENROLLED, residency_desc)
VALUES
('2001', 234, '1');
INSERT INTO enrollment
(FOUR_DIGIT_YEAR, STUDENTS_ENROLLED, residency_desc)
VALUES
('2002', 345, '1');
INSERT INTO enrollment
(FOUR_DIGIT_YEAR, STUDENTS_ENROLLED, residency_desc)
VALUES
('2003', 584, '1');
/*panel two data*/
INSERT INTO enrollment
(FOUR_DIGIT_YEAR, STUDENTS_ENROLLED, residency_desc)
VALUES
('2001', 465, '2');
INSERT INTO enrollment
(FOUR_DIGIT_YEAR, STUDENTS_ENROLLED, residency_desc)
VALUES
('2002', 344, '2');
INSERT INTO enrollment
(FOUR_DIGIT_YEAR, STUDENTS_ENROLLED, residency_desc)
VALUES
('2003', 200, '2');
quit;
proc sgpanel data=enrollment;
panelby residency_desc / novarname uniscale=row layout=columnlattice;
hbar FOUR_DIGIT_YEAR / response=STUDENTS_ENROLLED stat=sum group=residency_desc;
rowaxis label='Academic Year';
colaxis label=' ';
keylegend / position=right noborder;
run;
What version of SAS are you running?
9.2
Nevermind, I just saw in another of your posts that you are running SAS 9.2. I think the REVERSE option was added in SAS 9.3. As an alternative, if you presort *all* of the "class" variables in sgpanel, then SGPANEL will not auto sort the data. In addition, you'll need to tell the axis to stay in data order. The code will look something like this:
proc sort data=enrollment;
by residency_desc descending FOUR_DIGIT_YEAR;
run;
proc sgpanel data=enrollment;
panelby residency_desc/ novarname uniscale=row layout=columnlattice;
rowaxis discreteorder=data;
hbar FOUR_DIGIT_YEAR / response=STUDENTS_ENROLLED stat=sum group=degree_level /*descending*/;
keylegend / position=right noborder;
run;
It worked the key was the discreteorder=data.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.