ebook img

Applied Statistics and the SAS Programming Language PDF

595 Pages·066.989 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Applied Statistics and the SAS Programming Language

Library of Congress Cataloging-in-Publication Data Cody,Ronald P. Applied statisticsandtheSASprogramming languageIRonald.P.Cody,JeffreyK. Smith- 5thed. p. em. Includes bibliographicalreferences andindex. ISBN0-13-146532-5 1.SAS(Computer file) 2. Mathematical statistics- Data processing. I. Smith,Jeffrey K. II. Title. QA276.4.C532006 519.5'0285'536- de22 2004060178 ExecutiveAcquisitions Editor:Petra Recter Editor-in-Chief: Sally Yagan Project manager:Jacqueline Riotto Zupic Full-ServiceProjectManager:Heather MeledinlProgressive Publishing Alternatives TotalConcept Coordinator: Lynda Castillo Assistant Manufacturing Manager/Buyer: Michael Bell Marketing Assistant:Rebecca Alimena Editorial Assistant:Joanne Wendelken Art Director:Jayne Conte Director ofCreative Services:Paul Belfanti Cover Designer: Bruce Kenselaar Cover Image:Getty Images • ©2006,1997,1991Pearson Education, Inc.. Pearson Prentice Hall Pearson Education, Inc. Upper Saddle River,NJ 07458 Published byElsevierSciencePublishing Co.,Inc.1985,and 1987. All rightsreserved.Nopart ofthisbook maybereproduced, inanyform orbyanymeans,without permission in writing fromthepublisher. Pearson Prentice Hall®isatrademark ofPearson Education, Inc. Printed inthe United StatesofAmerica 10987654 ISBN: 0-13-146532-5 Pearson Education LTD.,London Pearson Education Australia PTY,Limited, Sydney Pearson Education Singapore,Pte.Ltd Pearson Education NorthAsiaLtd, Hong Kong Pearson Education Canada, Ltd., Toronto Pearson Educacion deMexico,S.A.deC.V Pearson Education-Japan, Tokyo Pearson Education Malaysia, Pte.Ltd Contents Preface X1l1 Acknowledgments xv Chapter 1 A SAS Tutorial 1 A. Introduction 1 B. Computing with SAS:An Illnstrative Example 2 e. Enhancing the Program 7 D. SAS Procedures 11 E. Overview ofthe SAS DATA Step 13 F. Syntax ofSAS Procedures 14 G. Comment Statements 15 H. References 18 Problems 19 Chapter 2 Describing Data 24 A. Introduction 24 B. Describing Data 24 e. More Descriptive Statistics 29 D. Histograms, QQ Plots, and Probability Plots 38 E. Descriptive Statistics Broken Down bySubgroups 41 F. Frequency Distributions 43 G. Bar Graphs 45 H. Plotting Data 58 Problems 64 Chapter 3 Analyzing Categorical Data 69 A. Introduction 69 B. Questionnaire Design and Analysis 70 e. Adding Variable Labels 75 D. Adding" Value Labels" (Formats) 77 E. Recoding Data 82 v Contents F. UsingaFormat to Recode aVariable 85 G. Two-wayFrequency Tables 87 H. A Shortcut Wayto Request Multiple Tables 91 I. Computing Chi-square from Frequency Counts 92 1. A UsefulProgram for Multiple Chi-square Tables 93 K. A Useful Macro for Computing Chi-square from Frequency Counts 94 L. McNemar's Testfor Paired Data 95 M. Computing the Kappa Statistics (Coefficient ofAgreement) 99 N. Odds Ratios 100 O. Relative Risk 104 P. Chi-square Testfor Trend 106 Q. Mantel-Haenszel Chi-square for Stratified Tables and Meta-analysis 108 R. "CheckAllThat Apply" Questions 111 Problems 114 Chapter 4 Working with Date and Longitudinal Data 123 A. Introduction 123 B. Processing Date Variables 123 e. WorkingwithTwo-digitYear Values (the Y2KProblem) 129 D. Longitudinal Data 129 E. Selecting the First or Last Visitper Patient 133 F. Computing Differences between Observations in a Longitudinal Data Set 135 G. Computing the Difference between the First and Last Observation for Each Subject 138 H. Computing Frequencies on Longitudinal Data Sets 140 I. Creating Summary Data Sets with PROC MEANS or PROC SUMMARY 141 1. Outputting Statistics Other Than Means 153 Problems 154 Chapter 5 Correlation and Simple Regression 159 A. Introduction 159 B. Correlation 160 e. Significanceof a Correlation Coefficient 162 D. How to Interpret a Correlation Coefficient 164 E. Partial Correlations 165 F. Linear Regression 166 G. Partitioning theTotal Sum ofSquares 169 H. Producing aScatter Plot and the Regression Line 170 1. Adding a Quadratic Term to the Regression Equation 173 1. Transforming Data 174 Problems 179 Contents vii Chapter 6 T-tests and Nonparametric Comparisons 183 A. Introduction 183 B. T-test:Testing Differences between TwoMeans 183 e. Random Assignment ofSubjects 186 D. TwoIndependent Samples: Distribution-free Tests 190 E. One-tailed versusTwo-tailedTests 193 F. Paired T-tests (Related Samples) 194 Problems 196 Chapter 7 Analysis of Variance 199 A. Introduction 199 B. One-way Analysis ofVariance 199 e. Computing Contrasts 208 D. Analysis ofVariance:TwoIndependent Variables 209 E. Interpreting Significant Interactions 214 F. N-wayFactorial Designs 222 a. Unbalanced Designs: PROC GLM 223 H. Analysis of Covariance 227 Problems 231 Chapter 8 Repeated Measures Designs 236 A. Introduction 236 B. One-factor Experiments 237 e. Using the REPEATED Statement ofPROC ANOVA 243 D. Using PROC MIXED to Compute aMixed (Random Effects) Model 245 E. Two-factor Experiments witha Repeated Measure on One Factor 247 F. Two-factor Experiments with Repeated Measures on Both Factors 258 G. Three-factor Experiments with aRepeated Measure on the Last Factor 261 H. Three-factor Experiments with Repeated Measures onTwoFactors 268 Problems 278 Chapter 9 Multiple-Regression Analysis 282 A. Introduction 282 B. Designed Regression 283 e. Nonexperimental Regression 288 D. Stepwise and Other Variable Selection Methods 291 E. Creating and Using Dummy Variables 298 F. Using theVariance Inflation Factor to Look for Multicollinearity 300 Contents 0. LogisticRegression 300 H. Automatic Creation ofDummy VariableswithPROC LOGISTIC 314 Problems 315 Chapter 10 Factor Analysis 320 A. Introduction 320 B. TypesofFactorAnalysis 320 e. Principal Components Analysis 321 D. Oblique Rotations 330 E. UsingCommunalities Other Than One 331 F How toReverse Item Scores 333 Problems 335 Chapter 11 Psychometrics 336 A. Introduction 336 B. UsingSAStoScoreaTest 336 e. Generalizingthe Program for aVariableNumberofQuestions 339 D. CreatingaBetter-looking TableUsingPROC TABULATE 342 E. A CompleteTest-scoringand Item-analysisProgram 345 F. TestReliability 348 G. Iuterrarer Reliability 349 Problems 350 Chapter 12 The SAS INPUT Statement 353 A. Introduction 353 B. ListInput:Data ValuesSeparated bySpaces 353 e. Reading Comma-delimited Data 354 D. UsingINFORMATS withList Input 355 E. ColumnInput 357 F. Formatted Input 357 0. Reading MoreThan One Line per SUbject 359 H. Changingthe Order and Reading aColumnMore than Once 359 1. Inforrnat Lists 360 J "Holdingthe Line"-Single- and Double-trailing@s 361 K. Suppressingthe Error Messagesfor InvalidData 362 L. Reading "Unstructured" Data 363 Problems 370 Chapter 13 External Files:Reading and Writing Raw and System Files 376 A. Introduction 376 B. Data inthe Program Itself 377 e. Reading Data fromanExternalTextFile(ASCIIorEBCDIC) 378 D. INFILE Options 380 • Contents ix E. Reading Data [rom Multiple Files (Using Wildcards) 384 F. Writing ASCII or Raw Data to an External File 385 G. Writing CSV (Comma-separated Variables) Files Using SAS 386 H. Creating a Permanent SAS Data Set 387 I. Reading Permanent SAS Data Sets 388 J. How to Determine the Contents of aSAS Data Set 390 K. Permanent SAS Data Sets with Formats 391 L. Working with Large Data Sets 392 Problems 400 Chapter 14 Data Set Subsetting, Concatenating, Merging, and Updating 403 A. Introduction 403 B. Subsetting 403 e. Combining Similar Data from Multiple SASData Sets 405 D. Combining Different Data from Multiple SASData Sets 406 E. "Table Look Up" 409 F. Updating aMaster Data Setfrom an Update Data Set 412 Problems 413 Chapter 15 Working with Arrays 417 A. Introduction 417 B. Substituting One Value forAnother fora Series ofVariables 417 e. Extending Example 1to Convert All Numeric Values of 999to Missing 419 D. Converting theValue ofNtA (Not Applicable) to a Character Missing Value 420 E. Converting Heights and Weightsfrom English to Metric Units 421 F. Temporary Arrays 422 G. Using aTemporary Array to Score aTest 424 H. Specifying Array Bounds 426 I. Temporary Arrays and Array Bounds 426 J. Implicitly Subscripted Arrays 427 Problems 428 Chapter 16 Restructuring SAS Data Sets Using Arrays 432 A. Introduction 432 B. Creating a New Data Set withSeveral Observations per Subject from aData Set with One Observation per Subject 433 e. Another Example of Creating Multiple Observations from aSingleObservation 435 D. Going from One Observation per Subject to Many Observations per Subject UsingMultidimensional Arrays 436 E. Creating aData Set with One Observation per Subject from aData Set with Multiple Observations per Subject 438 :ontents F. Creating aData Set with One Observation per Subject from aData Set with Multiple Observations per Subject Using a Multidimensional Array 440 Problems 441 Chapter 17 A Review of SAS Functions: Functions Other than Character Functions 444 A. Introduction 444 B. Arithmetic and Mathematical Functions 444 e. Random Number Functions 446 D. Time and Date Functions 448 E. The INPUT and PUT Functions: Converting Numeric to Character and Character to Numeric Variables 450 F. The LAG and DIP Functions 452 Problems 453 Chapter 18 A Review of SAS Functions: Character Functions 457 A. Introduction 457 B. How Lengths of Character Variables Are Set in aSASData Step 458 e. Working with Blanks 460 D. How to Remove Characters from a String 461 E. Character Data Verification 462 F. Substring Example 463 a. Using the SUBSTR Function on the Left-hand Sideof the Equal Sign 464 H. Doing the Previous Example Another Way 465 I. Unpacking a String 465 I Parsing aString 466 K. Locating the Position of One String WithinAnother String 467 L. Changing Lowercase to Uppercase and ViceVersa 468 M. Substituting One Character for Another 469 N. Suhstituting One Word for Another in aString 470 O. Concatenating (Joining) Strings 471 p. Soundex Conversion 472 Q. Spelling Distance: The SPEDIS Function 473 Problems 474 Chapter 19 Selected Programming Examples. 480 A. Introduction 480 B. Expressing Data Values as aPercentage ofthe Grand Mean 480 e. Expressing aValue as a Percentage of a Group Mean 482 D. Plotting Means with Error Bars 483 E. Using aMacro Variable to Save Coding Time 485 ----_ ......_.----------_ .. ;;.""...~=- Contents xi F. Computing Relative Frequencies 485 G. Computing Combined Frequencies on Different Variables 487 H. Computing a Moving Average 489 T. Sorting Within an Observation 491 1. Computing Coefficient Alpha (or KR-20) in a DATA Step 492 Problems 494 Chapter 20 Syntax Examples 495 A. Introduction 495 M. PROC GPLOT 500 B. PROC ANOVA 496 N. PROC LOGISTIC 500 C. PROC APPEND 496 O. PROC MEANS 500 D. PROC CHART 496 P. PROC NPARI WAY 501 E. PROC CONTENTS 497 Q. PROC PLOT 501 F. PROC CORR 497 R. PROC PRINT 502 G. PROC DATASETS 497 S. PROC RANK 502 H. PROC FACTOR 498 T. PROG REG 503 T. PROC FORMAT 498 U. PROC SORT 503 1. PROC FREQ 499 V. PROC TTEST 503 K. PROC GCHART 499 W. PROC UNIVARIATE 503 L. PROC GLM 499 solutions to Odd-Numbered Problems 504 Index 563 CHAPTER 1 A SAS Tutorial A. Introduction B. Computing with SAS:An Illustrative Example C. Enhaucing the Program D. SAS Procedures Eo Overview ofthe SAS DATA Step E Syntax ofSAS Procedures G. Comment Statements H. References A. INTRODUCTION For the novice,engaging instatistical analysisofdata can seem asappealing asgoing to the dentist. Ifthat pretty much describes your situation, perhaps youcan take comfort in the fact that thisisthe fifthedition ofthisbook-meaning that the firstfour editions soldpretty well,and this time wemayget itright. Our purpose for thistutorial isto get you started using SAS.The key objective isto get one program to run successfully.If you can do that, you can branch out alittle bit at atime.Your expertise willgrow. SAS is a combination of programs originally designed to perform statistical analysis ofdaIa.Other programs you may have heard of are SPSS,BMDP, or SYSTAT. Ifyou look at personal computer magazines, you might run across other programs pri- marily designed to run on personal computers. Since its inception,~has grown to where itcan erform afairly impressive array ofnonstatistical functions.We'll get into a little of that in later c ap ers. or now,wewant to learn the most basic rudiments of the SAS system. Ifyou skipped over it,the Preface to the fifth edition contains some history of SAS software development and a more complete overview of the capabili- ties ofSAS software. Tobegin,SAS runs on awide variety ofcomputers and operating systems (com- puter people call these platforms), and we don't know which one you have.You may have a personal computer running aWindows operating system (such asWindows XP 1

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.