没有合适的资源?快使用搜索试试~ 我知道了~
首页Step-by-Step Programming with Base SAS® 9.4.pdf
Step-by-Step Programming with Base SAS® 9.4.pdf
需积分: 10 10 下载量 2 浏览量
更新于2023-03-16
评论 1
收藏 19.03MB PDF 举报
Step-by-Step Programming with Base SAS® 9.4.pdf Step-by-Step Programming with Base SAS® 9.4.pdf
资源详情
资源评论
资源推荐
Step-by-Step Programming
with Base SAS
®
9.4
SAS
®
Documentation
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2013. Step-by-Step Programming with Base SAS® 9.4. Cary, NC:
SAS Institute Inc.
Step-by-Step Programming with Base SAS® 9.4
Copyright © 2013, SAS Institute Inc., Cary, NC, USA
All rights reserved. Produced in the United States of America.
For a hard-copy book: 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.
For a web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this
publication.
The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and
punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted
materials. Your support of others' rights is appreciated.
U.S. Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the U.S. government is
subject to the Agreement with SAS Institute and the restrictions set forth in FAR 52.227-19, Commercial Computer Software-Restricted Rights
(June 1987).
SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513.
July 2013
SAS provides a complete selection of books and electronic products to help customers use SAS® software to its fullest potential. For more
information about our e-books, e-learning products, CDs, and hard-copy books, visit support.sas.com/bookstore or call 1-800-727-3228.
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 registered trademarks or trademarks of their respective companies.
Contents
About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
What’s New in Step-by-Step Programming with Base SAS 9.4 . . . . . . . . . . . . . . . . . . . xix
Accessibility Features of Step-by-Step Programming with Base SAS 9.4 . . . . . . . . . . . xxi
PART 1 Introduction to the SAS System 1
Chapter 1 • What is the SAS System? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Introduction to the SAS System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Components of Base SAS Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Output Produced by the SAS System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Ways to Run SAS Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Running Programs in the SAS Windowing Environment . . . . . . . . . . . . . . . . . . . . . . . 13
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Chapter 2 • Working with Output Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Working with Output Defaults Starting in SAS 9.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
PART 2 Getting Your Data into Shape 25
Chapter 3 • Introduction to DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Introduction to DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The SAS Data Set: Your Key to the SAS System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
How the DATA Step Works: A Basic Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Supplying Information to Create a SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Chapter 4 • Starting with Raw Data: The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Introduction to Raw Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Examine the Structure of the Raw Data: Factors to Consider . . . . . . . . . . . . . . . . . . . . 52
Reading Unaligned Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Reading Data That Is Aligned in Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Reading Data That Requires Special Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Reading Unaligned Data with More Flexibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Mixing Styles of Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Chapter 5 • Starting with Raw Data: Beyond the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Introduction to Beyond the Basics with Raw Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Testing a Condition Before Creating an Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Creating Multiple Observations from a Single Record . . . . . . . . . . . . . . . . . . . . . . . . . 71
Reading Multiple Records to Create a Single Observation . . . . . . . . . . . . . . . . . . . . . . 75
Problem Solving: When an Input Record Unexpectedly Does Not
Have Enough Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Chapter 6 • Starting with SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Introduction to Starting with SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Understanding the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Reading Selected Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Reading Selected Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Creating More Than One Data Set in a Single DATA Step . . . . . . . . . . . . . . . . . . . . . . 97
Using the DROP= and KEEP= Data Set Options for Efficiency . . . . . . . . . . . . . . . . . . 99
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
PART 3 Basic Programming 103
Chapter 7 • Understanding DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Overview of DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Adding Information to a SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Defining Enough Storage Space for Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Conditionally Deleting an Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Chapter 8 • Working with Numeric Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Introduction to Working with Numeric Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
About Numeric Variables in SAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Calculating with Numeric Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Comparing Numeric Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Storing Numeric Variables Efficiently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Chapter 9 • Working with Character Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Introduction to Working with Character Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Identifying Character Variables and Expressing Character Values . . . . . . . . . . . . . . . 129
Setting the Length of Character Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Handling Missing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Creating New Character Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Saving Storage Space by Treating Numbers as Characters . . . . . . . . . . . . . . . . . . . . . 140
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Chapter 10 • Acting on Selected Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Introduction to Acting on Selected Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Selecting Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Constructing Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Comparing Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
iv Contents
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Chapter 11 • Creating Subsets of Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Introduction to Creating Subsets of Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Selecting Observations for a New SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Conditionally Writing Observations to One or More SAS Data Sets . . . . . . . . . . . . . 173
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Chapter 12 • Working with Grouped or Sorted Observations . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Introduction to Working with Grouped or Sorted Observations . . . . . . . . . . . . . . . . . 181
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Working with Grouped Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Working with Sorted Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Chapter 13 • Using More Than One Observation in a Calculation . . . . . . . . . . . . . . . . . . . . . . . 197
Introduction to Using More Than One Observation in a Calculation . . . . . . . . . . . . . 197
Input File and SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Accumulating a Total for an Entire Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Obtaining a Total for Each BY Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Writing to Separate Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Using a Value in a Later Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Chapter 14 • Finding Shortcuts in Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Introduction to Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Input File and SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Performing More Than One Action in an IF-THEN Statement . . . . . . . . . . . . . . . . . . 215
Performing the Same Action for a Series of Variables . . . . . . . . . . . . . . . . . . . . . . . . . 217
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Chapter 15 • Working with Dates in the SAS System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Introduction to Working with Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Understanding How SAS Handles Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Input File and SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Entering Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Displaying Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Using Dates in Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Using SAS Date Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Comparing Durations and SAS Date Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
PART 4 Combining SAS Data Sets 245
Chapter 16 • Methods of Combining SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Introduction to Combining SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Definition of Concatenating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Contents v
剩余905页未读,继续阅读
笨小孩Andy
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0