SAS Programming 1: Essentials PDF

Title SAS Programming 1: Essentials
Author Jimmy Rana
Pages 542
File Size 87.6 MB
File Type PDF
Total Downloads 13
Total Views 34

Summary

® SAS Programming I: Essentials Course Notes SAS® Programming I: Essentials Course Notes was developed by Michelle Buchecker, Sarah Calhoun, and Larry Stewart. Additional contributions were made by Randall Cates, Lise Cragen, Ted Durie, Susan Farmer, Natalie Murray, Kathy Passarella, and Andy Ravenn...


Description

Accelerat ing t he world's research.

SAS Programming 1: Essentials Jimmy Rana

Related papers

Download a PDF Pack of t he best relat ed papers 

SAS Cert ificat ion Prep Guide: Base Programming for SAS 9 Deb Cha Merged document 2 Bhavana Reddy

®

SAS Programming I: Essentials

Course Notes

SAS® Programming I: Essentials Course Notes was developed by Michelle Buchecker, Sarah Calhoun, and Larry Stewart. Additional contributions were made by Randall Cates, Lise Cragen, Ted Durie, Susan Farmer, Natalie Murray, Kathy Passarella, and Andy Ravenna. 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 I: Essentials Course Notes Copyright © 2007 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 E70306, course code PROG1, prepared date 18Apr2007.

PROG1_006

ISBN 978-1-59994-460-9

For Your Information

Table of Contents Course Description .....................................................................................................................vii Prerequisites ..............................................................................................................................viii Chapter 1 1.1

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

An Overview of the SAS System.....................................................................................1-3

Chapter 2

Getting Started with SAS ..................................................................... 2-1

2.1

Introduction to SAS Programs .........................................................................................2-3

2.2

Running SAS Programs ...................................................................................................2-8

2.3

Mastering Fundamental Concepts..................................................................................2-29

2.4

Diagnosing and Correcting Syntax Errors .....................................................................2-39

2.5

Exploring Your SAS Environment (Self-Study) ............................................................2-50

2.6

Solutions to Exercises ....................................................................................................2-64

Chapter 3

Getting Familiar with SAS Data Sets .................................................. 3-1

3.1

SAS Data Libraries ..........................................................................................................3-3

3.2

Solutions to Exercises ....................................................................................................3-16

Chapter 4

Producing List Reports........................................................................ 4-1

4.1

Getting Started with the PRINT Procedure......................................................................4-3

4.2

Sequencing and Grouping Observations........................................................................4-14

4.3

Identifying Observations (Self-Study) ...........................................................................4-22

4.4

Special WHERE Statement Operators (Self-Study) ......................................................4-28

4.5

Solutions to Exercises ....................................................................................................4-31

iii

iv

For Your Information

Chapter 5

Enhancing Output ................................................................................ 5-1

5.1

Customizing Report Appearance .....................................................................................5-3

5.2

Formatting Data Values....................................................................................................5-8

5.3

Creating HTML Reports ................................................................................................5-23

5.4

Solutions to Exercises ....................................................................................................5-29

Chapter 6

Creating SAS Data Sets ....................................................................... 6-1

6.1

Reading Raw Data Files: Column Input ..........................................................................6-3

6.2

Reading Raw Data Files: Formatted Input.....................................................................6-24

6.3

Examining Data Errors ..................................................................................................6-34

6.4

Assigning Variable Attributes ........................................................................................6-44

6.5

Changing Variable Attributes (Self-Study) ....................................................................6-51

6.6

Reading Microsoft Excel Spreadsheets (Self-Study).....................................................6-65

6.7

Solutions to Exercises ....................................................................................................6-80

Chapter 7

DATA Step Programming ..................................................................... 7-1

7.1

Reading SAS Data Sets and Creating Variables ..............................................................7-3

7.2

Conditional Processing ..................................................................................................7-17

7.3

Dropping and Keeping Variables (Self-Study) ..............................................................7-34

7.4

Reading Excel Spreadsheets Containing Date Fields (Self-Study)................................7-38

7.5

Solutions to Exercises ....................................................................................................7-43

Chapter 8

Combining SAS Data Sets ................................................................... 8-1

8.1

Concatenating SAS Data Sets ..........................................................................................8-3

8.2

Merging SAS Data Sets .................................................................................................8-22

8.3

Combining SAS Data Sets: Additional Features (Self-Study).......................................8-44

For Your Information

8.4

Solutions to Exercises ....................................................................................................8-48

Chapter 9

Producing Summary Reports .............................................................. 9-1

9.1

Introduction to Summary Reports....................................................................................9-3

9.2

Basic Summary Reports...................................................................................................9-6

9.3

The REPORT Procedure ................................................................................................9-23

9.4

The TABULATE Procedure (Self-Study) ......................................................................9-38

9.5

Solutions to Exercises ....................................................................................................9-53

Chapter 10

Introduction to Graphics Using SAS/GRAPH (Self-Study) ............. 10-1

10.1 Producing Bar and Pie Charts ........................................................................................10-3 10.2 Enhancing Output ........................................................................................................10-21 10.3 Producing Plots ............................................................................................................10-29 10.4 Solutions to Exercises ..................................................................................................10-40 Chapter 11

Additional Resources......................................................................... 11-1

11.1 Where Do I Go from Here? ........................................................................................... 11-3 11.2 SAS Resources............................................................................................................... 11-5 Appendix A

Using SAS Enterprise Guide to Complete Exercises....................... A-1

A.1 Introduction..................................................................................................................... A-3 A.2 Creating the Files Needed for the Course ....................................................................... A-4 A.3 Understanding Functional Areas in SAS Enterprise Guide ............................................ A-5 A.4 Naming the Project ......................................................................................................... A-7 A.5 Working with Existing Code......................................................................................... A-10 A.6 Resizing Windows in SAS Enterprise Guide................................................................ A-14 A.7 Modifying Demonstration Code ................................................................................... A-15

v

vi

For Your Information

A.8 Executing SAS Code .................................................................................................... A-16 A.9 Viewing SAS Enterprise Guide Output ........................................................................ A-17 A.10 Diagnosing and Correcting Syntax Errors .................................................................... A-19 A.11 Creating SAS Programs to Complete Exercises ........................................................... A-23 A.12 Accessing Data Sources with the LIBNAME Statement .............................................. A-25 A.13 Renaming a Code Node in the Process Flow Window ................................................. A-26 A.14 Submitting Exercise Programs...................................................................................... A-28 A.15 Saving Projects ............................................................................................................. A-31 A.16 The Output Delivery System and SAS Enterprise Guide ............................................. A-32 A.17 Copying SAS Programs within a Project...................................................................... A-33 Appendix B Introduction to Graphics Using SAS Enterprise Guide ................... B-1 B.1 Introduction to Graphics Using SAS Enterprise Guide .................................................. B-3 B.2 Exercise 1a: Producing a Vertical Bar Chart................................................................... B-4 B.3 Exercise 1b: Modifying the Bar Chart .......................................................................... B-18 B.4 Exercise 1c: Creating a Pie Chart ................................................................................. B-23 B.5 Exercise 1d: Modifying the Pie Chart........................................................................... B-28 B.6 Exercise 2: Producing a Horizontal Bar Chart.............................................................. B-32 B.7 Exercise 3: Producing a Two-Dimensional Plot ........................................................... B-39 Appendix C Index ..................................................................................................... C-1

For Your Information

vii

Course Description This foundation course focuses on the following key areas: reading raw data files and SAS data sets; investigating and summarizing data by generating frequency tables and descriptive statistics; creating SAS variables and recoding data values; subsetting data; combining multiple SAS files; creating listing, summary, HTML, and graph reports. If you do not plan to write SAS programs and prefer a menu-driven, point-and-click approach, you should consider taking the Querying and Reporting Using SAS® Enterprise Guide® course.

To learn more… A full curriculum of general and statistical instructor-based training is available at any of the Institute’s training facilities. Institute instructors can also provide on-site training. For information on other courses in the curriculum, contact the SAS Education Division at 1-800-333-7660, or send e-mail to [email protected]. You can also find this information on the Web at 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 our SAS Publishing Department at 1-800-727-3228 or send e-mail to [email protected]. Customers outside the USA, please contact your local SAS office. Also, see the Publications Catalog on the Web at support.sas.com/pubs for a complete list of books and a convenient order form.

viii

For Your Information

Prerequisites Before attending this course, you should have completed the Introduction to Programming Concepts Using SAS® Software course or have at least six months of programming experience. Specifically, you should be able to •

understand file structures and system commands on your operating systems



write system commands to create and access system files



understand programming logic.

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 Introduction to Programming Concepts Using SAS® Software course before attending this course. Introduction to Programming Concepts Using SAS® Software is designed to introduce you to computer programming and presents a portion of the SAS® Programming I: Essentials material at a slower pace.

Chapter 1 Introduction 1.1

An Overview of the SAS System...................................................................................1-3

1-2

Chapter 1 Introduction

1.1 An Overview of the SAS System

1.1 An Overview of the SAS System Objectives ̈ ̈

Describe the structure and design of the SAS System. Outline the course scenario.

2

Components of the SAS System

3

Reporting Reporting and and Graphics Graphics

Data DataAccess Access and and Management Management

User User Interfaces Interfaces

Analytical Analytical

Base BaseSAS SAS

Application Application Development Development

Visualization Visualization and andDiscovery Discovery

Business Business Solutions Solutions

Web Web Enablement Enablement

1-3

1-4

Chapter 1 Introduction

Data-Driven Tasks The functionality of SAS is built around the four data-driven tasks common to virtually any application: ̈ data access ̈ data management ̈ data analysis ̈ data presentation

4

data access

addresses the data required by the application.

data management

shapes data into a form required by the application.

data analysis

summarizes, reduces, or otherwise transforms raw data into meaningful and useful information.

data presentation

communicates information in ways that clearly demonstrate its significance.

Turning Data into Information The process of delivering meaningful information is typically distributed as follows: ̈

̈

5

80% data-related – access – scrub – transform – manage – store and retrieve 20% analysis

1.1 An Overview of the SAS System

1-5

Turning Data into Information DATA Step

Data

SAS Data Sets

PROC Steps

Information

6

Design of the SAS System MultiVendor Architecture

90% independent

PC

7

Workstation

10% dependent

Servers// Midrange

Mainframe

Super Computer

...

The term MultiVendor Architecture is used to reflect the layered structure of the SAS System. Much of the functionality of the SAS System is contained in a portable component, while the host component provides the required interfaces to the operating system and computer hardware. This enables you to run the same application in all your computing environments and take advantage of cooperative processing.

1-6

Chapter 1 Introduction

Design of the SAS System MultiEngine Architecture DB2 Teradata

SAP dBase

DATA DATA

ORACLE

SYBASE

Microsoft Excel

8

#

In order to access databases such as ORACLE, the SAS/ACCESS product for your given Database Management System (DBMS) must be licensed in addition to Base SAS software.

Course Scenario In this course, you work with business data from International Airlines (IA). The various kinds of data that IA maintains are listed below: ̈ flight data ̈ passenger data ̈ cargo data ̈ employee data ̈ revenue data

9

1.1 An Overview of the SAS System

Course Scenario The following are some tasks that you will perform: ̈ importing data ̈ creating a list of employees ̈ producing a frequency table of job codes ̈ summarizing data ̈ creating a report of salary information

10

1-7

1-8

Chapter 1 Introduction

Chapter 2 Getting Started with SAS 2.1

Introduction to SAS Programs ......................................................................................2-3

2.2

Running SAS Programs.................................................................................................2-8

2.3

Mastering Fundamental Concepts ..............................................................................2-29

2.4

Diagnosing and Correcting Syntax Errors .................................................................2-39

2.5

Exploring Your SAS Environment (Self-Study).......................................................


Similar Free PDFs