Data visualization with SAS programming

Nesting variables in a bar graph?

Reply
Contributor RVA
Contributor
Posts: 21

Nesting variables in a bar graph?

I wanted to produce a bar graph as the following (graph 1).  You can see that on the horizontal axis, the "student_class" variable is nested into the "seen_notseen" variable.  However, I could not figure out how to do this.  The only thing I could do was produce two separate graphs, one for "seen" students and one for "notseen" students (see graphs 2a and 2b).  Do you have any ideas on how I can produce a graph that looks like g

Graph 1:

SKM_C364e15031915030_0001.jpg

Graphs 2a and 2b:


SKM_C364e15031915140_0001.jpg

SKM_C364e15031915141_0001.jpg

Below are the codes I used to produce graph 2a (and 2b):

/* Set the graphics environment */                                                                                               
goptions reset=all cback=white border htitle=15pt htext=12pt;                                                                    
                                                                                                                                                                                                                                                                        
/* Define the axis characteristics */                                                                                             
axis1 value=none label=none;                                                                                                   
axis2 label=(angle=90 'Number of Students');                                                                                         
axis3 label=none;                                                                                                              
/* Define the legend options */                                                                                                  
legend1 frame label=none;                                                                                                                 

/* Generate the graph */                                                                                                         
title1 'Academic Standing by Class (Seen Students)';                                                                                    

proc gchart data=students_b;

where class in ('FR','SO','JR','SR') and acadstanding not in (' ','N/A') and meetingcount > 0;

format acadstanding $standing_b. class $class_b.;

vbar acadstanding /

subgroup=acadstanding group=class type=freq                                                                    
legend=legend1 space=0 gspace=4 width=5                                                                              
maxis=axis1 raxis=axis2 gaxis=axis3;                                                                            
run;                                                                                                                             
quit;
SAS Super FREQ
Posts: 925

Re: Nesting variables in a bar graph?

I'm not sure of your SAS version, but you can use PROC SGPANEL create this chart. Below is a similar example. If you want the headers are the bottom, use COLHEADERPOS=BOTTOM on the PANELBY statement. Hope this helps!

proc sgpanel data=sashelp.heart;

panelby sex / novarname layout=columnlattice onepanel;

vbar weight_status / response=cholesterol stat=mean group=bp_status

     groupdisplay=cluster;

run;

SGPanel.png

Contributor RVA
Contributor
Posts: 21

Re: Nesting variables in a bar graph?

Many thanks, Dan.  Unfortunately, I am still running SAS 9.2, so the groupdisplay= option is not available; otherwise, it would be perfect.  Do you have any work-around for me?  Thank you.

SAS Super FREQ
Posts: 925

Re: Nesting variables in a bar graph?

Unfortunately, no. I had another way to approach it using overlays and DISCRETEOFFSET, but that approach requires at least SAS 9.3. Do you have access to a more recent version of SAS?

Contributor RVA
Contributor
Posts: 21

Re: Nesting variables in a bar graph?

Thank you Dan.  Let me ask the IT for an upgrade and will get back to you later.  Thank you.

Ask a Question
Discussion stats
  • 4 replies
  • 422 views
  • 4 likes
  • 2 in conversation