SAS Essentials - Alan C. Elliott - E-Book

SAS Essentials E-Book

Alan C. Elliott

0,0
51,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

SAS ESSENTIALS Valuable step-by-step introduction to using SAS¯® statistical software as a foundational approach to data analysis and interpretation Presenting a straightforward introduction from the ground up, SAS¯® Essentials illustrates SAS using hands-on learning techniques and numerous real-world examples; keeping different experience levels in mind, the highly qualified author team has developed the book over 25 years of teaching introductory SAS courses. This book introduces data manipulation, statistical techniques, and the SAS programming language, including SAS macros, reporting results in tables, and factor analysis, as well as sections on character functions, variable manipulation, and merging, appending, and updating files. It features self-contained chapters to enhance the learning process and includes programming approaches for the latest version of the SAS platform. The Third Edition has been updated with expanded examples, a new chapter introducing PROC SQL as well as new end-of-chapter exercises. The Third Edition also includes a companion website with data sets, additional code, notes on SAS programming, functions, ODS, PROC SQL, and SAS Arrays, along with solutions for instructors. Specific sample topics covered in SAS¯® Essentials include: * Getting data into SAS, reading, writing, and importing data, preparing data for analysis, preparing to use SAS procedures, and controlling output using ODS * Techniques for creating, editing, and debugging SAS programs, cleaning up messy data sets, and manipulating data using character, time, and numeric functions * Other essential computational skills that are utilized by business, government, and organizations alike, and DATA step for data management * Using PROC to analyze data, including evaluating quantitative data, analyzing counts and tables, comparing means using T-Tests, correlation and regression, and analysis of variance, nonparametric analysis, logistic regression, factor analysis, and creating custom graphs and reports. SAS¯® Essentials is a fundamental study resource for professionals preparing for the SAS Base Certification Exam, as well as an ideal textbook for courses in statistics, data analytics, applied SAS programming, and statistical computer applications.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 836

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Cover

Title Page

Copyright Page

ABOUT THE AUTHORS’ WEBSITE

PART I: DATA MANIPULATION AND THE SAS

®

PROGRAMMING LANGUAGE

1 GETTING STARTED

1.1 USING SAS IN A WINDOWS ENVIRONMENT

1.2 YOUR FIRST SAS ANALYSIS

1.3 HOW SAS WORKS

1.4 TIPS AND TRICKS FOR RUNNING SAS PROGRAMS

1.5 SUMMARY

EXERCISES

2 GETTING DATA INTO SAS

®

2.1 USING SAS DATASETS

2.2 UNDERSTANDING SAS DATASET STRUCTURE

2.3 RULES FOR SAS VARIABLE NAMES

2.4 UNDERSTANDING SAS VARIABLE TYPES

2.5 METHODS OF READING DATA INTO SAS

2.6 GOING DEEPER: MORE TECHNIQUES FOR ENTERING DATA

2.7 SUMMARY

EXERCISES

3 READING, WRITING, AND IMPORTING DATA

3.1 WORKING WITH SAS LIBRARIES AND PERMANENT DATASETS

3.2 CREATING PERMANENT SAS DATASETS USING THE WINDOWS FILE NAME TECHNIQUE

3.3 CREATING PERMANENT SAS DATASETS USING A SAS LIBRARY

3.4 CREATING A SAS LIBRARY USING A DIALOG BOX

3.5 CREATING A SAS LIBRARY USING CODE

3.6 USING DATA IN PERMANENT SAS DATASETS

3.7 IMPORTING DATA FROM ANOTHER PROGRAM

3.8 DISCOVERING THE CONTENTS OF A SAS DATASET

3.9 GOING DEEPER: UNDERSTANDING HOW THE DATA STEP READS AND STORES DATA

3.10 SUMMARY

EXERCISES

4 PREPARING DATA FOR ANALYSIS

4.1 LABELING VARIABLES WITH EXPLANATORY NAMES

4.2 CREATING NEW VARIABLES

4.3 USING IF‐THEN‐ELSE CONDITIONAL STATEMENT ASSIGNMENTS

4.4 USING DROP AND KEEP TO SELECT VARIABLES

4.5 USING THE SET STATEMENT TO READ AN EXISTING DATASET

4.6 USING PROC SORT

4.7 APPENDING AND MERGING DATASETS

4.8 USING PROC FORMAT

4.9 GOING DEEPER: FINDING FIRST AND LAST VALUES

4.10 SUMMARY

EXERCISES

5 PREPARING TO USE SAS

®

PROCEDURES

5.1 UNDERSTANDING SAS SUPPORT STATEMENTS

5.2 UNDERSTANDING PROC STATEMENT SYNTAX

5.3 USING THE ID STATEMENT IN A SAS PROCEDURE

5.4 USING THE LABEL STATEMENT IN A SAS PROCEDURE

5.5 USING THE WHERE STATEMENT IN A SAS PROCEDURE

5.6 USING PROC PRINT

5.7 GOING DEEPER: SPLITTING COLUMN TITLES IN PROC PRINT

5.8 GOING DEEPER: COMMON SYSTEM OPTIONS

5.9 SUMMARY

EXERCISES

6 PREPARING DATA FOR ANALYSIS

6.1 USING SAS FUNCTIONS

6.2 USING PROC TRANSPOSE

6.3 THE SELECT STATEMENT

6.4 GOING DEEPER: CLEANING A MESSY DATASET

6.5 SUMMARY

EXERCISES

7 SAS

®

ADVANCED PROGRAMMING TOPICS PART 2

7.1 USING SAS ARRAYS

7.2 USING DO LOOPS

7.3 USING THE RETAIN STATEMENT

7.4 USING SAS MACROS

7.5 SUMMARY

EXERCISES

8 CONTROLLING OUTPUT USING ODS

8.1 SPECIFYING THE ODS OUTPUT FORMAT AND DESTINATION

8.2 SPECIFYING ODS OUTPUT STYLE

8.3 USING ODS TO SELECT SPECIFIC OUTPUT TABLES FOR SAS PROCEDURES

8.4 GOING DEEPER: CAPTURING INFORMATION FROM ODS TABLES

8.5 GOING DEEPER: USING “TRAFFIC LIGHTING” TO HIGHLIGHT SELECTED VALUES

8.6 CREATING A POWERPOINT SLIDE USING GMAPS

8.7 EXTENDED ODS FEATURES

8.8 SUMMARY

EXERCISES

9 INTRODUCTION TO PROC SQL

9.1 WHAT IS SQL, AND HOW DOES IT FIT IN SAS?

9.2 USING THE SELECT STATEMENT: VARIABLE SELECTION IN A PROC SQL STATEMENT

9.3 USING THE FROM STATEMENT IN PROC SQL

9.4 CREATING SAS DATASETS

9.5 USING A WHERE CLAUSE

9.6 USING A GROUP BY CLAUSE IN PROC SQL

9.7 USING A HAVING CLAUSE

9.8 USING AN ORDER BY CLAUSE

9.9 GOING DEEPER: DOING CALCULATIONS USING CALCULATED VARIABLES

9.10 GOING DEEPER: UNIONS AND JOINS

9.11 SUMMARY

EXERCISES

PART II: STATISTICAL ANALYSIS USING SAS PROCEDURES

10 EVALUATING QUANTITATIVE DATA

10.1 USING PROC MEANS

10.2 USING PROC UNIVARIATE

10.3 GOING DEEPER: ADVANCED PROC UNIVARIATE OPTIONS

10.4 SUMMARY

EXERCISES

REFERENCE

11 ANALYZING COUNTS AND TABLES

11.1 USING PROC FREQ

11.2 ANALYZING ONE‐WAY FREQUENCY TABLES

11.3 CREATING ONE‐WAY FREQUENCY TABLES FROM SUMMARIZED DATA

11.4 ANALYZING TWO‐WAY TABLES

11.5 GOING DEEPER: CALCULATING RELATIVE RISK MEASURES

11.6 GOING DEEPER: INTER‐RATER RELIABILITY (KAPPA)

11.7 SUMMARY

EXERCISES

REFERENCES

12 COMPARING MEANS USING

T

‐TESTS

12.1 PERFORMING A ONE‐SAMPLE

T

‐TEST

12.2 PERFORMING A TWO‐SAMPLE

T

‐TEST

12.3 PERFORMING A PAIRED

T

‐TEST

12.4 SUMMARY

EXERCISES

REFERENCE

13 CORRELATION AND REGRESSION

13.1 CORRELATION ANALYSIS USING PROC CORR

13.2 SIMPLE LINEAR REGRESSION

13.3 MULTIPLE LINEAR REGRESSION USING PROC REG

13.4 GOING DEEPER: CALCULATING PREDICTIONS

13.5 GOING DEEPER: RESIDUAL ANALYSIS

13.6 SUMMARY

EXERCISES

14 ANALYSIS OF VARIANCE

14.1 COMPARING THREE OR MORE MEANS USING ONE‐WAY ANALYSIS OF VARIANCE

14.2 COMPARING THREE OR MORE REPEATED MEASURES

14.3 GOING DEEPER: CONTRASTS

14.4 SUMMARY

EXERCISES

REFERENCE

15 ANALYSIS OF VARIANCE, PART II

15.1 ANALYSIS OF COVARIANCE

15.2 GOING DEEPER: TWO‐FACTOR ANOVA USING PROC MIXED

15.3 GOING DEEPER: REPEATED MEASURES WITH A GROUPING FACTOR

15.4 SUMMARY

EXERCISES

REFERENCES

16 NONPARAMETRIC ANALYSIS

16.1 COMPARING TWO INDEPENDENT SAMPLES USING NPAR1WAY

16.2 COMPARING

K

INDEPENDENT SAMPLES (KRUSKAL–WALLIS)

16.3 COMPARING TWO DEPENDENT (PAIRED) SAMPLES

16.4 COMPARING

K

‐DEPENDENT SAMPLES (FRIEDMAN’S TEST)

16.5 GOING DEEPER: NONPARAMETRIC MULTIPLE COMPARISONS

16.6 SUMMARY

EXERCISES

REFERENCES

17 LOGISTIC REGRESSION

17.1 LOGISTIC ANALYSIS BASICS

17.2 PERFORMING A LOGISTIC ANALYSIS USING PROC LOGISTIC

17.3 USING SIMPLE LOGISTIC ANALYSIS

17.4 MULTIPLE BINARY LOGISTIC ANALYSIS

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

17.6 SUMMARY

EXERCISES

REFERENCES

18 FACTOR ANALYSIS

18.1 FACTOR ANALYSIS BASICS

18.2 SUMMARY

EXERCISES

REFERENCES

19 CREATING CUSTOM GRAPHS

19.1 CREATING SCATTERPLOTS AND LINE GRAPHS USING GPLOT

19.2 CREATING BAR CHARTS AND PIE CHARTS

19.3 DEFINING GRAPH PATTERNS

19.4 CREATING STACKED BAR CHARTS

19.5 CREATING MEAN BARS USING GCHART

19.6 CREATING BOXPLOTS

19.7 GOING DEEPER: CREATING AN INTERACTIVE BAR USING ODS

19.8 GOING DEEPER: SGPLOTS

19.9 OTHER WAYS TO CUSTOMIZE PLOTS

19.10 SUMMARY

EXERCISES

REFERENCE

20 CREATING CUSTOM REPORTS

20.1 USING PROC TABULATE

20.2 USING PROC REPORT

EXERCISES

APPENDIX A: APPENDIX AOPTIONS REFERENCE

A.1 USING SAS FONTS

A.2 SPECIFYING SAS COLOR CHOICES

A.3 SPECIFYING PATTERNS FOR PROCS GPLOT AND PROC UNIVARIATE

A.4 BAR AND BLOCK PATTERNS FOR BAR CHARTS, PIE CHARTS, AND OTHER GRAPHICS

A.5 SAS LINE STYLES

A.6 USING SAS PLOTTING SYMBOLS

A.7 USING ODS STYLE ATTRIBUTES

A.8 COMMON (INPUT) INFORMATS

A.9 COMMON (OUTPUT) FORMATS

APPENDIX B: APPENDIX BSAS® FUNCTION REFERENCE

B.1. USING SAS FUNCTIONS

B.2. ARITHMETIC/MATHEMATICAL FUNCTIONS

B.3. TRIGONOMETRIC FUNCTIONS

B.4. DATE AND TIME FUNCTIONS

B.5. CHARACTER FUNCTIONS

B.6. TRUNCATION FUNCTIONS

B.7. FINANCIAL FUNCTIONS

B.8. SPECIAL USE FUNCTIONS

B.9. QUICK GUIDE TO SAS FUNCTIONS

APPENDIX C: APPENDIX CCHOOSING A SAS

®

PROCEDURE

C.1 DESCRIPTIVE STATISTICS

C.2. COMPARISON TESTS

C.3. RELATIONAL ANALYSES (CORRELATION AND REGRESSION)

APPENDIX D: APPENDIX DSAS CODE EXAMPLES

APPENDIX E: APPENDIX EUSING SAS

®

ONDEMAND FOR ACADEMICS WITH SAS ESSENTIALS

E.1 INSTALLING SAS ONDEMAND FOR ANALYTICS

E.2 LIMITATIONS

E.3 SUMMARY

APPENDIX F: APPENDIX FSAS

®

Example BASE Exam Questions

Answers to BASE Exam Sample Test

Index

End User License Agreement

List of Tables

Chapter 1

TABLE 1.1

Accessing Files in Various Operating Systems

TABLE 1.2

SAS Function Keys

Chapter 2

TABLE 2.1

Overview of the SAS DATA Step

TABLE 2.2

SAS Dataset (Table) Structure

TABLE 2.3

A Sample SAS Dataset

TABLE 2.4

Output from PROC PRINT for the Freeform Entry Example

TABLE 2.5

Output from the Column Entry Example

TABLE 2.6

Example SAS Informats (Input Formats)

TABLE 2.7

Output from Formatted Data Entry Example

TABLE 2.8

Example SAS (Output) FORMATs

TABLE 2.9

Output from Formatted Data Entry Example Including Dates

TABLE 2.10

Using the INFILE Statement

TABLE 2.11

Using Multiline Entry

TABLE 2.12

INPUT Pointer Control Commands

TABLE 2.13

INFILE Options

TABLE 2.14

Output from Reading CSV File

TABLE 2.15

Output from Reading Data with an Unusual Delimiter

TABLE 2.16

Output from Reading CSV File with Problems

TABLE 2.17

Output from Reading Data from a .CSV File Using TRUNCOVER

Chapter 3

TABLE 3.1

SAS DBMS Data Sources

TABLE 3.2

Example PROC CONTENTS Output

Chapter 4

TABLE 4.1

OUTPUT without Labels

TABLE 4.2

OUTPUT with Labels

TABLE 4.3

Listing Formatted Dates

TABLE 4.4

SAS Arithmetic Operators

TABLE 4.5

Output Showing Results of Calculation

TABLE 4.6

SAS Conditional Operators

TABLE 4.7

SAS Logical Operators

TABLE 4.8

Results of IF‐THEN‐ELSE Statement

TABLE 4.9

SAS Sorting Sequence

TABLE 4.10

SAS Output Showing Sort Ascending and Descending

TABLE 4.11

SAS Output Showing Result of KEEP and RENAME in SORT Statement

TABLE 4.12

Example Output from Merged Datasets

TABLE 4.13

Data for a Few‐to‐Many Merge

TABLE 4.14

Results for the Few‐to‐Many Merge

TABLE 4.15

Application of a FORMAT

TABLE 4.16

Finding First and Last in a Group

Chapter 5

TABLE 5.1

Output Showing a TITLE and FOOTNOTE for PROC PRINT

TABLE 5.2

Output Showing a TITLE and FOOTNOTE for PROC MEANS

TABLE 5.3

Common Options for TITLEs and FOOTNOTEs

TABLE 5.4

Common Options and Statements for SAS PROCS

TABLE 5.5

Output from PROC MEANS

TABLE 5.6

Output before Defining ID Column

TABLE 5.7

Output after Defining ID Column

TABLE 5.8

Using Revised Labels in PROC PRINT

TABLE 5.9

Selection Using the Where Statement

TABLE 5.10

Common Options and Statements for PROC PRINT

TABLE 5.11

PROC PRINT Using SUM, OBS, and

N

TABLE 5.12

Example of Column Titles in PROC PRINT

TABLE 5.13

Example Revised of Column Titles in PROC PRINT

TABLE 5.14

Common System Options

Chapter 6

TABLE 6.1

Results of the INTCK Function Calculation

TABLE 6.2

Example of Transposed Data

TABLE 6.3

Transposed Data with ID

TABLE 6.4

Data from the COMPLICATIONS Dataset

TABLE 6.5

Output from PROC TRANSPOSE

TABLE 6.6

Example of SELECT Statement

TABLE 6.7

A Messy Dataset

TABLE 6.8

Data Dictionary for Messy Dataset

TABLE 6.9

First Pass to Fix Messy Data

TABLE 6.10

Some Corrected Variables in the Messy Dataset

TABLE 6.11

Frequencies for Several Categorical Variables

TABLE 6.12

Checking Means for Several Variables

TABLE 6.13

Converting Date and Time Values

TABLE 6.14

Calculated Values for Time Stayed in Clinic

TABLE 6.15

Discovering Duplicate IDs

TABLE 6.16

Discovering Observation Number for Supplicate IDs

TABLE 6.17

Listing of Transposed Data

Chapter 7

TABLE 7.1

Values in an Array

TABLE 7.2

Example Output Using the

IN

Statement with an Array

TABLE 7.3

Example of Using the DO WHILE Statement

TABLE 7.4

Example of ARRAYs and DO Loops

TABLE 7.5

Results of Using LBOUND and HBOUND in a DO Loop

TABLE 7.6

Results of Calculation Using the RETAIN Statement

TABLE 7.7

Using RETAIN to Accumulate TOTAL and Find MAX

TABLE 7.8

Output Obtained Using the %LET Statement to Create Macro Variables

TABLE 7.9

Output Created Using Macro Variables

TABLE 7.10

Output from Macro Program

TABLE 7.11

Output Showing GSLIDE Results

TABLE 7.12

Output Showing Results of %DO Loop

TABLE 7.13

Output Showing Results of Call Symput

Chapter 8

TABLE 8.1

Current ODS Styles for SAS 9.4

TABLE 8.2

Microsoft Word Output Using SAS ODS

TABLE 8.3

ODS HTML Output Using Festival Style

TABLE 8.4

Output in ODS PDF Format Using Statistical Style

TABLE 8.5

The SAS Dataset Created Using ODS Output

TABLE 8.6

Results of Calculating

Z

‐Score

TABLE 8.7

Frequency Output from PROC FREQ

TABLE 8.8

Traffic Light Example

Chapter 9

TABLE 9.1

A SQL View Resulting from the PROC SAS Program (Results not Order

...

TABLE 9.2

Results of Calculating Values in SQL

TABLE 9.3

Grouped Output from PROC SQ

TABLE 9.4

Results of a SQL Append

TABLE 9.5

Types of SQL UNIONS

TABLE 9.6

Types of SQL JOINS

TABLE 9.7

Output Illustrating the Use of the JOIN Command

Chapter 10

TABLE 10.1

Common Options for PROC MEANS

TABLE 10.2

Statistics Keywords for PROC MEANS

TABLE 10.3

Common Statements for PROC MEANS

TABLE 10.4

Output for PROC MEANS

TABLE 10.5

PROC MEANS Output Using the BY Option

TABLE 10.6

PROC MEANS Output Using the CLASS Option

TABLE 10.7

PROC MEANS Using OUTPUT Statement

TABLE 10.8

Output Includes Calculated ZSCORE

TABLE 10.9

Common Options for PROC UNIVARIATE

TABLE 10.10

Common Statements for PROC UNIVARIATE

TABLE 10.11

Common OPTIONS for the PROC UNIVARIATE HISTOGRAM Statement

TABLE 10.12

Common OPTIONS for the COLOR Statement (in a Univariate Graph)

...

TABLE 10.13 Common OPTIONS for the PROC UNIVARIATE BAR Statement (Related t...

TABLE 10.14

Common OPTIONS for the PROC UNIVARIATE INSET Statement

TABLE 10.15

Moments Output for PROC UNIVARIATE

TABLE 10.16

Basic Statistical Measures from PROC UNIVARIATE

TABLE 10.17

Tests for Location from PROC UNIVARIATE

TABLE 10.18

Quantiles from PROC UNIVARIATE

TABLE 10.19

Extreme Values Output from PROC UNIVARIATE

TABLE 10.20 Test for Normality from PROC UNIVARIATE

Chapter 11

TABLE 11.1

Common Options for PROC FREQ

TABLE 11.2

Common Statements for PROC FREQ

TABLE 11.3

Sample TABLES Statements

TABLE 11.4

Options for the TABLE Statement

TABLE 11.5

Simple Output for PROC FREQ

TABLE 11.6

PROC FREQ Output Using the ORDER=FREQ Option

TABLE 11.7

Output from PROC FREQ Using the ORDER=FORMATTED Option

TABLE 11.8

Simple Output for PROC FREQ

TABLE 11.9

Goodness‐of‐Fit Test Using PROC FREQ

TABLE 11.10

Cross‐Tabulation from PROC FREQ

TABLE 11.11

Statistics for Drinking and Crime Cross‐Tabulation

TABLE 11.12

Expected Values for Drinking and Crime Data

TABLE 11.13

Cross‐Tabulation of Cleaner By Rash

TABLE 11.14

Statistics Tables for a 2 × 2 Analysis

TABLE 11.15

Cross‐Tabulation of a 2 × 2 Table with Small Cell Sizes

...

TABLE 11.16

Cross‐Tabulation of a 2 × 2 Table Showing Expected Values

...

TABLE 11.17

Relative Risk Measures for the Floor Cleaner Data

TABLE 11.18

Data for Inter‐Rater Reliability Analysis

TABLE 11.19

Results for Kappa Analysis

TABLE 11.20

Interpretation of Kappa Statistic

TABLE 11.21

Partial SECURITY Data

TABLE 11.22

Cross‐Tabulation of Security Data

TABLE 11.23

Kappa Results for Security Data

Chapter 12

TABLE 12.1

t

‐Test Results Using PROC UNIVARIATE

TABLE 12.2

t

‐Test Results Using PROC TTEST

TABLE 12.3

Common Options and Statements for PROC TTEST

TABLE 12.4

Two‐Sample

t

‐Test Output from PROC TTEST

TABLE 12.5

Paired

t

‐Test Output

Chapter 13

TABLE 13.1

Common Options for PROC CORR

TABLE 13.2

Output from PROC CORR

TABLE 13.3

Correlations Using a WITH Statement

TABLE 13.4

Common Options for PROC REG

TABLE 13.5

Output from PROG REG for a Simple Linear Regression

TABLE 13.6

Common Options for PROC REG for Multiple Regression

TABLE 13.7

Common Statement Options for the PROC REG MODEL Statement (Optio

...

TABLE 13.8

Analysis of Variance Output for PROC REG

TABLE 13.9

Parameter Estimates

TABLE 13.10

Parameter Estimates for Revised Model

TABLE 13.11

Parameter Estimates for Final Model

TABLE 13.12

Predictions Using Final Model

TABLE 13.13

Output Statistics for PROC REG

TABLE 13.14

Regression Estimates for Washington, DC, Crime Data 1978–1993

...

Chapter 14

TABLE 14.1

Common Options for PROC ANOVA and PROC GLM for Performing a One‐

...

TABLE 14.2

Common

type comparison

Options for the PROC ANOVA or GLM MEANS

...

TABLE 14.3

ANOVA Results

TABLE 14.4

Simultaneous Confidence Limits

TABLE 14.5

Analysis of Variance Results

TABLE 14.6

Analysis of Variance Results

TABLE 14.7

LSMEANS Multiple Comparison Results

TABLE 14.8

CONTRAST Results from PROC GLM

TABLE 14.9

Additional CONTRAST Results

Chapter 15

TABLE 15.1

Data from Math Course Analysis

TABLE 15.2

Test of Slopes for Analysis of Covariance

TABLE 15.3

Analysis of Covariance Test of Main Effects

TABLE 15.4

Scheffe Multiple Comparisons for ANCOVA

TABLE 15.5

ANOVA Results from a Two‐Factor Analysis Using PROC GLM

TABLE 15.6

Marginal Means for Levels of STATUS

TABLE 15.7

PROC MEANS Output

TABLE 15.8

PROC MIXED Output Testing the Fixed Factor

TABLE 15.9

Model Run as If All Factors Were Fixed

TABLE 15.10

Original Dataset of Repeated Measures Data

TABLE 15.11

REPMIXED Data for Use in PROC MIXED

TABLE 15.12

Results from PROC MIXED for AR(1) Structure

TABLE 15.13

Comparing Pairwise Times

Chapter 16

TABLE 16.1

Common Options for PROC NPAR1WAY

TABLE 16.2

Output from NPAR1WAY for a Two‐Group Analysis

TABLE 16.3

Output from NPAR1WAY for a Four‐Sample Group Comparison

TABLE 16.4

PROC UNIVARIATE to Test Paired Difference

TABLE 16.5

Results for Friedman’s Test

TABLE 16.6

Multiple Comparison Test for a Kruskal–Wallis Analysis

TABLE 16.7

Store Shrinkage, in Thousands

Chapter 17

TABLE 17.1

Common Options for PROC LOGISTIC

TABLE 17.2

Common MODEL Statement options for PROC Logistic

TABLE 17.3

Output from Logistic Regression

TABLE 17.4

Output for a Continuous Measure from Logistic Regression

TABLE 17.5

CLASS Variables

TABLE 17.6

Final Model

TABLE 17.7

Hosmer and Lemeshow Results

TABLE 17.8

Classification Table for Logistic Regression

TABLE 17.9

Big Box Store Sales

Chapter 18

TABLE 18.1

Common Options for PROC FACTOR

TABLE 18.2

Descriptive Statistics for Intelligence Data

TABLE 18.3

Correlations for Intelligence Data

TABLE 18.4

Prior Communalities Estimates Using PRIORS=SMC

TABLE 18.5

Eigenvalues of the Reduced Correlation Matrix

TABLE 18.6

Communalities Associated with the Two‐Factor Solution

TABLE 18.7

Factor Pattern Matrix Associated with the Two‐Factor Solution

...

TABLE 18.8

Rotated Factor Pattern Matrix Using VARIMAX Rotation

TABLE 18.9

Output from PROC PRINT Showing the First 8 Factor Scores

TABLE 18.10

Descriptive Statistics for Olympic Athlete Data

TABLE 18.11

Correlations for Olympic Athlete Data

TABLE 18.12

Prior Communalities Estimates Using PRIORS=SMC for Olympic Athl

...

TABLE 18.13

Eigenvalues of the Reduced Correlation Matrix for Olympic Athle

...

TABLE 18.14

Communalities Associated with the Three‐Factor Solution for the

...

TABLE 18.15

Factor Pattern Matrix Associated with the Three‐Factor Solution

...

TABLE 18.16

Rotated Factor Pattern Matrix for the Olympic Athlete Data Usin

...

Chapter 19

TABLE 19.1 Common Options for PROC GPLOT

TABLE 19.2 Common Statements for PROC GPLOT

TABLE 19.3 Common Options for PROC GPLOT’s PLOT Statement

TABLE 19.4 Common Options for PROC GPLOT’s SYMBOL Statement

TABLE 19.5 AXIS Names for GPLOT and GCHART

TABLE 19.6 Common Options for PROC GPLOT’s AXIS Statement

TABLE 19.7 Common Options for PROC GCHART

TABLE 19.8 Common GCHART Options for Bar Charts

TABLE 19.9 Pattern Definitions for the PATTERN Value Statement

TABLE 19.10 Common Statements for PROC BOXPLOT

TABLE 19.11 Common Options the BOXPLOT PLOT Statement (Follows a Slash (/) ...

TABLE 19.12 Report for Group A

TABLE 19.13 Common PLOT Statements for PROC SGPLOT

Chapter 20

TABLE 20.1 Common Options for PROC TABULATE

TABLE 20.2 Common Statements in PROC TABULATE

TABLE 20.3 The Regions Dataset

TABLE 20.4 Simple PROC TABULATE Table

TABLE 20.5 PROC TABULATE Table Using Two Variables

TABLE 20.6 A PROC TABULATE Table with Rows and Columns

TABLE 20.7 A PROC TABULATE Table with Labels and Formats

TABLE 20.8 Statistics Available in PROC Tabulate

TABLE 20.9 A PROC TABULATE Table with Sum

TABLE 20.10 A PROC TABULATE Table with Means

TABLE 20.11 A PROC TABULATE with ALL

TABLE 20.12 A PROC TABULATE with ALL

TABLE 20.13 A PROC TABULATE as Output to Excel

TABLE 20.14 PROC REPORT DEFINE Statement Options

TABLE 20.15 PROC REPORT DEFINE Statement Option Attributes

TABLE 20.16 PROC REPORT DISPLAY Option Example

TABLE 20.17 PROC REPORT Using ORDER Option

TABLE 20.18 PROC REPORT by GROUP

TABLE 20.19 PROC REPORT Using ANALYSIS Option

TABLE 20.20 PROC REPORT Using COMPUTE Option

TABLE 20.21 PROC REPORT Using the ACROSS Option

TABLE 20.22 PROC REPORT with Means

TABLE 20.23 A Portion of the PROC REPORT Table with Means

TABLE 20.24 Options for the PUT Statement

TABLE 20.25 Results of PROC MEANS on the GRADE Data

TABLE 20.26 Grade Report Created Using PUT Statements

1

TABLE A.1 Custom Pattern Codes

TABLE A.2 Line styles

TABLE A.3 Common ODS Style Options

TABLE A.4 Common SAS Informats (Input Formats)

TABLE A.5 Common SAS (Output) FORMATs

2

TABLE B.1

Arithmetic and Mathematical Functions

TABLE B.2

Using of Arithmetic Functions

TABLE B.3

Arithmetic and Trigonometric Functions

TABLE B.4

Date and Time Functions

TABLE B.5

Using Date and Time Functions

TABLE B.6

Character Functions

TABLE B.7

SCAN, LENGTH, and CAT Functions

TABLE B.8

Truncation Functions

TABLE B.9

Special Use Functions

TABLE B.10

Example of MORT Function

TABLE B.11

Special Use Functions

TABLE B.12

Output from PUT and INPUT Example

TABLE B.13

Convert Dates to Components

TABLE B.14

January Open Prices, Yearly Change

TABLE B.15

Find Distances Using the ZIP Functions

3

TABLE C.1

Decision Table for Descriptive Statistics

TABLE C.2

Decision Table for Comparison Tests

TABLE C.3

Decision Table for Relational Analysis

5

TABLE E.1

Results of SECOND.SAS, run in SAS ODA

TABLE E.2

Results of SAMPLEPROGRAMS.SAS, run in SAS ODA.

List of Illustrations

Chapter 1

Figure 1.1 Initial SAS screen.

Figure 1.2 The FIRST.SAS file opened

Figure 1.3 Results for FIRST.SAS

Figure 1.4 How SAS works

Figure 1.5 Help file display

Chapter 2

Figure 2.1 SAS Basic Tips, page 1

Figure 2.2 SAS Basic Tips, page 2

Chapter 3

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 CSV data ready for import

Figure 3.6 Initial screen of the SAS Import Wizard

Figure 3.7 Selecting a CSV file name

Figure 3.8 Selecting the library and member name

Figure 3.9 MPG_FOR_CARS dataset n SAS Viewer

Figure 3.10 The SAS INPUT process

Chapter 4

Figure 4.1 Creating a new dataset using the SET statement

Figure 4.2 FORMAT folders

Chapter 5

Figure 5.1 Illustrating options for titles and footnotes

Chapter 7

Figure 7.1 Quick Tips for Using SAS Arrays

Figure 7.2 Quick Tips for Using SAS Arrays, page 2

Figure 7.3

How a SAS macro works

Chapter 8

Figure 8.1 ODS TRACE output

Figure 8.2 Trace output from a PROC MEANS

Figure 8.3 Preferences/results dialog box

Figure 8.4 Requested ODS graph from PROC FREQ

Figure 8.5 Map Created as a PowerPoint slide

Chapter 9

Figure 9.1 SAS PROC SQL Reference, part 1

Figure 9.2 SAS PROC SQL Reference, part 2

Figure 9.3 SAS PROC SQL Unions and Joins Part 1

Figure 9.4 SAS PROC SQL Unions and Joins, part 2

Chapter 10

Figure 10.1 Default plots to assess normality from PROC UNIVARIATE

Figure 10.2 Histogram with normal curve superimposed

Figure 10.3 Multiple histograms from PROC UNIVARIATE

Figure 10.4 PROC UNIVARIATE histogram output using two grouping variables

Figure 10.5 Multiple histograms from the CAR dataset

Chapter 11

Figure 11.1 Partial viewtable for the RASH dataset

Figure 11.2 Example graphical output from a kappa test

Chapter 12

Figure 12.1 Histogram, kernel density estimate, and normal curve output for ...

Figure 12.2 Plots produced by PROC TTEST

Figure 12.3 Plots produced by PROC TTEST using the PAIRED option

Chapter 13

Figure 13.1 Matrix of scatterplots

Figure 13.2 Scatterplots with histogram

Figure 13.3 Scatterplots with prediction ellipse

Figure 13.4 The SAS model statement

Figure 13.5 A scatterplot of

CREATE

*

TASK

with a regression fit

Figure 13.6 Diagnostic plots for a simple linear regression

Figure 13.7 Visualizing a prediction interval

Figure 13.8 Fit plot for JOBSCORE model

Figure 13.9 Washington, DC, assaults, 1978–1993

Chapter 14

Figure 14.1 Tukey Multiple Comparisons Results

Figure 14.2 Box plots for one‐way ANOVA

Figure 14.3 Duncan’s Multiple Comparison Results

Figure 14.4 Interaction plot for repeated measures

Chapter 15

Figure 15.1 Regression lines for ANCOVA data

Figure 15.2 Parallel lines for ANCOVA data, for the second model assuming pa...

Figure 15.3 Graphical representation of Scheffe results

Figure 15.4 (a, b) Example of an interaction effect

Figure 15.5 Interaction plot for the two‐factor ANOVA example

Figure 15.6 (a, b) Custom plots for repeated measures analysis

Chapter 16

Figure 16.1 Boxplots from animal feeds data

Chapter 17

Figure 17.1 A logistic plot from a simple logistic model

Figure 17.2 ROC curve

Chapter 18

Figure 18.1 Scree plot

Figure 18.2 Scree plot for Olympic Athlete Data

Chapter 19

Figure 19.1 Default scatterplot using PROC GPLOT

Figure 19.2 PROC GPLOT with dots and line specified

Figure 19.3 PROC GPLOT with dots and lines specified

Figure 19.4 PROC GPLOT showing error bars

Figure 19.5 Horizontal bar chart using PROC GCHART

Figure 19.6 PROC GCHART showing groups bars

Figure 19.7 Stacked bar chart

Figure 19.8 Enhanced bar chart

Figure 19.9 Means with error bars

Figure 19.10 Boxplots showing highway MPG by cylinders

Figure 19.11 Boxplots with enhancements

Figure 19.12 Drill‐down plot, first run

Figure 19.13 Code to create an HTML report file

Figure 19.14 Histogram created using SGPLOTS

Figure 19.15 Histogram with normal and kernel curves

Figure 19.16 Horizontal bar chart

Figure 19.17 SGPLOT clustered bar chart

Figure 19.18 SGPLOT scatterplot

Figure 19.19 SGPLOT scatterplot with regression lines

Figure 19.20 Bubble plot created using SGPLOT

1

Figure A.1 Example SAS fonts

Figure A.2 Example crosshatch pattern

Figure A.3 Example fill patterns

Figure A.4 Graph showing selected line style

2

Figure B.1 Quick Guide to SAS Functions, page 1

Figure B.2 Quick Guide to SAS Functions, page 2

5

Figure E.1 SAS Studio server files and folders. If SAS Studio doesn’t come u...

Figure E.2 Upload Files dialog box for SAS Studio

Figure E.3 List of Uploaded files in SAS Studio

Figure E.4 New Library Dialog Box

Figure E.5 SG plot from SAS ODA

Guide

Cover Page

Title Page

Copyright Page

ABOUT THE AUTHORS’ WEBSITE

Table of Contents

Begin Reading

APPENDIX A OPTIONS REFERENCE

APPENDIX B SAS® FUNCTION REFERENCE

APPENDIX C CHOOSING A SAS® PROCEDURE

APPENDIX D SAS CODE EXAMPLES

APPENDIX E USING SAS® ONDEMAND FOR ACADEMICS WITH SAS ESSENTIALS

APPENDIX F SAS® Example BASE Exam Questions

Index

WILEY END USER LICENSE AGREEMENT

Pages

iii

iv

vii

1

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

SAS® ESSENTIALS

Mastering SAS for Data Analytics

Third Edition

ALAN C. ELLIOTT and WAYNE A. WOODWARD

This edition first published 2023© 2023 John Wiley and Sons, Inc.

Edition HistoryJohn Wiley & Sons (2e, 2015)

All rights reserved. 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 or otherwise, except as permitted by law. Advice on how to obtain permission to reuse material from this title is available at http://www.wiley.com/go/permissions.

The right of Alan C. Elliott and Wayne A. Woodward to be identified as the authors of this work has been asserted in accordance with law.

Registered OfficeJohn Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, USA

Editorial Office111 River Street, Hoboken, NJ 07030, USA

For details of our global editorial offices, customer services, and more information about Wiley products visit us at www.wiley.com.

Wiley also publishes its books in a variety of electronic formats and by print‐on‐demand. Some content that appears in standard print versions of this book may not be available in other formats.

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

Limit of Liability/Disclaimer of WarrantyIn view of ongoing research, equipment modifications, changes in governmental regulations, and the constant flow of information relating to the use of experimental reagents, equipment, and devices, the reader is urged to review and evaluate the information provided in the package insert or instructions for each chemical, piece of equipment, reagent, or device for, among other things, any changes in the instructions or indication of usage and for added warnings and precautions. While the publisher and authors have used their best efforts in preparing this work, they make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives, written sales materials or promotional statements for this work. The fact that an organization, website, or product is referred to in this work as a citation and/or potential source of further information does not mean that the publisher and authors endorse the information or services the organization, website, or product may provide or recommendations it may make. This work is sold with the understanding that the publisher is not engaged in rendering professional services. The advice and strategies contained herein may not be suitable for your situation. You should consult with a specialist where appropriate. Further, readers should be aware that websites listed in this work may have changed or disappeared between when this work was written and when it is read. Neither the publisher nor authors shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.

Library of Congress Cataloging‐in‐Publication Data Applied for:Paperback ISBN: 9781119901617

Cover Design: WileyCover Image: © piranka/Getty Images

ABOUT THE AUTHORS’ WEBSITE

This book is accompanied by the authors’ website:

https://www.alanelliott.com/SASED3/

This site will contain links to:

The data and program files referenced in the book

PowerPoint files for instructors

Teaching videos that relate to the book's content

Quick tip pages referenced in the book

Future help or exercises related to the book's content

PART IDATA MANIPULATION AND THE SAS® PROGRAMMING LANGUAGE

1GETTING STARTED

LEARNING OBJECTIVES

To be able to use the SAS

®

software program in a Windows environment.

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

To be able to run a simple SAS program.

Data analytics is the process of gathering and using data to understand some process, predict a future outcome, or make a decision. The SAS system is a powerful software program designed to give data analysts 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: (1) how to get data into SAS and ready for analysis using the SAS programming language and (2) how to perform the desired data analysis.

Part 1

(

Chapters 2

9

) shows how to get data into SAS and prepare it for analysis.

Part 2

(

Chapters 10

20

) shows how to use data to perform statistical analyses, create graphs, and produce reports.

This chapter introduces you to the SAS system’s use in the Microsoft Windows environment and provides numerous Hands‐On examples of how to use SAS to analyze data.

1.1 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, Linux, or Windows. This book is based on using SAS in a Windows environment where you have the software installed on your local computer. The vast majority of the content in this book will apply to any SAS computer environment. However, we will include occasional references to differences that are present in other operating systems. Most of the differences between versions have to do with file references. Moreover, there are multiple ways to use SAS, notably the programming or Enterprise Guide approaches. This book teaches the programming approach that offers the user the most flexibility. Before discussing the SAS program, we’ll review some of the basic file‐handling features of Windows. There is a free version of SAS called OnDemand for Academics: SAS Studio for Learning Purposes. Appendix E discusses how to install this version and how it can be used to run many of the examples in this book.

1.1.1 Creating a Folder for Storing Your SAS Files

As there are several versions of Windows currently in use, we present general guidelines that should work in any one of them. To follow our examples, we recommend that you store the data and SAS files provided in this book in a folder named SASDATA. In fact, we recommend that you do this NOW!. The examples in this text will assume that all example files used in this book are in a folder whose file path is C:\SASDATA. You can adapt the examples by using an appropriate file path for other operating systems. Table 1.1 shows several ways to reference a file.

In your own data analysis, you may choose to store your SAS files in a folder with a name that makes sense to you, such as C:\RESEARCH. You can also create subfolders for each analysis; for example, C:\RESEARCH\SMITH or C:\RESEARCH\JONES.

To copy the example files of this book to the C:\SASDATA folder on your own computer, perform the following:

Download the example files from the following web site:

http://www.alanelliott.com/sas

Follow the installation instructions provided on the web site for the 3rd edition of this book. Doing so creates the

C:\SASDATA

folder on your computer and copies the example files to that folder. (The web site also includes updates concerning the information in this book and other helpful resources.)

TABLE 1.1Accessing Files in Various Operating Systems

Operating System

Example File Reference

Windows

C:\SASATA\myfile

Windows/Cytrix

\\CLIENT\C$\SASDATA\myfile

UNIX

/home/sasdata/myfile

Open VMS

[username.sasdata]myfile

z/OS

SASDATA.myfile

You can also use SAS on an Apple Mac. To do so, we recommend that you install a virtual Windows environment using commercially available programs such as Bootcamp or Parallels and install SAS in the Windows environment. You can also run SAS OnDemand for Academics on Windows, Mac, or Linux environment. (Refer to Appendix E in this book or search the web for “SAS OnDemand for Academics” for more information.

The examples in the book are designed to use data and sample programs in the folder C:\SASDATA – in other words, in a folder on your computer’s hard drive. You can also put the example files on any rewritable medium such as a flash drive or on a network drive – just remember to adjust the file names and file paths given in the examples in this book accordingly if you store your files in a location other than C:\SASDATA.

1.1.2 Beginning the SAS Program

Since there are multiple ways to use SAS, launching SAS may differ according to your installation and operating system. For a typical Windows environment, where there is a SAS icon (or tile) on your desktop, simply double‐click it to launch SAS. If the SAS icon is not on your desktop, go to the Start button and select Start → Programs → SAS (English) to launch SAS. Henceforth, we will refer to this simply as the SAS icon.

(We don’t recommend that you click on a .SAS file to launch SAS because it may not open SAS in the way you want. Doing so may open SAS in the Enhanced Editor, Enterprise Guide, or Universal Viewer. (It depends on how SAS was installed on your computer.) This book uses the SAS Windows Enhanced Editor as the primary interface for using SAS. Refer to SAS documentation for information about Enterprise Guide.

1.1.3 Understanding the SAS Windows Interface

Once you begin the SAS program, you will see a screen similar to that shown in Figure 1.1. (The SAS program appearance may be slightly different depending on which versions of Windows and SAS you’re using.)

The normal opening SAS screen is divided into three visible windows. The top right window is the Log Window, and at the bottom right is the Editor. The third window, which appears as a vertical element on the left, is called the SAS Explorer/Results window. There are other SAS windows that are not visible on the normal opening screen. These include the Graph and Results Viewer windows. To open a SAS window that is not currently visible, click its tab at the bottom of the screen. (The Output tab relates to a window that is not often used and we will not discuss it here.) The following is a brief description of the windows that are used in this text.

Editor:

Also called the

Enhanced Editor

or

Windows Programming Editor

(WPGM), this is the area where you write SAS code. It is like a simple word processor. When you open a previously saved SAS program, its contents will appear in this window. SAS code is stored in plain ASCII text, so files saved in the ASCII format from any other editor or word processor may be easily opened in this editor. You can also copy (or cut) text from another editor or word processor and paste it into the

Editor Window

.

Log:

When you run a SAS program, a report detailing how (and if) the program ran appears in the

Log Window

. Typically, when you run a SAS program, you first look at the contents of the

Log Window

to see if any errors in the program were reported. The

Log Window

highlights errors in red. You should also look for warnings and other notes in the

Log Window

, which tell you that some part of your program may not have run correctly.

Figure 1.1 Initial SAS screen.

(Source: Created with SAS® software, Version 9.4. Copyright 2022, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. Reproduced with permission of SAS Institute Inc., Cary, NC)

SAS Explorer/Results:

This window appears at the left of the screen and contains two tabs (shown at the bottom of the window): The

Results

tab displays a tree‐like listing of your output, making it easy to scroll quickly to any place in your output listing. The

Explorer Window

(which you can display by clicking the

Explorer tab

) displays the available SAS libraries where SAS data files are stored. A SAS library is a nickname for an actual physical location on disk, such as

C:\SASDATA

. This will be described in detail in

Chapter 3

.

Graph:

If your SAS program creates graphics output, SAS will display a

Graph Window tab

. Click that tab to view graphics results.

Results Viewer:

Beginning with SAS 9.3, the results of analysis appear in this viewer. It will appear the first time you run an analysis that creates output.

Do not close any of the windows that make up the SAS interface. Move from window to window by clicking on the tabs. If you close one of the windows, its tab at the bottom of the SAS screen will disappear and you will need to go to the View pull‐down menu and select the appropriate window name to redisplay the element that you closed. (Or restart the program.)

1.2 YOUR FIRST SAS ANALYSIS

Now that you’ve installed SAS and copied the SAS example data files to your computer, it’s time to jump in and perform a quick analysis to see how the program works. (You have downloaded the example files, haven’t you? If not, go back to Section 1.1.1 and do so.) Once you have downloaded the example files to your computer, continue with this chapter.

The following steps show you how to open a SAS program file, perform a simple analysis using the data in the file, and create statistical output.

Our first example is a quick overview of how SAS works. You should not be concerned if you don’t know much about the information in the SAS program file at this point. The remainder of the book teaches you how to create and run SAS programs.

HANDS‐ON EXAMPLE 1.1

In this example, you’ll run your first SAS analysis.

Launch SAS. SAS initially appears as shown in

Figure 1.1

. (If a tutorial or some other initial dialog box appears, dismiss it.)

Open a program file. This example uses a file named

FIRST.SAS.

To open this file, first make sure that your active window is the

Editor Window

. (Click anywhere in the

Editor Window

to make it the active window.) On the menu bar, select

File → Open Program

to open the file

C:\SASDATA\FIRST.SAS

. You may need to navigate to the

C:\SASDATA

folder to open this file.

Examine the opened file, the contents of which appear in the

Editor Window

. Maximize the

Editor Window

so that you can see more of the program code if necessary.

Figure 1.2

shows the

Editor Window

maximized. We’ll learn more in the latter chapters about what these lines of code mean.

Figure 1.2 The FIRST.SAS file opened

Run the SAS job. There are three ways to run (sometimes called submit) your SAS code. (1) On the menu bar, select

Run → Submit

, (2) click the “running man” icon on the toolbar, or (3) press F8. Perform any of these to run this code. The SAS instructions in the file are carried out (or, in computer terminology, the commands are

executed

). The SAS program creates an analysis output that automatically appears in the

Results Viewer

.

View the results shown in

Figure 1.3

.

The analysis requested in this SAS program is a task to calculate basic statistics (

PROC MEANS

) for each group (

GENDER

) in the data set.

Note the

Results Window

(as opposed to the

Results Viewer

) on the left of the screen illustrated in

Figure 1.3

– it contains a single item called

Means: The SAS System

(the full name is truncated in the image). As you perform more analyses in SAS, this list will grow. You can quickly display the results of any previous analysis by clicking the item in the list in this

Results Window

.

Figure 1.3 Results for FIRST.SAS

Print the output. Make sure the

Results Viewer

is active by clicking anywhere in the

Results Viewer

. Print the contents of the viewer by clicking the printer icon on the toolbar or by selecting

File → Print

on the menu bar.

Save the output. To save the results shown in the

Results Viewer

, select

File → Save As

on the menu bar and enter an appropriate name for the output file, such as

FIRST OUTPUT

. The file will be saved as

FIRST OUTPUT.MHT.

(The .MHT extension refers to a single file web page file and is automatically added to the file name. If you subsequently open this file, it will open into your default web browser.)

Save the SAS program code (instruction file) that created the output by first going to the

Editor Window

that contains the

FIRST.SAS

program code. With the program on the screen, select

File → Save As

and enter a name such as

MYFIRST

. Make sure you are saving the code in the

C:\SASDATA

folder. This saves the file as

MYFIRST.SAS.

(The .SAS extension is automatically added to the file name.)

Examine the SAS

Log Window

. Click on the

Log Window

tab at the bottom of your screen and note that it contains a report on the SAS program code you just ran. It will include statements such as the following:

NOTE: Writing HTML Body file: sashtml.htm

NOTE: There were 18 observations read from the data set

WORK.EMPLOYEES.

    This indicates that the output is in an html format (web file format) and that the data set contained 18 records.

Clear the contents of the

Log Window

by right‐clicking and selecting

Edit → Clear All

from the pop‐up menu. In the

Editor Window

, right‐click and select

Clear All

. (We’ll learn a shortcut to this process later in this chapter.)

The Save As command saves the contents of the window that is currently active. Thus, if the Results Viewer is active, it saves the output as an *.MHT file; if the Log Window is active, it saves the contents of that window as an *.LOG file; and if the Editor Window is the active window, it saves the code as an *.SAS (SAS program code) file.

That’s it! You’ve run your first SAS program. But wait, there’s more. Now that you have one SAS job under your belt, it’s time to try another one. This time, you’ll make a small change to the program before you run it.

Before running each Hands‐On Example, clear the Log and Editor Windows so that you will not mix up information from a previous example. To clear each window, use the right‐click technique previously described, or go to the window and on the menu bar select Edit → Clear All. In Section 1.4.2, we will show a way to shorten this process.

HANDS‐ON EXAMPLE 1.2

In this example, you make a small change in the program and see how that change alters the output.

In the SAS

Editor Window

, open the program file

SECOND.SAS

. (It should be in your

C:\SASDATA

folder.) The SAS code looks like this:

* PUT YOUR TITLE ON THE NEXT LINE;

DATA EXAMPLE;

INPUT AGE @@;

DATALINES;

12 11 12 12 9 11 8 8 7 11 12 14 9 10 7 13

6 11 12 4 11 9 13 6 9 7 13 9 13 12 10 13

11 8 11 15 12 14 10 10 13 13 10 8 12 7 13

11 9 12

;

PROC MEANS DATA=EXAMPLE;

VAR AGE;

RUN;

Run the SAS job using any of the methods described in the previous example and observe the output. Note that the title at the top of the output page is “The SAS System.”

Under the comment line that reads

* PUT YOUR TITLE ON THE NEXT LINE;

type this new line:

TITLE “HELLO WORLD, MY NAME IS

your name

.”;

Enter your own name instead of your name. Make sure you include the quotation marks and end the statement with a semicolon (;).

Run the SAS program, examine the output, and note how the title has changed in the output.

1.3 HOW SAS WORKS

Look at the SECOND.SAS program file to see how SAS works. It is really very simple. The lines in the file are like the items on a grocery list or a “to do” list. You create a list of things you want SAS to do and when you submit the job, SAS does its best to carry out your instructions. The basic steps are as follows:

Define a data set in SAS using the

DATA

step (which begins with the keyword

DATA

.) In this case, the data values are a part of the code (although it is not always the case.) The data values to be used in this analysis follow the keyword

DATALINES

.

Once you have a data set of values, you can tell SAS what analysis to perform using a procedure (

PROC

) statement. In this case, the keywords

PROC MEANS

initiate the “MEANS” procedure.

Run the program and observe the output (in the

Results Viewer

).

Figure 1.4 illustrates this process.

This book teaches you how to create and use SAS by illustrating SAS techniques of data handling and analysis through a number of sample SAS programs.

To exit the SAS program, select File → Exit on the menu bar. Make sure you’ve saved all files you wish to save before ending the program. (The program will prompt you to save files if you have not previously done so.)

Figure 1.4 How SAS works

1.4 TIPS AND TRICKS FOR RUNNING SAS PROGRAMS

This section contains tips and tricks that can help you if something in your program goes wrong. Now that you have seen two sample SAS jobs, you should have an idea of how SAS programs are constructed. This section provides general rules for writing SAS programs.

Within a SAS program, each statement begins with an identifying keyword ( DATA, PROC, INPUT, DATALINES, RUN, etc.) and ends with a semicolon (;). For example:

DATA TEMP;

PROC PRINT DATA=TEMP;

SAS statements are free‐format – they do not have to begin in any particular column. Thus,

Statements can begin anywhere and end anywhere

. One statement can continue over several lines with a semicolon at the end of the last line signaling the end of the statement.

Several statements may be on the same line

, with each statement terminated with a semicolon.

Blanks

, as many as you want but at least one, may be used to separate the components (words) in a SAS program statement.

Case (lower‐ and upper‐)

doesn’t

matter in most SAS statements.

Case

does matter

in data and quoted information.

When you enter character data values (such as

M

or

m

for “male”), case will matter when you are sorting or selecting the data. Moreover, the contents of a title or footnote are placed in quotation marks and are printed in the output using the uppercase and lowercase characters you specify in the program code.

The most common error in SAS programming is a misplaced (or missing) semicolon.

Pay careful attention to the semicolons at the end of the statements; they tell SAS that the statement is completed.

A second common error is a missing RUN statement

. You

must

end every program with a

RUN

statement (in the Windows version of SAS). If you do not end the program with a

RUN

statement, your program may not terminate normally, and your last statement may not be completed. (For some procedures, you should also end with the

QUIT;

statement. Those will be discussed when they are mentioned in the text.)

A third common error in a SAS program is the presence of unmatched quotation marks

. If you enter a title without matching quotation marks, you will see an error message in your

Log File

such as “The TITLE statement is ambiguous due to … unquoted text.” This error can cause subsequent statements in your code to be misinterpreted by SAS.

A search for errors in a program Log Window should be from the top down.

It is inevitable that you will write programs that contain errors in syntax. When you get lots of errors in a SAS run, always fix the errors from the top down in your program code, because often the early errors lead to confusion that results in the latter errors.

If program errors cause problems that result in SAS’s “freezing up” or not completing the steps in your program,

you can abort SAS’s processes by pressing Ctrl‐Break and selecting the “Cancel Submitted Statements” option from the dialog box that appears.

If you cannot resolve a problem within SAS

,

save your files

, restart SAS, and reopen the files. Try to find the code that caused the problem, and then re‐run your program.

The structure of your SAS programs should be easy to read.

Note how the example programs in this book are structured – how some statements are indented for easy reading and how the code contains comments. (Lines that begin with an asterisk (*) are comments that are ignored when the program is run. Comments are discussed more in

Chapter 5

.)

Now that you have experience running simple programs in SAS, you will want to know more about the syntax and conventions for entering and running a SAS program. The following is a brief introduction to some of the SAS program requirements you need to know.

1.4.1 Using the SAS Enhanced Editor

You may have noted that different parts of the coding in FIRST.SAS or SECOND.SAS appear in various colors and in bold font. The color coding is designed to help you clearly see step boundaries (major SAS commands), keywords, column and table names, and constants. For example, in the SAS Enhanced Editor:

Green

is used for comments.

Bold Dark Blue

is used for the keyword in major SAS commands.

Blue

is used for keywords that have special meaning as SAS commands.

A yellow background

is used to highlight data.

A boundary line

separates each step.