BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

View solution in original post

7 REPLIES 7
DanH_sas
SAS Super FREQ

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;

DanH_sas
SAS Super FREQ

That should have been ROWAXIS, not YAXIS. I fixed the code.

DavidPhillips2
Rhodochrosite | Level 12

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;

panel.png

DanH_sas
SAS Super FREQ

What version of SAS are you running?

DavidPhillips2
Rhodochrosite | Level 12

9.2

DanH_sas
SAS Super FREQ

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;

DavidPhillips2
Rhodochrosite | Level 12

It worked the key was the discreteorder=data.

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