Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SAS Programming 1: Essentials: Course Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

SAS® Programming 1:

Essentials

Course Notes
SAS® Programming 1: Essentials Course Notes was developed by Charlot Bennett, Michele Ensor, and
Kathy Passarella. Additional contributions were made by Davetta Dunlap, Susan Farmer, Ted Meleky,
Linda Mitterling, and Theresa Stemler. Editing and production support was provided by the Curriculum
Development and Support Department.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of
SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product
names are trademarks of their respective companies.

SAS® Programming 1: Essentials Course Notes

Copyright © 2015 SAS Institute Inc. Cary, NC, USA. All rights reserved. Printed in the United States of
America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written
permission of the publisher, SAS Institute Inc.

Book code E2795, course code LWPG1/PG1, prepared date 3/20/2015. LWPG1_001

ISBN 978-1-62959-735-5
For Your Information iii

Table of Contents

Course Description ...................................................................................................................... ix

Prerequisites ................................................................................................................................. x

Chapter 1 Introduction ......................................................................................... 1-1

1.1 Overview of SAS Foundation .......................................................................................... 1-1

1.2 Course Logistics .............................................................................................................. 1-1


Demonstration: Investigating the Help Facility ........................................................ 1-1

1.3 Course Data Files ............................................................................................................. 1-1


Demonstration: Creating Course Data Files ............................................................. 1-1
Exercises ................................................................................................................... 1-1

Chapter 2 SAS® Programs ................................................................................... 2-1

2.1 Introduction to SAS Programs ......................................................................................... 2-1

2.2 Submitting a SAS Program .............................................................................................. 2-1


Demonstration: Submitting a SAS Program: SAS Enterprise Guide........................ 2-1
Demonstration: Submitting a SAS Program: SAS Windowing Environment .......... 2-1
Exercises ................................................................................................................... 2-1

2.3 SAS Program Syntax ....................................................................................................... 2-1


Demonstration: Automatic Formatting with SAS Enterprise Guide ........................ 2-1
Demonstration: Diagnosing and Correcting Syntax Errors ...................................... 2-1
Demonstration: Correcting Unbalanced Quotation Marks: SAS Windowing
Environment .................................................................................... 2-1
Demonstration: Correcting Unbalanced Quotation Marks: SAS Enterprise
Guide ............................................................................................... 2-1
Exercises ................................................................................................................... 2-1

2.4 Solutions .......................................................................................................................... 2-1


iv For Your Information

Solutions to Exercises ............................................................................................... 2-1


Solutions to Student Activities (Polls/Quizzes) ........................................................ 2-1

Chapter 3 Accessing Data ................................................................................... 3-1

3.1 Examining SAS Data Sets ............................................................................................... 3-1


Exercises ................................................................................................................... 3-1

3.2 Accessing SAS Libraries ................................................................................................. 3-1


Demonstration: Browsing SAS Libraries: SAS Enterprise Guide ............................ 3-1
Demonstration: Browsing SAS Libraries: SAS Windowing Environment............... 3-1
Exercises ................................................................................................................... 3-1

3.3 Solutions .......................................................................................................................... 3-1


Solutions to Exercises ............................................................................................... 3-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 3-1

Chapter 4 Producing Detail Reports ................................................................... 4-1

4.1 Subsetting Report Data .................................................................................................... 4-1


Exercises ................................................................................................................... 4-1

4.2 Sorting and Grouping Report Data .................................................................................. 4-1


Exercises ................................................................................................................... 4-1

4.3 Enhancing Reports ........................................................................................................... 4-1


Exercises ................................................................................................................... 4-1

4.4 Solutions .......................................................................................................................... 4-1


Solutions to Exercises ............................................................................................... 4-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 4-1

Chapter 5 Formatting Data Values ...................................................................... 5-1

5.1 Using SAS Formats ......................................................................................................... 5-1


Exercises ................................................................................................................... 5-1
For Your Information v

5.2 User-Defined Formats ...................................................................................................... 5-1


Demonstration: Defining and Using a Numeric Format ........................................... 5-1
Exercises ................................................................................................................... 5-1

5.3 Solutions .......................................................................................................................... 5-1


Solutions to Exercises ............................................................................................... 5-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 5-1

Chapter 6 Reading SAS® Data Sets ..................................................................... 6-1

6.1 Reading a SAS Data Set .................................................................................................. 6-1


Exercises ................................................................................................................... 6-1

6.2 Customizing a SAS Data Set ........................................................................................... 6-1


Exercises ................................................................................................................... 6-1

6.3 Solutions .......................................................................................................................... 6-1


Solutions to Exercises ............................................................................................... 6-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 6-1

Chapter 7 Reading Spreadsheet and Database Data ......................................... 7-1

7.1 Reading Spreadsheet Data ............................................................................................... 7-1


Demonstration: Reading Excel Data in SAS Enterprise Guide ................................ 7-1
Demonstration: Reading Excel Data in the SAS Windowing Environment ............. 7-1
Demonstration: Creating a SAS Data Set ................................................................. 7-1
Exercises ................................................................................................................... 7-1

7.2 Reading Database Data .................................................................................................... 7-1

7.3 Solutions .......................................................................................................................... 7-1


Solutions to Exercises ............................................................................................... 7-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 7-1

Chapter 8 Reading Raw Data Files ..................................................................... 8-1

8.1 Introduction to Reading Raw Data Files ......................................................................... 8-1


vi For Your Information

8.2 Reading Standard Delimited Data ................................................................................... 8-1


Demonstration: Examining Data Errors .................................................................... 8-1
Exercises ................................................................................................................... 8-1

8.3 Reading Nonstandard Delimited Data ............................................................................. 8-1


Demonstration: Using List Input: Importance of Colon Format Modifier ............... 8-1
Exercises ................................................................................................................... 8-1

8.4 Handling Missing Data .................................................................................................... 8-1


Exercises ................................................................................................................... 8-1

8.5 Solutions .......................................................................................................................... 8-1


Solutions to Exercises ............................................................................................... 8-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 8-1

Chapter 9 Manipulating Data ............................................................................... 9-1

9.1 Using SAS Functions ....................................................................................................... 9-1


Exercises ................................................................................................................... 9-1

9.2 Conditional Processing .................................................................................................... 9-1


Exercises ................................................................................................................... 9-1

9.3 Solutions .......................................................................................................................... 9-1


Solutions to Exercises ............................................................................................... 9-1
Solutions to Student Activities (Polls/Quizzes) ........................................................ 9-1

Chapter 10 Combining Data Sets ........................................................................ 10-1

10.1 Concatenating Data Sets ................................................................................................ 10-1


Exercises ................................................................................................................. 10-1

10.2 Merging Data Sets One-to-One...................................................................................... 10-1

10.3 Merging Data Sets One-to-Many ................................................................................... 10-1


Exercises ................................................................................................................. 10-1

10.4 Merging Data Sets with Non-Matches........................................................................... 10-1


For Your Information vii

Exercises ................................................................................................................. 10-1

10.5 Solutions ........................................................................................................................ 10-1


Solutions to Exercises ............................................................................................. 10-1
Solutions to Student Activities (Polls/Quizzes) ...................................................... 10-1

Chapter 11 Creating Summary Reports .............................................................. 11-1

11.1 The FREQ Procedure ..................................................................................................... 11-1


Exercises ................................................................................................................. 11-1

11.2 The MEANS and UNIVARIATE Procedures ................................................................ 11-1


Exercises ................................................................................................................. 11-1

11.3 Using the Output Delivery System ................................................................................ 11-1


Demonstration: Using the Output Delivery System................................................ 11-1
Exercises ................................................................................................................. 11-1

11.4 Solutions ........................................................................................................................ 11-1


Solutions to Exercises ............................................................................................. 11-1
Solutions to Student Activities (Polls/Quizzes) ...................................................... 11-1

Chapter 12 Learning More ................................................................................... 12-1

12.1 Introduction.................................................................................................................... 12-1

Appendix A Self-Study ........................................................................................... A-1

A.1 Submitting Programs in UNIX and z/OS........................................................................ A-1


Demonstration: Submitting a Program in the SAS Windowing Environment:
UNIX .............................................................................................. A-1
Demonstration: Submitting a Program in the SAS Windowing Environment:
z/OS ................................................................................................ A-1

A.2 Accessing Data ............................................................................................................... A-1


Exercises .................................................................................................................. A-1

A.3 Manipulating Data .......................................................................................................... A-1


viii For Your Information

Exercises .................................................................................................................. A-1

A.4 Combining Data Sets ...................................................................................................... A-1


Exercises .................................................................................................................. A-1

A.5 Advanced Reporting Techniques .................................................................................... A-1


Exercises .................................................................................................................. A-1

A.6 Introduction to SAS/GRAPH.......................................................................................... A-1


Demonstration: Creating Bar and Pie Charts ........................................................... A-1
Demonstration: Creating Plots ................................................................................. A-1
Demonstration: Enhancing Output........................................................................... A-1

A.7 Solutions ......................................................................................................................... A-1


Solutions to Exercises .............................................................................................. A-1

Note for CP5804 Students :

This Table of Contents may not exactly matched with chapter materials you are provided.
You are not provided with Some Solutions or Appendix directly.

The solutions will be released only when your submission of weekly activity answer
sheet is done and marked off.
For Your Information ix

Course Description

This course is for users who want to learn how to write SAS programs. It is the entry point to learning
SAS programming and is a prerequisite to many other SAS courses. If you do not plan to write SAS
programs and you prefer a point-and-click interface, you should attend the SAS® Enterprise Guide® 1:
Querying and Reporting course.

To learn more…

For information about other courses in the curriculum, contact the SAS
Education Division at 1-800-333-7660, or send e-mail to training@sas.com.
You can also find this information on the web at http://support.sas.com/training/
as well as in the Training Course Catalog.

For a list of other SAS books that relate to the topics covered in this
course notes, USA customers can contact the SAS Publishing Department
at 1-800-727-3228 or send e-mail to sasbook@sas.com. Customers outside
the USA, please contact your local SAS office.
Also, see the SAS Bookstore on the web at http://support.sas.com/publishing/
for a complete list of books and a convenient order form.
x For Your Information

Prerequisites

Before attending this course, you should have experience using computer software. Specifically, you
should be able to
• understand file structures and system commands on your operating systems
• access data files on your operating systems.
No prior SAS experience is needed. If you do not feel comfortable with the prerequisites or are new to
programming and think that the pace of this course might be too demanding, you can take the SAS®
Programming Introduction: Basic Concepts course before attending this course. SAS® Programming
Introduction: Basic Concepts is designed to introduce you to computer programming and presents a
portion of the SAS® Programming 1: Essentials material at a slower pace.

You might also like