BookmarkSubscribeRSS Feed
babaJB
Calcite | Level 5

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!.

3 REPLIES 3
Jay54
Meteorite | Level 14

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

babaJB
Calcite | Level 5

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

Jay54
Meteorite | Level 14

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

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