Upload
truongdang
View
221
Download
1
Embed Size (px)
Citation preview
SAS® Learner Response System - SAS Programming 1: Essentials Question Workbook
8th February 2012
SAS Institute
Wittington House Henley Road Medmenham Marlow Bucks SL7 2EB
This document is the confidential and proprietary property of SAS Institute Inc. It may
contain approaches, techniques, and other information proprietary to SAS, and shall not
be disclosed in whole or in part to third parties without the prior written consent of SAS.
Copyright 2012 SAS Institute Inc. All Rights Reserved
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 3 of 47
Contents
Chapter 1: Introduction ..................................................................................... 4
Chapter 2: Getting Started with SAS ............................................................... 7
Chapter 3: Working with SAS Syntax .............................................................. 9
Chapter 4: Getting Familiar with SAS Data Sets .......................................... 11
Chapter 5: Reading SAS Data Sets ................................................................ 14
Chapter 6: Reading Excel Worksheets .......................................................... 18
Chapter 7: Reading Delimited Raw Data Files .............................................. 20
Chapter 8: Validating and Cleaning Data ...................................................... 23
Chapter 9: Manipulating Data ......................................................................... 26
Chapter 10: Combining SAS Data Sets ......................................................... 30
Chapter 11: Summary Reports ....................................................................... 36
Chapter 12: Enhancing Reports ..................................................................... 40
Chapter 15: Confidence and Relevance ........................................................ 46
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 4 of 47
Chapter 1: Introduction
Chapter 1 provides an introduction to the course but more importantly it gives you an overview of SAS
and specifically the four data-driven tasks normally associated with getting to the information that you
need. The four data-driven tasks are: accessing data; manipulating or managing data; analysing data;
presenting data. Generally speaking 80% of the process deals with accessing and managing data
with the remaining 20% focussing on analysis and reporting. It isn’t always the case that you will start
by accessing data and go through all four steps in the process. It may be that your data is already
prepared for analysis or reporting.
Associated Key Learning Point: N/A
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 5 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: N/A
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 6 of 47
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 7 of 47
Chapter 2: Getting Started with SAS
Before we can start programming it’s important to understand what makes a SAS program and how
to use the SAS windowing environment interface to run a program and confirm it has executed
correctly.
Associated Key Learning Point: Fundamental Concepts
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 8 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: Fundamental Concepts
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 9 of 47
Chapter 3: Working with SAS Syntax
Having got to grips with some of the fundamentals of SAS programs this chapter looks a little deeper,
exploring SAS syntax rules and how to diagnose and solve SAS syntax errors. The basics are
straightforward: a SAS program consists of a series of steps; a step consists of a series of
statements; statements begin with an identifying keyword and end with a semi-colon. The most
common syntax error is a missing semi-colon! Fortunately the Enhanced Editor colour coding can
help make syntax errors easier to spot.
Associated Key Learning Point: Fundamental Concepts
Associated Key Learning Point: Handling Errors
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 10 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: Handling Errors
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 11 of 47
Chapter 4: Getting Familiar with SAS Data Sets
In Chapter 4 we look at the first of our four data-driven tasks – accessing data. In this case we are
looking at how to access existing SAS data sets. A SAS data set is a proprietary file type so it’s
important to understand some of the terminology associated with this data source before
investigating how to access them for use.
Associated Key Learning Point: Fundamental Concepts
Associated Key Learning Point: Fundamental Concepts
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 12 of 47
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: N/A
Associated Key Learning Point: Managing Data
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 13 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: N/A
Associated Key Learning Point: Handling Errors
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 14 of 47
Chapter 5: Reading SAS Data Sets
Remember we said that there are four data-driven tasks, the first is accessing data and the second is
managing data. In this chapter we're starting to look at how to manage our data by creating a new
SAS data set from an existing SAS data set. We explored techniques for selecting observations and
variables and applying permanent attributes to variables. It's never too early to start thinking about the
efficiency of your programs so think about how SAS processes and when/how you should be
asking SAS to drop or keep variables.
Associated Key Learning Point: N/A
Associated Key Learning Point: Creating Data Structures
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 15 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Creating Data Structures
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 16 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: Managing Data
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 17 of 47
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 18 of 47
Chapter 6: Reading Excel Worksheets
SAS can read many different forms of data. By using SAS/ACCESS software you can access
common data sources including Oracle, Teradata and Microsoft files. In order to read Microsoft Excel
or Microsoft Access data, SAS/ACCESS for PC File Formats must be licensed. This software also
provides additional functionality to the Import/Export Wizard which is covered in the self-study
Section 6.2.
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: Handling Errors
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 19 of 47
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 20 of 47
Chapter 7: Reading Delimited Raw Data Files
Chapter 7 brought us to our final example of accessing data – reading raw data files, specifically a
delimited raw data file. This is a more common task than you might realise simply because lots of
applications can read and write to this type of data file. In this chapter we also started to look at how
SAS processes a DATA step – the concept of compilation and execution and the Program Data
Vector (PDV). This is a very important concept to get to grips with. It will help you enormously when
your program seems to have executed properly but you are not seeing the output that you expected.
This is called a logic error. Being able to walk-through how the DATA step is processed will enable
you to debug this type of error.
Associated Key Learning Point: N/A
Associated Key Learning Point: Creating Data Structures
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 21 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 22 of 47
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 23 of 47
Chapter 8: Validating and Cleaning Data
Understanding your data is vital to ensuring your programs are working correctly and giving you the
correct output. It's important to remember that unclean data is a part of day-to-day life for a SAS
Programmer. This chapter looks at how to identify unclean data and what you can do about it. Firstly,
we looked at what happens when we read in a raw data file that contains invalid data. Remember, this
isn't a syntax error so you won't see error or warning messages in the log. This makes it all the more
important to read the SAS log properly after your program has finished executing. You will see invalid
data errors which have been prompted by the SAS temporary variable _ERROR_.
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: Creating Data Structures
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 24 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: N/A
Associated Key Learning Point: Handling Errors
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 25 of 47
Associated Key Learning Point: Managing Data
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 26 of 47
Chapter 9: Manipulating Data
This chapter teaches you how to create new variables using assignment statements. These variables
were created using SAS functions and also we looked at creating multiple variables based on
conditions using DO and END statements. There was also a review of Compilation and Execution
stage and a review of dropping and keeping variables. These function categories are covered in the
second programming course SAS Programming 2: Data Manipulation Techniques.
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Managing Data
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 27 of 47
Associated Key Learning Point: Managing Data
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 28 of 47
Associated Key Learning Point: Managing Data
Associated Key Learning Point: N/A
Associated Key Learning Point: Creating Data Structures
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 29 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 30 of 47
Chapter 10: Combining SAS Data Sets
This chapter teaches you several different ways to combine SAS data sets, including appending,
concatenation, interleaving and merging. The section on merging also covered the different types of
merges, one-to-one, one-to-many, many-to-many and non-matches and also looked at different
techniques to control which observations are output to the new data sets.
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: Accessing Data
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 31 of 47
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: N/A
Associated Key Learning Point: Accessing Data
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 32 of 47
Associated Key Learning Point: Handling Errors
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 33 of 47
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: Managing Data
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 34 of 47
Associated Key Learning Point: Accessing Data
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Accessing Data
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 35 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 36 of 47
Chapter 11: Summary Reports
This chapter dealt with producing summary reports using SAS procedures. The content consisted of
investigating in more detail, the FREQ, MEANS/SUMMARY and the TABULATE procedures. For
each of the procedures we began with a basic set of statements and then enhanced each procedure
with additional statements and options.
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 37 of 47
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: N/A
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 38 of 47
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 39 of 47
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 40 of 47
Chapter 12: Enhancing Reports
This chapter introduced several different ways of enhancing reports. We covered some global
statements, for example TITLE and FOOTNOTE, as well as using LABEL and FORMAT statements
within DATA steps and procedure steps. We also looked at directing output to various different output
files by using ODS statements and also added some style definitions to change the appearance of the
output files.
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 41 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 42 of 47
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: N/A
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 43 of 47
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 44 of 47
Associated Key Learning Point: Creating Data Structures
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: Generating Reports
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 45 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: Generating Reports
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 46 of 47
Chapter 15: Confidence and Relevance
Associated Key Learning Point: N/A
Associated Key Learning Point: N/A
Associated Key Learning Point: N/A
January 21, 2012 SAS Programming 1 Essentials Question Workbook.docx Page 47 of 47
Associated Key Learning Point: N/A
Associated Key Learning Point: N/A