SAS: Bar Chart

Let’s create a bar chart in SAS. There are two ways you can go about it: Code or work with the menus provided. We will start with the menus.

Start by clicking on Task and Utilities

2016-11-28_21-30-01

Select Graph > Bar Chart

2016-11-28_21-30-45

In the new window pane that opens, we need to add Data. Select the browse button

2016-11-28_21-31-16

Expand SASHELP (a collection of data sets that came with SAS)

2016-11-28_21-31-41

We are going to pick SHOES

2016-11-28_21-33-02.jpg

Now the red * indicates required fields. The only one bar charts require is Category variable. Hit the plus sign.

2016-11-28_21-33-27.jpg

Select Product – notice how the code automatically fills in for you now.

2016-11-28_21-33-47

Hit the little running man and your chart will appear in the Results

2016-11-28_21-34-14.jpg

Let’s change the color. – go to Options>Bar Details>Apply bar Color and pick a new color

2016-11-28_21-34-44.jpg

And now it is red (or whatever color you chose)

2016-11-28_21-35-00.jpg

Go back to the Data tab and add Region to Group Variable

2016-11-28_21-35-25

Notice we now have two dimensions Product and Region. Also notice a legend is auto generated.

2016-11-28_21-35-41.jpg

Now let’s try doing via code, use the following code:

proc sgplot data=SASHELP.SHOES;
 vbar Product / group=Region groupdisplay=Stack name='Bar';
 yaxis grid;
run;

Note I changed groupdisplay to Stack. Here are the results

2016-11-28_21-37-21

 

Please Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s