Data visualization with SAS programming

Descending Y Axis SGPanel with Hbar

Accepted Solution Solved
Reply
Super Contributor
Posts: 465
Accepted Solution

Descending Y Axis SGPanel with Hbar

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;


Accepted Solutions
Solution
‎01-15-2015 11:30 AM
SAS Super FREQ
Posts: 889

Re: Descending Y Axis SGPanel with Hbar

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


All Replies
SAS Super FREQ
Posts: 889

Re: Descending Y Axis SGPanel with Hbar

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;

SAS Super FREQ
Posts: 889

Re: Descending Y Axis SGPanel with Hbar

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

Super Contributor
Posts: 465

Re: Descending Y Axis SGPanel with Hbar

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

SAS Super FREQ
Posts: 889

Re: Descending Y Axis SGPanel with Hbar

What version of SAS are you running?

Super Contributor
Posts: 465

Re: Descending Y Axis SGPanel with Hbar

9.2

Solution
‎01-15-2015 11:30 AM
SAS Super FREQ
Posts: 889

Re: Descending Y Axis SGPanel with Hbar

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;

Super Contributor
Posts: 465

Re: Descending Y Axis SGPanel with Hbar

It worked the key was the discreteorder=data.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 681 views
  • 0 likes
  • 2 in conversation