Susan Slaughter

Exercises for Learning SAS Programming

In Everything, Little SAS Book Series, SAS on August 21, 2015 at 10:36 am

LSBXcoverOur new book, Exercises and Projects for The Little SAS® Book Fifth Edition, includes a variety of exercises to help people learn SAS programming.  Rebecca Ottesen, Lora Delwiche and I designed this book so that it can be used either in a classroom setting or by individual readers working alone.

One of the challenges we faced in writing exercises was how to create questions that were thought-provoking and yet not too complicated for people who are just starting to learn SAS.  Our goal was not only to test readers’ knowledge, but to solidify that knowledge so they will remember what they learn.  That’s why we included different types of exercises.  Multiple-choice exercises are quick and easy, open-ended short answer exercises encourage readers to think a little more deeply about the material, and then programming exercises challenge readers to apply what they have learned.

The following questions are examples of the three types of exercises found in our book.  For help with these exercises, see section 4.13 “Producing Tabular Reports with PROC TABULATE” in The Little SAS® Book, Fifth Edition.

Multiple Choice

1.  For variables listed in a CLASS statement, what statistic will PROC TABULATE produce by default?

a. Sums
b. Percentages
c. Means
d. Counts

2.  If you specify two dimensions in a TABLE statement in PROC TABULATE, which dimensions will you get?

a. Pages and rows
b. Pages and columns
c. Rows and columns
d. Columns and rows

Short Answer

3.  Explain what happens to observations with missing values for variables listed in a CLASS statement in PROC TABULATE.  Describe an option you can use to change this default behavior.

4.  Is it possible to write a TABLE statement in PROC TABULATE that specifies a row dimension but no column dimension?  Explain your answer.

Programming Exercises

    5.  A friend, who has recently begun bird watching, keeps a list of birds.  For each species, she records its name and three one letter codes.  The codes indicate whether or not she has seen that species (S for seen, or N for not seen), the type of bird (G for game birds, S for songbirds, R for raptors, or W for waterfowl), and whether or not that species is migratory (M for migratory, or N for nonmigratory).  Use the data in her list to create summary reports.

a. Write a DATA step to read the following raw data into a SAS data set.

Bald Eagle     S R M
Barn Owl       S R M
Gambel’s Quail S G N
Canada Goose   S G N
Cardinal       N S N
Common Loon    N W M
Condor         N R N
Crow           S S N
Elf Owl        N R N
Golden Eagle   N R M
Goldfinch      S S M
Magpie         S S N
Mallard        S W M
Meadowlark     N S N
Mockingbird    S S N
Osprey         N R M
Robin          S S M
Scrub Jay      S S N
Rock Ptarmigan N G N
Turkey         N G N

b. Using PROC TABLULATE, produce a report with counts that specifies rows for the type of bird and columns for whether the bird has been seen.  Be sure to include an appropriate title.

c. Create user-defined formats to replace the one letter codes with formatted values for the type of bird and whether or not it has been seen.  Rerun the report using the new formats.

d. Use a different procedure to produce the same counts.  Then add a comment to your program describing the differences between the two reports.

We hope that you found this information helpful.  Visit the book page for additional information, reviews, and a free book excerpt.

Presenting the Newest Member of The Little SAS Book Family

In Everything, Little SAS Book Series, SAS on July 24, 2015 at 2:23 pm

LSBXcoverThere is a new kid on the block: Exercises and Projects for The Little SAS Book Fifth Edition.  Rebecca Ottesen, Lora Delwiche and I have worked for three years to complete this book of multiple choice, short answer, programming exercises, and projects.  This book is designed to be used as a supplement to the fifth edition of The Little SAS Book.  However, I think this book has turned out so well that someone who just wants practice with SAS programming could use this book by itself.

One of the great things about this book is that we have created 77 data sets for the programming exercises, and you can download these data sets for free.

For more information about our book or to download the data, click here.

Now Starring Susan and Lora in “SGPLOT and SGPANEL Procedures”

In Little SAS Book Series, SAS Global Forum, ODS Graphics, SAS, Everything on May 29, 2015 at 10:14 am

SAS Global Forum logoODS Graphics is not exactly new.  It became production with SAS 9.2 back around 2008, and before then it existed in a pre-production form at least as early as 2003.  So you would think that by now everyone who uses SAS would be using ODS Graphics, but apparently this is not the case.

It has come to my attention that some long-time SAS users still use PROC CHART–not even PROC GCHART, but PROC CHART which was designed for line printers back in the 1970s and creates graphs using alphanumeric characters!  Here is an example of a bar chart created using PROC CHART:


There is no excuse for this (unless, of course, you are trying to create a hip, retro vibe).  ODS Graphics is easy to use and produces beautiful graphs.  Here is the same bar chart created using PROC SGPLOT:


Now, if you are one of those people who uses SAS/Graph and PROC GCHART, and you are able to get the results you want, then that’s great.  I would never tell a SAS/Graph user to switch to ODS Graphics.  But for most people SAS/Graph is just too hard to use.  That’s why the developers at SAS created ODS Graphics: for the rest of us.  Just to prove that PROC SGPLOT is not any harder than PROC CHART, here is the code I used to create the two preceding bar charts:

PROC CHART DATA = olympics;
VBAR Region / SUBGROUP = PopGroup;

PROC SGPLOT DATA = olympics;
VBAR Region / GROUP = PopGroup;

If you are one of those people who still hasn’t learned ODS Graphics (or if you are new to SAS and want to get off on the right foot), this is your big chance.  At the recent SAS Global Forum conference, Lora Delwiche and I presented our paper “Graphing Made Easy with SGPLOT and SGPANEL Procedures.”  You can view that presentation.  Give us 50 minutes of your time, and we will convince you that ODS Graphics is easy (and maybe even fun) to use.  We start with a general introduction so you understand how the SGPLOT and SGPANEL procedures fit into the larger world of ODS Graphics, then we show how to create different types of graphs and how to customize them.

To watch our presentation, click here.

To download a copy of our paper, click here.

A lot of other great presentations were recorded at SGF too.  To see the full list, click here.

Happy graphing!



Get every new post delivered to your Inbox.

Join 331 other followers