How to create a histogram in SAS University Edition

4

This is a simple tutorial showing how to use SQL to subset data, and then create a histogram using Proc Sgplot, in SAS University Edition.

So you've downloaded SAS University Edition, and you're wondering "What now?" -- I would recommend exploring some of the sample data, and creating some simple charts!

To explore the sample data, select 'Libraries' along the left side, and then expand the 'SASHELP' library. This will show you a list of all the sample data that is included with the SAS University Edition. Scroll through the list of datasets, and look for names that might interest you.

university_libraries

For this example, we'll be using the SASHELP.HEART dataset, which contains some heart-related data about several patients. Double-click SASHELP.HEART, and it will let you browse the data in a spreadsheet-like interface. Scroll left/right in the data, and notice there is a column for Sex and columns for Diastolic, and Systolic blood pressure (these are the values we'll be using in our graph).

sashelp_heart

We could easily plot all the data, but it is very useful to know how to plot just a subset. There are several ways to subset data in SAS, but I'm going to teach you how to do it with Proc SQL ... because SQL is a very versatile tool to use, and also because many of you might already be familiar with SQL if you've worked with databases.

The following SAS SQL code will create a new dataset called male_data, containing ... you guessed it! ... just the data for the males. Type this code into the CODE tab of the Program 1 window, and then click the Run button (icon of a little man running). Yeah, I know - I'm a meanie, making you type it in, rather than copy-n-paste -- but this is part of the learning process! :)

male_data

Did your code run smoothly? If not, check to make sure you have a matching single-quote on both sides of 'Male', and make sure you have all four semicolons! Once you've got it running smoothly, then you can add the following Proc Sgplot code to create a histogram:

heart_histogram

Double- and triple-check to make sure you have all the code typed in correctly, with all the quotes, slashes, and semicolons ... and then click the Run button. If you've done everything correctly, you should get a chart like the following:

male_heart_histogram

So now you know how to view the sample data, manipulate it with SQL, and create a simple chart - you're well on your way to becoming a highly-paid SAS programmer! :)

Share

About Author

Robert Allison

The Graph Guy!

Robert has worked at SAS for over 25 years, and is perhaps the foremost expert in creating custom graphs using SAS/GRAPH. His educational background is in Computer Science, and he holds a BS, MS, and PhD from NC State University. He is the author of several conference papers, has won a few graphic competitions, and has written a book (SAS/GRAPH: Beyond the Basics).

4 Comments

    • Robert Allison
      Robert Allison on

      A simple 'where' statement would be easier ... but by using sql in the example, all the database people who already know sql see how they can become immediately productive in manipulating data in SAS :)

  1. Pingback: What Is SAS University Edition?My personal blog on Big Data technologies and concepts : SAS, Netezza, Oracle, ETL and Analytics | My personal blog on Big Data technologies and concepts : SAS, Netezza, Oracle, ETL and Analytics

  2. Pingback: Graphs are easy in SAS University Edition - Graphically Speaking

Leave A Reply

Back to Top