Data visualization with SAS programming

Is there a way for GBARLINE to plot 3 bar charts and 3 lines ?

Reply
Occasional Contributor
Posts: 12

Is there a way for GBARLINE to plot 3 bar charts and 3 lines ?

Hi All,

I was wondering if there is a possibility for PROC GBARLINE to plot 3 charts in single primary axis and 3 lines in single secondary axis. Basically my data set contains variables such as average student final exam in semester 1,2,3 and average number of hours student study in semester 1,2,3. Herein my data set example :

Class       exam_1   exam_2  exam_3  studyhours_1  studyhours_2 studyhours_3
Math             6.2         7.5           7.0         4                    4                         5

Physic          7.12        6.7          5.8          5                    3                         4

Is there a way for PROC GBARLINE to manage all of these data in single picture ?

Thanks for any help!.

SAS Super FREQ
Posts: 1,104

Re: Is there a way for GBARLINE to plot 3 bar charts and 3 lines ?

I will let other GRAPH experts answer the GBARLINE question.  With SAS 9.3, you can certainly do this using proc SGPLOT.  While data is reorganized as group (for convenience), you can certainly also use the multi column format, with different syntax.  Having same number of ticks on both Y & Y2 axis allows using grids lines.

BarLine3.png

%let gpath='C:\';

data scores;
  input Subject $1-8 Semester Score StudyTime;
  datalines;
Math       1  6.2  4
Math       2  7.5  4
Math       3  7.0  5
Physics  1  7.12 5
Physics  2  6.7  3
Physics  3  5.8  4
;
run;

ods listing style=htmlblue gpath=&gpath;

ods graphics / reset width=4in height=3in imagename='BarLine3';
proc sgplot data=scores;
  title 'Scores and Study Time by Subject and Semester';
  vbar subject / response=score group=semester groupdisplay=cluster

          nostatlabel dataskin=gloss name='a';
  vline subject / response=studytime group=semester nostatlabel y2axis lineattrs=(thickness=5);
  yaxis min=0 offsetmin=0 values=(0 to 10 by 2) grid label='Score (Bar)';
  y2axis min=0 offsetmin=0 label='Study Time in Hours (Line)';
  xaxis display=(nolabel);
  keylegend 'a' / title='Semester';

run;

Switching Group and Category gives an alternate arrangement, recommended by some when using Line Charts:

BarLine3B.png

Occasional Contributor
Posts: 12

Re: Is there a way for GBARLINE to plot 3 bar charts and 3 lines ?

Many Thanks Sanjay. I don't mind if there is another procedure to do it.

SAS Super FREQ
Posts: 1,104

Re: Is there a way for GBARLINE to plot 3 bar charts and 3 lines ?

Please see first line of my code (%let).

For more information see Graphically Speaking blog.

Also see book:  Statistical Graphics Procedures by Example: Effective Graphs Using SAS

Ask a Question
Discussion stats
  • 3 replies
  • 575 views
  • 0 likes
  • 2 in conversation