Table of Contents

Title Page

Copyright Page

Table of Figures

List of Tables

PREFACE

Acknowledgments

THE AUTHORS

CHAPTER 1 - GETTING STARTED

USING SAS IN A WINDOWS ENVIRONMENT

YOUR FIRST SAS ANALYSIS

HOW SAS WORKS

TIPS AND TRICKS FOR RUNNING SAS PROGRAMS

SUMMARY

EXERCISES

CHAPTER 2 - GETTING DATA INTO SAS

USING THE SAS DATA SETS

UNDERSTANDING SAS DATA SET STRUCTURE

RULES FOR SAS VARIABLE NAMES

UNDERSTANDING THREE SAS VARIABLE TYPES

METHODS OF READING DATA INTO SAS

GOING DEEPER: MORE TECHNIQUES FOR ENTERING DATA

SUMMARY

EXERCISES

CHAPTER 3 - READING, WRITING, AND IMPORTING DATA

WORKING WITH SAS LIBRARIES AND PERMANENT DATA SETS

READING AND CREATING PERMANENT SAS DATA SETS USING THE WINDOWS FILE NAME TECHNIQUE

READING DATA FROM PERMANENT SAS DATA SETS

READING AND CREATING PERMANENT SAS DATA SETS USING A SAS LIBRARY

CREATING A SAS LIBRARY USING A DIALOG BOX

IMPORTING DATA FROM ANOTHER PROGRAM

GOING DEEPER: MORE WAYS TO MANAGE DATA

GOING DEEPER: IMPORTING MICROSOFT EXCEL DATA USING SAS CODE

DISCOVERING THE CONTENTS OF A SAS DATA SET

SUMMARY

EXERCISES

CHAPTER 4 - PREPARING DATA FOR ANALYSIS

LABELING VARIABLES WITH EXPLANATORY NAMES

CREATING NEW VARIABLES

USING DROP AND KEEP TO SELECT VARIABLES

SUBSETTING DATA SETS

USING THE SET STATEMENT TO READ AN EXISTING DATA SET

USING PROC SORT

APPENDING AND MERGING DATA SETS

GOING DEEPER: USING PROC FORMAT

SUMMARY

EXERCISES

CHAPTER 5 - PREPARING TO USE SAS PROCEDURES

UNDERSTANDING SAS SUPPORT STATEMENTS

UNDERSTANDING PROC STATEMENT SYNTAX

USING THE ID STATEMENT IN A SAS PROCEDURE

USING THE LABEL STATEMENT IN A SAS PROCEDURE

USING THE WHERE STATEMENT IN A SAS PROCEDURE

USING PROC PRINT

GOING DEEPER: INTRODUCING THE SAS OUTPUT DELIVERY SYSTEM (ODS)

SUMMARY

EXERCISES

CHAPTER 6 - EVALUATING QUANTITATIVE DATA

USING PROC MEANS

USING PROC UNIVARIATE

GOING DEEPER: ADVANCED PROC UNIVARIATE OPTIONS

SUMMARY

EXERCISES

CHAPTER 7 - ANALYZING COUNTS AND TABLES

USING PROC FREQ

ANALYZING ONE-WAY FREQUENCY TABLES

CREATING ONE-WAY FREQUENCY TABLES FROM SUMMARIZED DATA

ANALYZING TWO-WAY TABLES

GOING DEEPER: CALCULATING RELATIVE RISK MEASURES

GOING DEEPER: INTER-RATER RELIABILITY (KAPPA)

SUMMARY

EXERCISES

CHAPTER 8 - COMPARING MEANS USING T-TESTS

PERFORMING A ONE-SAMPLE T-TEST

PERFORMING A TWO-SAMPLE T-TEST

PERFORMING A PAIRED T-TEST

SUMMARY

EXERCISES

CHAPTER 9 - ANALYSIS OF VARIANCE

COMPARING THREE OR MORE MEANS USING ONE-WAY ANALYSIS OF VARIANCE

COMPARING THREE OR MORE REPEATED MEASURES

GOING DEEPER: GRAPHING MEAN COMPARISONS

SUMMARY

EXERCISES

CHAPTER 10 - CORRELATION AND REGRESSION

CORRELATION ANALYSIS USING PROC CORR

SIMPLE LINEAR REGRESSION

MULTIPLE LINEAR REGRESSION USING PROC REG

GOING DEEPER: CALCULATING PREDICTIONS

GOING DEEPER: RESIDUAL ANALYSIS

SUMMARY

EXERCISES

CHAPTER 11 - NONPARAMETRIC ANALYSIS

COMPARING TWO INDEPENDENT SAMPLES USING NPAR1WAY

COMPARING K INDEPENDENT SAMPLES (KRUSKAL-WALLIS)

COMPARING TWO DEPENDENT (PAIRED) SAMPLES

COMPARING K DEPENDENT SAMPLES (FRIEDMAN’S TEST)

GOING DEEPER: NONPARAMETRIC MULTIPLE COMPARISONS

SUMMARY

EXERCISES

CHAPTER 12 - LOGISTIC REGRESSION

LOGISTIC ANALYSIS BASICS

PERFORMING A LOGISTIC ANALYSIS USING PROC LOGISTIC

USING SIMPLE LOGISTIC ANALYSIS

MULTIPLE BINARY LOGISTIC ANALYSIS

GOING DEEPER: ASSESSING A MODEL’S FIT AND PREDICTIVE ABILITY

SUMMARY

EXERCISES

CHAPTER 13 - ANALYSIS OF VARIANCE, PART II

ANALYSIS OF COVARIANCE

GOING DEEPER: TWO-FACTOR ANOVA USING PROC MIXED

GOING DEEPER: REPEATED MEASURES WITH A GROUPING FACTOR

SUMMARY

EXERCISES

CHAPTER 14 - CREATING GRAPHS

CREATING SCATTERPLOTS AND LINE GRAPHS USING GPLOT

CREATING BAR CHARTS AND PIE CHARTS

CREATING STACKED BAR CHARTS

CREATING MEAN BARS USING GCHART

CREATING BOXPLOTS

GOING DEEPER: ODS GRAPHICS

SUMMARY

EXERCISES

CHAPTER 15 - CONTROLLING OUTPUT USING ODS

SPECIFYING THE ODS OUTPUT FORMAT AND DESTINATION

SPECIFYING ODS OUTPUT STYLE

USING ODS TO SELECT SPECIFIC OUTPUT TABLES FOR PROCEDURES

GOING DEEPER: ENHANCING GRAPHICS USING ODS AND CREATING HYPERLINKS

GOING DEEPER: CAPTURING INFORMATION FROM ODS TABLES

EXTENDED ODS FEATURES

SUMMARY

EXERCISES

CHAPTER 16 - ADVANCED SAS PROGRAMMING TOPICS

READING AND WRITING DATA USING DDE

USING THE RETAIN STATEMENT

ARRAYS AND DO LOOPS

TRANSPOSING DATA SETS

USING SAS MACROS

SUMMARY

EXERCISES

APPENDIX A - SAS GRAPH OPTIONS REFERENCE

APPENDIX B - SAS FUNCTION REFERENCE

APPENDIX C - CHOOSING A SAS PROCEDURE

APPENDIX D - QUICK REFERENCE

REFERENCES

INDEX

Table of Figures

FIGURE 1.1. Initial SAS screen

FIGURE 1.2. The FIRST.SAS file opened

FIGURE 1.3. Output for FIRST.SAS

FIGURE 1.4. How SAS works

FIGURE 1.5. Help file display

FIGURE 3.1. Reading and storing data in SAS

FIGURE 3.2. New Library dialog box

FIGURE 3.3. The SAS Library icon

FIGURE 3.4. SAS Viewtable

FIGURE 3.5. Excel data ready for import

FIGURE 3.6. Initial screen of the SAS Import Wizard

FIGURE 3.7. Selecting an Excel file name

FIGURE 3.8. Selecting the library and member name

FIGURE 4.1. Creating a new data set using the SET statement

FIGURE 4.2. Example output from merged data sets

FIGURE 5.1. Using SAS

FIGURE 5.2. Example output

FIGURE 6.1. Plots to assess normality from PROC UNIVARIATE

FIGURE 6.2. Histogram with normal curve superimposed

FIGURE 6.3. Multiple histograms from PROC UNIVARIATE

FIGURE 6.4. PROC UNIVARIATE histogram output using two groups

FIGURE 6.5. Multiple Histograms from the CAR dataset

FIGURE 7.1. Example data records from the RASH dataset

FIGURE 8.1. Plots produced by PROC TTEST

FIGURE 8.2. Plots produced by PROC TTEST

FIGURE 8.3. Plots produced by PROC TTEST using the PAIRED option

FIGURE 9.1. Side-by-side boxplots produced by ODS GRAPHICS

FIGURE 9.2. Side-by-side dot plots produced by GPLOT

FIGURE 10.1. Matrix of scatterplots

FIGURE 10.2. Example simple linear regression using PROC REG

FIGURE 10.3. Scatterplot and regression line for final model

FIGURE 10.4. ODS GRAPHICS output for PROC REG

FIGURE 10.5. Prediction limits

FIGURE 10.6. Washington, D.C., assaults, 1978-93

FIGURE 11.1. Side-by-side boxplots for the weight-gain data

FIGURE 12.1. A logistic plot from a simple logistic model LOGISTIC PLOT

FIGURE 12.2. ROC curve

FIGURE 13.1. Regression lines for ANCOVA data

FIGURE 13.2. Parallel lines for ANCOVA data, for second model assuming parallel lines

FIGURE 13.3. Graphical representation of Scheffe results

FIGURE 13.4. Example of an interaction effect

FIGURE 13.5. ODS Graphics interaction plot for the two-factor ANOVA example (SAS version 9.2)

FIGURE 13.6. Interaction plots for two-way ANOVA

FIGURE 13.7. Plots for repeated measures analysis

FIGURE 14.1. Default scatterplot using PROC GPLOT

FIGURE 14.2. PROC GPLOT with dots and line Specified

FIGURE 14.3. PROC GPLOT with dots and lines specified

FIGURE 14.4. PROC GPLOT showing error bars

FIGURE 14.5. Horizontal bar chart using PROC GCHART

FIGURE 14.6. PROC GCHART showing groups bars

FIGURE 14.7 Stacked bar chart

FIGURE 14.8. Means with error bars

FIGURE 14.9. Boxplots showing highway MPG by cylinders

FIGURE 14.10. Boxplots with enhancements

FIGURE 14.11. Graphics output from ODS

FIGURE 14.12. ODS graphics output from PROC CORR

FIGURE 15.1. ODS TRACE output

FIGURE 15.2. Drill-down plot, first run

FIGURE 16.1. Excel data to import into SAS via the clipboard

FIGURE 16.2. Data written to an Excel spreadsheet from SAS

FIGURE 16.3. Data from the COMPLICATIONS data set

FIGURE A.1 . Standard SAS fonts

FIGURE A.2 . Example crosshatch pattern

FIGURE A.3 . Example fill patterns

FIGURE A.4 . Line styles

FIGURE A.5 . Select line style

FIGURE A.6 . Standard SAS symbols

List of Tables

TABLE 1.1. SAS Function Keys

TABLE 2.1. Overview of the SAS DATA step

TABLE 2.2. SAS Data set (table) structure

TABLE 2.3. A sample SAS data set

TABLE 2.4. Example SAS FORMATs and INFORMATs

TABLE 3.1. SAS DBMS data sources

TABLE 4.1. SAS sorting sequence

TABLE 4.2. SAS output showing sort ascending and descending

TABLE 6.1. Output for PROC MEANS

TABLE 6.2. PROC MEANS output using the BY option

TABLE 6.3. PROC MEANS output using the CLASS option

TABLE 6.4. Moments output for PROC UNIVARIATE

TABLE 6.5. Basic statistical measures from PROC UNIVARIATE

TABLE 6.6. Tests for location from PROC UNIVARIATE

TABLE 6.7. Quantiles from PROC UNIVARIATE

TABLE 6.8. Extreme values output from PROC UNIVARIATE

TABLE 6.9. Test for normality from PROC UNIVARIATE

TABLE 7.1. Sample TABLE statements

Table 7.2. Simple output for PROC FREQ

TABLE 7.3. PROC FREQ output using the ORDER FREQ option

TABLE 7.4. Output from PROC FREQ using the ORDER= FORMATTED option

TABLE 7.5. Proc FREQ output for summarized counts

TABLE 7.6. Goodness-of-fit test using PROC FREQ

TABLE 7.7. Cross-tabulation from PROC FREQ

TABLE 7.8. Statistics for drinking and crime cross-tabulation

TABLE 7.9. Expected values for drinking and crime data

TABLE 7.10. Cross-tabulation of cleaner by rash

TABLE 7.11. Statistics tables for a 2 × 2 analysis

TABLE 7.12. Relative risk measures for the floor cleaner data

TABLE 7.13. Data for inter-rater reliability analysis

TABLE 7.14. Results for Kappa analysis

TABLE 7.15. Interpretation of kappa statistic

TABLE 7.16. Partial SECURITY data

TABLE 7.17. Cross-tabulation of security data

TABLE 7.18. Kappa statistics for security data

TABLE 8.1. t-test results using PROC UNIVARIATE

TABLE 8.2. t-test results using PROC TTEST

TABLE 8.3. Two-sample t-test output from PROC TTEST

TABLE 8.4. Paired t-test output

TABLE 9.1. ANOVA results

TABLE 9.2. Tukey multiple comparisons results

TABLE 9.3. Simultaneous confidence limits

TABLE 9.4. Analysis of variance results

TABLE 9.5. Duncan’s multiple comparison results

TABLE 10.1. Output from PROC CORR

TABLE 10.2. Correlations using a WITH statement

TABLE 10.3. Data for simple linear regression

TABLE 10.4. Output from PROG REG for a simple linear regression

TABLE 10.5. Analysis of variance output for PROC REG

TABLE 10.6. Parameter estimates

TABLE 10.7. Parameter estimates for revised model

TABLE 10.8. Parameter estimates for final model

TABLE 10.9. Predictions using final model

TABLE 10.10. Output statistics for PROC REG

TABLE 10.11. Regression estimates for Washington, D.C., crime data 1978-93

TABLE 11.1. Output from NPAR1WAY for a two-group analysis

TABLE 11.2. Output from NPAR1WAY for a four-sample group comparison

TABLE 11.3. PROC UNIVARIATE to test paired difference

TABLE 11.4. Friedman’s test output using PROC FREQ

TABLE 11.5. Multiple comparison test for a Kruskal-Wallis analysis

TABLE 11.6. Store shrinkage, in thousands

TABLE 12.1. Output from logistic regression

TABLE 12.2. Output for a continuous measure from logistic regression

TABLE 12.3. CLASS variables

TABLE 12.4. Final model

TABLE 12.5. Hosmer and Lemeshow results

TABLE 12.6. Classification table for logistic regression

TABLE 13.1. Data from math course analysis

TABLE 13.2. Test of slopes for analysis of covariance

TABLE 13.3. Analysis of covariance test of main effects

TABLE 13.4. Scheffe multiple comparisons for ANCOVA

TABLE 13.5. ANOVA results from a two-factor analysis using PROC GLM

TABLE 13.6. Marginal means for levels of STATUS

TABLE 13.7. Means by factor

TABLE 13.8. Output from PROC MIXED using random effects

TABLE 13.9. Model run as if all factors were fixed

TABLE 13.10. Original data set of repeated measures data

TABLE 13.11. REPMIXED data for use in PROC MIXED

TABLE 13.12. Results from PROC MIXED for AR(1) Structure

TABLE 13.13. Comparing pairwise times

TABLE 15.1. ODS output styles

TABLE 15.2. HTML output using SAS ODS

TABLE 15.3. ODS HTML output using JOURNAL style The MEANS Procedure

TABLE 15.4. Output in PDF format with the statistical style

TABLE 15.5. Output from drilling down from a bar chart

TABLE 15.6. Trace output from a PROC REG

TABLE 15.7. The SAS Data set created using ODS OUTPUT

TABLE 15.8. Results of calculating Z-Score

TABLE 16.1. Data from windows clipboard import

TABLE 16.2. Results of calculation using the RETAIN statement (these are the contents of the dataset DAYS)

TABLE 16.3. Example of ARRAYs and DO loops

TABLE 16.4. Example of transposed data

TABLE 16.5. Output from PROC TRANSPOSE

TABLE 16.6. Output from macro program

TABLE 16.7. Listing of transposed data

TABLE C.1. Decision table for descriptive statistics

TABLE C.2. Decision table for comparison tests

TABLE C.3. Decision table for relational analysis

Copyright © 2010 by John Wiley & Sons, Inc. All rights reserved.

Published by Jossey-Bass
A Wiley Imprint
989 Market Street, San Francisco, CA 94103-1741—www.josseybass.com

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, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400, fax 978-646-8600, or on the Web at www.copyright.com. Requests to the publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748-6008, or online at www.wiley.com/go/permissions.

Readers should be aware that Internet Web sites offered as citations and/or sources for further information may have changed or disappeared between the time this was written and when it is read.

Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.

Jossey-Bass books and products are available through most bookstores. To contact Jossey-Bass directly call our Customer Care Department within the U.S. at 800-956-7739, outside the U.S. at 317-572-3986, or fax 317-572-4002.

Jossey-Bass also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Cataloging-in-Publication Data

Elliott, Alan C., 1952-

SAS essentials : a guide to mastering SAS for research / Alan C. Elliott and Wayne A. Woodward.

p. cm.

Includes bibliographical references and index.

ISBN 978-0-470-46129-7 (pbk.)

1. SAS (Computer file) 2. Mathematical statistics—Data processing. I. Woodward, Wayne A. II. Title.

QA276.4.E423 2010

519.50285—dc22

2009031926

PB Printing

PREFACE

Although there are millions of SAS installations around the world, there is a steep learning curve involved in mastering the program. This book is a straightforward approach developed from more than fifteen years of teaching introductory SAS courses for scientific researchers and more than fifty combined years of teaching and consulting by the authors.

This book uses a hands-on programming approach to teaching SAS. It includes techniques for entering and manipulating data combined with step-by-step instructions for analyzing the data using commonly taught introductory applied statistical techniques.

Data sets for the examples can be downloaded from a Web site described in Chapter 1: “Creating a Folder for Storing Your SAS Files.” This book uses examples based on SAS 9.2 for Windows. However, the vast majority of the examples will work with any Windows version of SAS.

ACKNOWLEDGMENTS

There is more to SAS than a programming language and more to the output than p-values. With that in mind, this book integrates information from discussions with colleagues over several years who contributed ideas to the selection of content for this book. Several colleagues helped by reading early versions and providing suggestions on various topics from their area of expertise. These include Terry D. Bilhartz, PhD (Sam Houston State University), Linda Hynan, PhD (UT Southwestern Medical Center, Dallas) and Cecil Hallum (Sam Houston State University).

We are also indebted to the fine editorial and production staff at Josey Bass/Wiley Publications and for the reviewers that provided valuable insights and suggestions. In particular we’d like to thank Andy Pasternack, Seth Schwartz, and Kelsey McGee for their help in getting this work into print.

Above all we wish to thank our wives, E’Lynne and Beverly for their patience and support through the long process of writing and rewriting the book.

Alan C. Elliott and Wayne A. Woodward
Dallas, Texas

THE AUTHORS

Alan C. Elliott has been a faculty member at the University of Texas Southwestern Medical Center at Dallas, currently in the Center for Biostatistics and Clinical Science, for more than 25 years. He holds masters degrees in business administration (MBA) and applied statistics (MAS). He has authored or coauthored a number of scientific articles and more than a dozen books on a wide variety of subjects including the Directory of Microcomputer Statistical Software, Microcomputing with Applications, Getting Started in Internet Auctions, Currents in American History, and the Statistical Analysis Quick Reference Guide. He has taught courses in statistics, research methods and computing (including SAS and SPSS) at the university for more than fifteen years and has been a collaborator on numerous medical research projects.

Wayne A. Woodward received his PhD (1974) in mathematical statistics from Texas Tech University. He is professor of Statistics and chair of the Department of Statistical Science at Southern Methodist University. He was elected as fellow of the American Statistical Association in 1996 and in 2003 was named an Altshuler University Distinguished Teaching Professor at SMU. In 2004 he received the Don Owen Award, given annually by the San Antonio chapter of the American Statistical Association, for recognition of his contributions in the areas of research, consulting, and service to the statistical community. He was named the 2006-2007 United Methodist Church Scholar/Teacher of the Year at SMU. Wayne is an active researcher, having published more than 60 research articles. His primary research interests lie in the area of statistical time series analysis with applications in the analysis of brain imaging and EEG data and in outlier detection.

CHAPTER 1

GETTING STARTED

LEARNING OBJECTIVES

• To be able to use the SAS software program in a Windows environment

• To understand basic information about getting data into SAS and running a SAS program

• To be able to run a simple SAS program

Research involves the collection and analysis of data. The SAS system is a powerful software program designed to give researchers a wide variety of both data management and data analysis capabilities. Although SAS has millions of users worldwide, it is not the simplest program to learn. With that in mind, we’ve created this book to provide you with a straightforward approach to learning SAS that can help you surmount the learning curve and successfully use SAS for data analysis.

Two main concepts are involved in learning SAS: first, how to get data into SAS and ready for analysis, and second, how to perform the desired data analysis. This chapter introduces you to the SAS system’s use in the Microsoft Windows environment and provides examples of using SAS to analyze data.

USING SAS IN A WINDOWS ENVIRONMENT

SAS runs on a number of computer platforms (operating systems), including mainframes and personal computers whose operating systems are UNIX, Mac OS X, Linux, and Windows. This book is based on SAS’s use in the Windows environment, although most of what is covered is the same on any computer. We assume that you have already installed SAS on your computer. Most differences across computers have to do with file references. Before discussing the SAS program, we’ll review some of the basic file-handling features of Windows.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!