Contents

List of Programs

Preface

About This Book

About the Author

Acknowledgments

Part 1: Getting Started

Chapter 1: What Is SAS?

1.1      Introduction

1.2      Getting Data into SAS

1.3      A Sample SAS Program

1.4      SAS Names

1.5      SAS Data Sets and SAS Data Types

1.6      The SAS Windowing Environment, SAS Enterprise Guide, and the SAS University Edition

1.7      Problems

Chapter 2: Writing Your First SAS Program

2.1      A Simple Program to Read Raw Data and Produce a Report

2.2      Enhancing the Program

2.3      More on Comment Statements

2.4      How SAS Works (a Look inside the “Black Box”)

2.5      Problems

Part 2: DATA Step Processing

Chapter 3: Reading Raw Data from External Files

3.1      Introduction

3.2      Reading Data Values Separated by Blanks

3.3      Specifying Missing Values with List Input

3.4      Reading Data Values Separated by Commas (CSV Files)

3.5      Using an alternative Method to Specify an External File

3.6      Reading Data Values Separated by Delimiters Other Than Blanks or Commas

3.7      Placing Data Lines Directly in Your Program (the DATALINES Statement)

3.8      Specifying INFILE Options with the DATALINES Statement

3.9      Reading Raw Data from Fixed Columns—Method 1: Column Input

3.10    Reading Raw Data from Fixed Columns—Method 2: Formatted Input

3.11    Using a FORMAT Statement in a DATA Step versus in a Procedure

3.12    Using Informats with List Input

3.13    Supplying an INFORMAT Statement with List Input

3.14    Using List Input with Embedded Delimiters

3.15    Problems

Chapter 4: Creating Permanent SAS Data Sets

4.1      Introduction

4.2      SAS Libraries—The LIBNAME Statement

4.3      Why Create Permanent SAS Data Sets?

4.4      Examining the Descriptor Portion of a SAS Data Set Using PROC CONTENTS

4.5      Listing All the SAS Data Sets in a SAS Library Using PROC CONTENTS

4.6      Viewing the Descriptor Portion of a SAS Data Set Using a Point-and-Click Approach

4.7      Viewing the Data Portion of a SAS Data Set Using PROC PRINT

4.8      Using a SAS Data Set as Input to a DATA Step

4.9      DATA _NULL_: A Data Set That Isn’t

4.10    Problems

Chapter 5: Creating Labels and Formats

5.1      Adding Labels to Your Variables

5.2      Using Formats to Enhance Your Output

5.3      Regrouping Values Using Formats

5.4      More on Format Ranges

5.5      Storing Your Formats in a Format Library

5.6      Permanent Data Set Attributes

5.7      Accessing a Permanent SAS Data Set with User-Defined Formats

5.8      Displaying Your Format Definitions

5.9      Problems

Chapter 6: Reading and Writing Data from an Excel Spreadsheet

6.1      Introduction

6.2      Using the Import Wizard to Convert a Spreadsheet to a SAS Data Set

6.3      Creating an Excel Spreadsheet from a SAS Data Set

6.4      Using an Engine to Read an Excel Spreadsheet

6.5      Using the SAS Output Delivery System to Convert a SAS Data Set to an Excel Spreadsheet

6.6      A Quick Look at the Import Utility in SAS Studio

6.7      Problems

Chapter 7: Performing Conditional Processing

7.1      Introduction

7.2      The IF and ELSE IF Statements

7.3      The Subsetting IF Statement

7.4      The IN Operator

7.5      Using a SELECT Statement for Logical Tests

7.6      Using Boolean Logic (AND, OR, and NOT Operators)

7.7      A Caution When Using Multiple OR Operators

7.8      The WHERE Statement

7.9      Some Useful WHERE Operators

7.10    Problems

Chapter 8: Performing Iterative Processing: Looping

8.1      Introduction

8.2      DO Groups

8.3      The Sum Statement

8.4      The Iterative DO Loop

8.5      Other Forms of an Iterative DO Loop

8.6      DO WHILE and DO UNTIL Statements

8.7      A Caution When Using DO UNTIL Statements

8.8      LEAVE and CONTINUE Statements

8.9      Problems

Chapter 9: Working with Dates

9.1      Introduction

9.2      How SAS Stores Dates

9.3      Reading Date Values from Text Data

9.4      Computing the Number of Years between Two Dates

9.5      Demonstrating a Date Constant

9.6      Computing the Current Date

9.7      Extracting the Day of the Week, Day of the Month, Month, and Year from a SAS Date

9.8      Creating a SAS Date from Month, Day, and Year Values

9.9      Substituting the 15th of the Month when the Day Value Is Missing

9.10    Using Date Interval Functions

9.11    Problems

Chapter 10: Subsetting and Combining SAS Data Sets

10.1    Introduction

10.2    Subsetting a SAS Data Set

10.3    Creating More Than One Subset Data Set in One DATA Step

10.4    Adding Observations to a SAS Data Set

10.5    Interleaving Data Sets

10.6    Combining Detail and Summary Data

10.7    Merging Two Data Sets

10.8    Omitting the BY Statement in a Merge

10.9    Controlling Observations in a Merged Data Set

10.10   More Uses for IN= Variables

10.11   When Does a DATA Step End?

10.12   Merging Two Data Sets with Different BY Variable Names

10.13   Merging Two Data Sets with Different BY Variable Data Types

10.14   One-to-One, One-to-Many, and Many-to-Many Merges

10.15   Updating a Master File from a Transaction File

10.16   Problems

Chapter 11: Working with Numeric Functions

11.1    Introduction

11.2    Functions That Round and Truncate Numeric Values

11.3    Functions That Work with Missing Values

11.4    Setting Character and Numeric Values to Missing

11.5    Descriptive Statistics Functions

11.6    Computing Sums within an Observation

11.7    Mathematical Functions

11.8    Computing Some Useful Constants

11.9    Generating Random Numbers

11.10   Special Functions

11.11   Functions That Return Values from Previous Observations

11.12   Sorting Within an Observations—a Game Changer

11.13   Problems

Chapter 12: Working with Character Functions

12.1    Introduction

12.2    Determining the Length of a Character Value

12.3    Changing the Case of Characters

12.4    Removing Characters from Strings

12.5    Joining Two or More Strings Together

12.6    Removing Leading or Trailing Blanks

12.7    Using the COMPRESS Function to Remove Characters from a String

12.8    Searching for Characters

12.9    Searching for Individual Characters

12.10   Searching for Words in a String

12.11   Searching for Character Classes

12.12   Using the NOT Functions for Data Cleaning

12.13   Extracting Part of a String

12.14   Dividing Strings into Words

12.15   Performing a Fuzzy Match

12.16   Substituting Strings or Words

12.17   Problems

Chapter 13: Working with Arrays

13.1    Introduction

13.2    Setting Values of 999 to a SAS Missing Value for Several Numeric Variables

13.3    Setting Values of NA and ? to a Missing Character Value

13.4    Converting All Character Values to Propercase

13.5    Using an Array to Create New Variables

13.6    Changing the Array Bounds

13.7    Temporary Arrays

13.8    Loading the Initial Values of a Temporary Array from a Raw Data File

13.9    Using a Multidimensional Array for Table Lookup

13.10   Problems

Part 3: Presenting and Summarizing Your Data

Chapter 14: Displaying Your Data

14.1    Introduction

14.2    The Basics

14.3    Changing the Appearance of Your Listing

14.4    Changing the Appearance of Values

14.5    Controlling the Observations That Appear in Your Listing

14.6    Adding Titles and Footnotes to Your Listing

14.7    Changing the Order of Your Listing

14.8    Sorting by More Than One Variable

14.9    Labeling Your Column Headings

14.10   Adding Subtotals and Totals to Your Listing

14.11   Making Your Listing Easier to Read

14.12   Adding the Number of Observations to Your Listing

14.13   Listing the First n Observations of Your Data Set

14.14   Problems

Chapter 15: Creating Customized Reports

15.1    Introduction

15.2    Using PROC REPORT

15.3    Selecting the Variables to Include in Your Report

15.4    Comparing Detail and Summary Reports

15.5    Producing a Summary Report

15.6    Demonstrating the FLOW Option of PROC REPORT

15.7    Using Two Grouping Variables

15.8    Changing the Order of Variables in the COLUMN Statement

15.9    Changing the Order of Rows in a Report

15.10   Applying the ORDER Usage to Two Variables

15.11   Creating a Multi-Column Report

15.12   Producing Report Breaks

15.13   Using a Nonprinting Variable to Order a Report

15.14   Computing a New Variable with PROC REPORT

15.15   Computing a Character Variable in a COMPUTE Block

15.16   Creating an ACROSS Variable with PROC REPORT

15.17   Using an ACROSS Usage to Display Statistics

15.18   Problems

Chapter 16: Summarizing Your Data

16.1    Introduction

16.2    PROC MEANS—Starting from the Beginning

16.3    Adding a BY Statement to PROC MEANS

16.4    Using a CLASS Statement with PROC MEANS

16.5    Applying a Format to a CLASS Variable

16.6    Deciding between a BY Statement and a CLASS Statement

16.7    Creating Summary Data Sets Using PROC MEANS

16.8    Outputting Other Descriptive Statistics with PROC MEANS

16.9    Asking SAS to Name the Variables in the Output Data Set

16.10   Outputting a Summary Data Set: Including a BY Statement

16.11   Outputting a Summary Data Set: Using a CLASS Statement

16.12   Using Two CLASS Variables with PROC MEANS

16.13   Selecting Different Statistics for Each Variable

16.14   Printing all Possible Combinations of Your Class Variables

16.15   Problems

Chapter 17: Counting Frequencies

17.1    Introduction

17.2    Counting Frequencies

17.3    Selecting Variables for PROC FREQ

17.4    Using Formats to Label the Output

17.5    Using Formats to Group Values

17.6    Problems Grouping Values with PROC FREQ

17.7    Displaying Missing Values in the Frequency Table

17.8    Changing the Order of Values in PROC FREQ

17.9    Producing Two-Way Tables

17.10   Requesting Multiple Two-Way Tables

17.11   Producing Three-Way Tables

17.12   Problems

Chapter 18: Creating Tabular Reports

18.1    Introduction

18.2    A Simple PROC TABULATE Table

18.3    Describing the Three PROC TABULATE Operators

18.4    Using the Keyword ALL

18.5    Producing Descriptive Statistics

18.6    Combining CLASS and Analysis Variables in a Table

18.7    Customizing Your Table

18.8    Demonstrating a More Complex Table

18.9    Computing Row and Column Percentages

18.10   Displaying Percentages in a Two-Dimensional Table

18.11   Computing Column Percentages

18.12   Computing Percentages on Numeric Variables

18.13   Understanding How Missing Values Affect PROC TABULATE Output

18.14   Problems

Chapter 19: Introducing the Output Delivery System

19.1    Introduction

19.2    Sending SAS Output to an HTML File

19.3    Creating a Table of Contents

19.4    Selecting a Different HTML Style

19.5    Choosing Other ODS Destinations

19.6    Selecting or Excluding Portions of SAS Output

19.7    Sending Output to a SAS Data Set

19.8    Problems

Chapter 20: Creating Charts and Graphs

20.1    Introduction

20.2     Creating Bar Charts

20.3     Displaying Statistics for a Response Variable

20.4     Creating Scatter Plots

20.5     Adding a Regression Line and Confidence Limits to the Plot

20.6     Generating Time Series Plots

20.7     Describing Two Methods of Generating Smooth Curves

20.8     Generating Histograms

20.9     Generating a Simple Box Plot

20.10   Producing a Box Plot with a Grouping Variable

20.11   Demonstrating Overlays and Transparency

20.12   Problems

Part 4: Advanced Topics

Chapter 21: Using Advanced INPUT Techniques

21.1    Introduction

21.2    Handling Missing Values at the End of a Line

21.3    Reading Short Data Lines

21.4    Reading External Files with Lines Longer Than 32,767 Characters

21.5    Detecting the End of the File

21.6    Reading a Portion of a Raw Data File

21.7    Reading Data from Multiple Files

21.8    Reading Data from Multiple Files Using a FILENAME Statement

21.9    Reading External Filenames from a Data File

21.10   Reading Multiple Lines of Data to Create One Observation

21.11   Reading Data Conditionally (the Single Trailing @ Sign)

21.12   More Examples of the Single Trailing @ Sign

21.13   Creating Multiple Observations from One Line of Input

21.14   Using Variable and Informat Lists

21.15   Using Relative Column Pointers to Read a Complex Data Structure Efficiently

21.16   Problems

Chapter 22: Using Advanced Features of User-Defined Formats and Informats

22.1    Introduction

22.2    Using Formats to Recode Variables

22.3    Using Formats with a PUT Function to Create New Variables

22.4    Creating User-Defined Informats

22.5    Reading Character and Numeric Data in One Step

22.6    Using Formats (and Informats) to Perform Table Lookup

22.7    Using a SAS Data Set to Create a Format

22.8    Updating and Maintaining Your Formats

22.9    Using Formats within Formats

22.10   Multilabel Formats

22.11   Using the INPUTN Function to Perform a More Complicated Table Lookup

22.12   Problems

Chapter 23: Restructuring SAS Data Sets

23.1    Introduction

23.2    Converting a Data Set with One Observation per Subject to a Data Set with Several Observations per Subject: Using a DATA Step

23.3    Converting a Data Set with Several Observations per Subject to a Data Set with One Observation per Subject: Using a DATA Step

23.4    Converting a Data Set with One Observation per Subject to a Data Set with Several Observations per Subject: Using PROC TRANSPOSE

23.5    Converting a Data Set with Several Observations per Subject to a Data Set with One Observation per Subject: Using PROC TRANSPOSE

23.6    Problems

Chapter 24: Working with Multiple Observations per Subject

24.1    Introduction

24.2    Identifying the First or Last Observation in a Group

24.3    Counting the Number of Visits Using PROC FREQ

24.4    Computing Differences between Observations

24.5    Computing Differences between the First and Last Observation in a BY Group Using the LAG Function

24.6    Computing Differences between the First and Last Observation in a BY Group Using a RETAIN Statement

24.7    Using a Retained Variable to “Remember” a Previous Value

24.8    Problems

Chapter 25: Introducing the SAS Macro Language

25.1    Introduction

25.2    Macro Variables: What Are They?

25.3    Some Built-In Macro Variables

25.4    Assigning Values to Macro Variables with a %LET Statement

25.5    Demonstrating a Simple Macro

25.6    Describing Positional and Keyword Macro Parameters

25.7    A Word about Tokens

25.8    Another Example of Using a Macro Variable as a Prefix

25.9    Using a Macro Variable to Transfer a Value between DATA Steps

25.10   Problems

Chapter 26: Introducing the Structured Query Language

26.1    Introduction

26.2    Some Basics

26.3    Joining Two Tables (Merge)

26.4    Left, Right, and Full Joins

26.5    Concatenating Data Sets

26.6    Using Summary Functions

26.7    Demonstrating the ORDER Clause

26.8    An Example of Fuzzy Matching

26.9    Problems

Chapter 27: Introducing Perl Regular Expressions

27.1    Introduction

27.2     Describing the Syntax of Regular Expressions

27.3     Testing That Social Security Numbers Are in Standard Form

27.4     Checking for Valid ZIP Codes

27.5     Verifying That Phone Numbers Are in a Standard Form

27.6     Describing the PRXPARSE Function

27.7    Problems

Solutions to Odd-Numbered Exercises

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset