List of Programs
Program 1.1: A Sample SAS Program
Program 1.2: An Alternative Version of Program 1.1
Program 2.1: Your First SAS Program
Program 2. 2: Enhancing the Program
Program 3.1: Demonstrating List Input with Blanks as Delimiters
Program 3.2: Reading Data From a Comma-Separated Values (Csv) File
Program 3.3: Using a Filename Statement to Identify an External File
Program 3.4: Demonstrating the DATALINES Statement
Program 3.5: Using INFILE Options with DATALINES
Program 3.6: Demonstrating Column Input
Program 3.7: Demonstrating Formatted Input
Program 3.8: Demonstrating a FORMAT Statement
Program 3.9: Rerunning Program 3.8 with a Different Format
Program 3.10: Using Informats with List Input
Program 3.11: Supplying an INFORMAT Statement with List Input
Program 3.12: Demonstrating the Ampersand Modifier for List Input
Program 4.1: Creating a Permanent SAS Data Set
Program 4.2: Using PROC CONTENTS to Examine the Descriptor Portion of a SAS Data Set
Program 4.3: Demonstrating the VARNUM option of PROC CONTENTS
Program 4.4: Using a LIBNAME in a New SAS Session
Program 4.5: Using PROC CONTENTS to List the Names of all the SAS Data Sets in a SAS Library
Program 4.6: Using PROC PRINT to List the Data Portion of a SAS Data Set
Program 4.7: Using Observations from a SAS Data Set as Input to a New SAS Data Set
Program 4.8: Demonstrating a DATA _NULL_ Step
Program 5.1: Adding Labels to Variables in a SAS Data Set
Program 5.2: Using PROC FORMAT to Create User-Defined Formats
Program 5.3: Adding a FORMAT Statement in PROC PRINT
Program 5.4: Regrouping Values Using a Format
Program 5.5: Applying the New Format to Several Variables with PROC FREQ
Program 5.6: Creating a Permanent Format Library
Program 5.7: Adding LABEL and FORMAT Statements in the DATA Step
Program 5.8: Running PROC CONTENTS on a Data Set with Labels and Formats
Program 5.9: Using a User-defined Format
Program 5.10: Displaying Format Definitions in a User-created Library
Program 5.11: Demonstrating a SELECT Statement with PROC FORMAT
Program 6.1: Using PROC PRINT to List the First Four Observations in a Data Set
Program 6.2: Using the FIRSTOBS= and OBS= Options Together
Program 6.3: Reading a Spreadsheet Using an XLSX Engine
Program 6.4: Using ODS to Convert a SAS Data Set into a CSV File (to Be Read by Excel)
Program 7.1: First Attempt to Group Ages into Age Groups (Incorrect)
Program 7.2: Corrected Program to Group Ages into Age Groups
Program 7.3: An Alternative to Program 7.2
Program 7.4: Demonstrating a Subsetting IF statement
Program 7.5: Demonstrating a SELECT Statement When a Select-Expression is Missing
Program 7.6: Combining Various Boolean Operators
Program 7.7: A Caution on the Use of Multiple OR Operators
Program 7.8: Using a WHERE Statement to Subset a SAS Data Set
Program 8.1: Example of a Program That Does Not Use a DO Group
Program 8.2: Demonstrating a DO Group
Program 8.3: Attempt to Create a Cumulative Total (First Attempt)
Program 8.4: Creating a Cumulative Total with the RETAIN Statement (Second Attempt)
Program 8.5: Creating a Cumulative Total with RETAIN and IF Statements (Third Attempt)
Program 8.6: Using a SUM Statement to Create a Cumulative Total
Program 8.7: Using a SUM Statement to Create a Counter
Program 8.8: Program Without Iterative Loops
Program 8.9: Demonstrating an Iterative DO Loop
Program 8.10: Using an Iterative DO Loop to Make a Table of Squares and Square Roots
Program 8.11: Using an Iterative DO Loop to Graph an Equation
Program 8.12: Using Character Values for DO Loop Index Values
Program 8.13: Demonstrating a DO UNTIL Loop
Program 8.14: Demonstrating That a DO UNTIL Loop Always Executes at Least Once
Program 8.15: Demonstrating a DO WHILE Statement
Program 8.16: Demonstrating That DO WHILE Loops Are Evaluated at The Top
Program 8.17: Combining a DO UNTIL and Iterative DO Loop
Program 8.18: Demonstrating the LEAVE Statement
Program 8.19: Demonstrating a CONTINUE Statement
Program 9.1: Program to Read Dates from Text Data
Program 9.2: Adding a FORMAT Statement to Format Each of the Date Values
Program 9.3: Compute a Person's Age in Years
Program 9.4: Demonstrating a Date Constant
Program 9.5: Using the TODAY Function to Return the Current Date
Program 9.6: Extracting the Day of the Week, Day of the Month, Month, and Year from a SAS Date
Program 9.7: Using the MDY Function to Create a SAS Date from Month, Day, and Year
Program 9.8: Substituting the 15th of the Month When a Day Value is Missing
Program 9.9: Demonstrating the INTCK Function
Program 9.10: Using the INTNX Function to Compute Dates 6 Months After Discharge
Program 9.11: Demonstrating the SAMEDAY Alignment with the INTNX Function
Program 10.1: Subsetting a SAS Data Set Using a WHERE Statement
Program 10.2: Demonstrating a KEEP= Data Set Option
Program 10.3: Creating Two Data sets in One DATA Step 139
Program 10.4: Using a SET Statement to Combine Observations from Two Data Sets
Program 10.5: Using a SET Statement on Two Data Sets Containing Different Variables
Program 10.6: Interleaving Data Sets
Program 10.7: Combining Detail and Summary Data:Using a Conditional SET Statement
Program 10.8: Merging Two SAS Data Sets
Program 10.9: Demonstrating the IN= Data Set Option
Program 10.10: Using IN= Variables to Select IDs That Are In Both Data Sets
Program 10.11: More Examples of Using IN= Variables
Program 10.12: Demonstrating When a DATA Step Ends
Program 10.13: Merging Two Data Sets by Renaming a Variable in One Data Set
Program 10.14: Merging Two Data Sets When the BY Variables Are Different Data Types
Program 10.15: An Alternative to Program 10.14
Program 10.16: Updating a Master File From a Transaction File
Program 11.1: Demonstrating the ROUND and INT Truncation Functions
Program 11.2: Testing for Missing Numeric and Character Values (without the MISSING Function)
Program 11.3: Demonstrating the MISSING Function
Program 11.4: Demonstrating the N, MEAN, MIN, and MAX Functions
Program 11.5: Finding the Sum of the Three Largest Values in a List of Variables
Program 11.6: Using the SUM Function to Compute Totals
Program 11.7: Demonstrating the ABS, SQRT, EXP, and LOG Functions
Program 11.8: Computing Some Useful Constants with the CONSTANT Function
Program 11.9: Program to Generate Five Uniform Random Numbers
Program 11.10: Including a Call to Streaminit
Program 11.11: Using the RAND function to randomly select observations
Program 11.12: Using PROC SURVEYSELECT to Obtain a Random Sample
Program 11.13: Using the INPUT Function to Perform a Character-to-Numeric Conversion
Program 11.14: Demonstrating the PUT Function
Program 11.15: Demonstrating the LAG and LAGn Functions
Program 11.16: Demonstrating What Happens When You Execute a LAG Function Conditionally
Program 11.17: Using the LAG Function to Compute Inter-observation Differences
Program 11.18: Demonstrating the DIF Function
Program 11.19: Solving the Quiz Problem the Hard Way
Program 11.20: Repeating Program 11.19 Using the CALL SORTN Routine
Program 12.1: Determining the Length of a Character Value
Program 12.2: Changing Values to Uppercase
Program 12.3: Converting Multiple Blanks to a Single Blank and Demonstrating the PROPCASE Function
Program 12.4: Demonstrating the Concatenation Functions
Program 12.5: Demonstrating the TRIMN, LEFT, and STRIP Functions
Program 12.6: Using the COMPRESS Function to Remove Characters from a String
Program 12.7: Demonstrating the COMPRESS Modifiers
Program 12.8: Demonstrating the COMPRESS and FIND Functions
Program 12.9: Demonstrating the FINDW Function
Program 12.10: Demonstrating the ANYDIGIT Function
Program 12.11: Demonstrating the NOT Functions for Data Cleaning
Program 12.12: Using the SUBSTR Function to Extract Substrings
Program 12.13: Demonstrating the SCAN Function
Program 12.14: Using the SCAN Function to Extract the Last Name
Program 12.15: Using the SPEDIS Function to Perform a Fuzzy Match
Program 12.16: Demonstrating the TRANSLATE function
Program 12.17: Using the TRANWRD Function to Standardize an Address
Program 13.1: Converting Values of 999 to a SAS Missing Value—Without Using Arrays
Program 13.2: Converting Values of 999 to a SAS Missing Value—Using Arrays
Program 13.3: Converting Values of NA and ? to a Missing Character Value
Program 13.4: Converting All Character Values in a SAS Data Set to Propercase
Program 13.5: Using an Array to Create New Variables
Program 13.6: Changing the Array Bounds
Program 13.7: Using a Temporary Array to Score a Test
Program 13.8: Loading the Initial Values of a Temporary Array from a Raw Data File
Program 13.9: Loading a Two-Dimensional, Temporary Array with Data Values
Program 14.1: PROC PRINT Using All the Defaults
Program 14.2: Controlling Which Variables Appear in the Listing
Program 14.3: Using an ID Statement to Omit the Obs Column
Program 14.4: Adding a FORMAT Statement to PROC PRINT
Program 14.5: Controlling Which Observations Appear in the Listing (WHERE Statement)
Program 14.6: Using the IN Operator in a WHERE Statement
Program 14.7: Adding Titles and Footnotes to Your Listing
Program 14.8: Using PROC SORT to Change the Order of Your Observations
Program 14.9: Demonstrating the DESCENDING Option of PROC SORT
Program 14.10: Sorting the Permanent Data Set and Creating a Temporary Output Data Set
Program 14.11: Sorting by More than One Variable
Program 14.12: Using Labels as Column Headings with PROC PRINT
Program 14.13: Using a BY Statement in PROC PRINT
Program 14.14: Adding Totals and Subtotals to Your Listing
Program 14.15: Using an ID Statement and a BY Statement in PROC PRINT
Program 14.16: Demonstrating the N= Option with PROC PRINT
Program 14.17: Listing the First Five Observations of Your Data Set
Program 15.1: Listing of Medical Using PROC PRINT
Program 15.2: Using PROC REPORT (All Defaults)
Program 15.3: Adding a COLUMN Statement to PROC REPORT
Program 15.4: Using PROC REPORT with Only Numeric Variables
Program 15.5: Using DEFINE Statements to Define a Display Usage
Program 15.6: Specifying a GROUP Usage to Create a Summary Report
Program 15.7: Demonstrating the FLOW Option with PROC REPORT
Program 15.8: Explicitly Defining Usage for Every Variable
Program 15.9: Demonstrating the Effect of Two Variables with GROUP Usage
Program 15.10: Reversing the Order of Variables in the COLUMN Statement
Program 15.11: Demonstrating the ORDER Usage of PROC REPORT
Program 15.12: Applying the ORDER Usage for Two Variables
Program 15.13: Creating a Multi-column Report
Program 15.14: Requesting a Report Break (RBREAK Statement)
Program 15.15: Demonstrating the BREAK Statement of PROC REPORT
Program 15.16: Using a Nonprinting Variable to Order the Rows of a Report
Program 15.17: Computing a New Variable with PROC REPORT
Program 15.18: Computing a Character Variable in a COMPUTE Block
Program 15.19: Demonstrating an ACROSS Usage in PROC REPORT
Program 15.20: Using ACROSS Usage to Display Statistics
Program 16.1: PROC MEANS with All the Defaults
Program 16.2: Adding a VAR Statement and Requesting Specific Statistics with PROC MEANS
Program 16.3: Adding a BY Statement to PROC MEANS
Program 16.4: Using a CLASS Statement with PROC MEANS
Program 16.5: Demonstrating the Effect of a Formatted CLASS Variable
Program 16.6: Creating a Summary Data Set Using PROC MEANS
Program 16.7: Outputting More Than One Statistic with PROC MEANS
Program 16.8: Demonstrating the OUTPUT Option AUTONAME
Program 16.9: Adding a BY Statement to PROC MEANS
Program 16.10: Adding a CLASS Statement to PROC MEANS
Program 16.11: Adding the NWAY Option to PROC MEANS
Program 16.12: Using Two CLASS Variables with PROC MEANS
Program 16.13: Adding the CHARTYPE Procedure Option to PROC MEANS
Program 16.14: Using the _TYPE_ Variable to Select Cell Means
Program 16.15: Using a DATA Step to Create Separate Summary Data Sets
Program 16.16: Selecting Different Statistics for Each Variable Using PROC MEANS
Program 17.1: Counting Frequencies:One-Way Tables Using PROC FREQ
Program 17.2: Adding a TABLES Statement to PROC FREQ
Program 17.3: Adding Formats to Program 17.2
Program 17.4: Using Formats to Group Values
Program 17.5: Demonstrating a Problem in How PROC FREQ Groups Values
Program 17.6: Fixing the Grouping Problem
Program 17.7: Demonstrating the Effect of the MISSING Option of PROC FREQ
Program 17.8: Demonstrating the ORDER= Option of PROC FREQ
Program 17.9: Demonstrating the ORDER= Formatted, Data, and Freq Options
Program 17.10: Requesting a Two-Way Table
Program 17.11: Requesting a Three-Way Table with PROC FREQ
Program 18.1: PROC TABULATE with All the Defaults and a Single CLASS Variable
Program 18.2: Demonstrating Concatenation with PROC TABULATE
Program 18.3: Demonstrating Table Dimensions with PROC TABULATE
Program 18.4: Demonstrating the Nesting Operator with PROC TABULATE
Program 18.5: Adding the Keyword ALL to Your Table Request
Program 18.6: Using PROC TABULATE to Produce Descriptive Statistics
Program 18.7: Specifying Statistics on an Analysis Variable with PROC TABULATE
Program 18.8: Specifying More than One Descriptive Statistic with PROC TABULATE
Program 18.9: Combining CLASS and Analysis Variables in a Table
Program 18.10: Associating a Different Format with Each Variable in a Table
Program 18.11: Renaming Keywords with PROC TABULATE
Program 18.12: Eliminating the N Column in a PROC TABULATE Table
Program 18.13: Demonstrating a More Complex Table
Program 18.14: Computing Percentages in a One-Dimensional Table
Program 18.15: Improving the Appearance of the Output from Program 18.14
Program 18.16: Counts and Percentages in a Two-Dimensional Table
Program 18.17: Using COLPCTN to Compute Column Percentages
Program 18.18: Computing Percentages on a Numeric Value
Program 18.19: Demonstrating the Effect of Missing Values on CLASS Variables
Program 18.20: Missing Values on a CLASS Variable That Is Not Used in the Table
Program 18.21: Adding the PROC TABULATE Procedure Option MISSING
Program 18.22: Demonstrating the MISSTEXT= TABLES Option
Program 19.1: Sending SAS Output to an HTML File
Program 19.2: Creating a Table of Contents for HTML Output
Program 19.3: Choosing a Style for HTML Output
Program 19.4: Using an ODS SELECT Statement to Restrict PROC UNIVARIATE Output
Program 19.5: Using the ODS TRACE Statement to Identify Output Objects
Program 19.6: Using ODS to Send Procedure Output to a SAS Data Set
Program 19.7: Using an Output Data Set to Create a Simplified Report
Program 20.1: Creating a Vertical Bar Chart
Program 20.2: Creating a Horizontal Bar Chart
Program 20.3: Vertical Bar Chart Example (Two Variables)
Program 20.4: Vertical Bar Chart Displaying a Response Variable
Program 20.5: Simple Scatter Plot
Program 20.6: Scatter Plot with a Regression Line and Confidence Intervals
Program 20.7: Time Series Plot
Program 20.8: Smooth Curves - Splines
Program 20.9: Smooth Curve - LOESS Method
Program 20.10: Histogram with a Normal Curve Overlaid
Program 20.11: Simple Box Plot
Program 20.12: Box Plot with a Grouping Variable
Program 20.13: Demonstrating Overlays and Transparency
Program 21.1: Missing Values at the End of a Line with List Input
Program 21.2: Using the MISSOVER Option
Program 21.3: Reading a Raw Data file with Short Records
Program 21.4: Demonstrating the INFILE PAD Option
Program 21.5: Demonstrating the END= Option in the INFILE Statement
Program 21.6: Demonstrating the OBS= INFILE Option to Read the First Three Lines of Data
Program 21.7: Using the OBS= and FIRSTOBS= INFILE Options Together
Program 21.8: Using the END= Option to Read Data from Multiple Files
Program 21.9: Alternative to Program 21.8
Program 21.10: Reading External Filenames from an External File
Program 21.11: Reading External Filenames Using a DATALINES Statement
Program 21.12: Reading Multiple Lines of Data to Create One Observation
Program 21.14: Incorrect Attempt to Read a File of Mixed Record Types
Program 21.15: Using a Trailing @ to Read a File with Mixed Record Types
Program 21.16: Another Example of a Trailing @ Sign
Program 21.17: Creating One Observation from One Line of Data
Program 21.18: Creating Several Observations from One Line of Data
Program 22.1: Using a Format to Recode a Variable
Program 22.2: Using a Format and a PUT Function to Create a New Variable
Program 22.3: Demonstrating a User-Written Informat
Program 22.4: Demonstrating Informat Options UPCASE and JUST
Program 22.5: A Traditional Approach to Reading a Combination of Character and Numeric Data
Program 22.6: Using an Enhanced Numeric Informat to Read a Combination of Character and Numeric Data
Program 22.7: Another Example of an Enhanced Numeric Informat
Program 22.8: Using Formats and Informats to Perform a Table Lookup
Program 22.9: Creating a Test Data Set That Will be Used to Make a CNTLIN Data Set
Program 22.10: Creating a CNTLIN Data Set from an Existing SAS Data Set
Program 22.11: Using the CNTLIN= Created Data Set
Program 22.12: Adding an OTHER Category to Your Format
Program 22.13: Updating an Existing Format Using the CNTLOUT= Data Set Option
Program 22.14: Demonstrating Nested Formats
Program 22.15: Using the Nested Format in a DATA Step
Program 22.16: Creating a Data Set of Benzene Levels
Program 22.17: Creating a MULTILABEL Format
Program 22.18: Using a MULTILABEL Format with PROC MEANS
Program 22.19: Demonstrating a Multilabel Format
Program 22.20: Using the PRELOADFMT, PRINTMISS, and MISSTEXT Options with PROC TABULATE
Program 22.21: Partial Program Showing How to Create Several Informats
Program 22.22: Creating Several Informats with a Single CNTLIN Data Set
Program 22.23: Using a SELECT Statement to Display the Contents of Two Informats
Program 22.24: Using User-Defined Informats to Perform a Table Lookup Using the INPUTN Function
Program 24.1: Creating FIRST. and LAST. Variables
Program 24.2: Counting the Number of Visits per Patient Using the DATA Step
Program 24.3: Using PROC FREQ to Count the Number of Observations in a BY Group
Program 24.4: Using the RENAME= and DROP= Data Set Options to Control the Output Data Set
Program 24.5: Computing Differences between Observations
Program 24.6: Computing Differences between the First and Last Observation in a BY Group
Program 24.7: Demonstrating the Use of Retained Variables
Program 24.8: Using a Retained Variable to “Remember” a Previous Value
Program 25.1: Using an Automatic Macro Variable to Include a Date and Time in a Title
Program 25.2: Assigning a Value to a Macro Variable with a %LET Statement
Program 25.3: Another Example of Using a %LET Statement
Program 25.4: Writing a Simple Macro
Program 25.5: Program 25.4 Rewritten to Use Keyword Parameters
Program 25.6: Macro Demonstrating Keyword Parameters and Default Values
Program 25.7: Demonstrating a Problem with Resolving a Macro Variable
Program 25.8: Program 25.7 Corrected
Program 25.9: Using a Macro Variable as a Prefix (Incorrect Version)
Program 25.10: Using a Macro Variable as a Prefix (Corrected Version)
Program 25.11: Using Macro Variables to Transfer Values from One DATA Step to Another
Program 26.1: Demonstrating a Simple Query from a Single Data Set
Program 26.2: Using an Asterisk to Select all the Variables in a Data Set
Program 26.3: Using PROC SQL to Create a SAS Data Set
Program 26.4: Joining Two Tables (Cartesian Product)
Program 26.5: Renaming the Two Subj Variables
Program 26.6: Using Aliases to Simplify Naming Variables
Program 26.7: Performing an Inner Join Using a DATA Step
Program 26.8: Performing an Inner Join
Program 26.9: Demonstrating a Left, Right, and Full Join
Program 26.10: Concatenating Two Tables
Program 26.11: Using a Summary Function in PROC SQL
Program 26.12: Demonstrating the ORDER Clause
Program 26.13: Using PROC SQL to Perform a Fuzzy Match
Program 27.1: Using a Regex to Test Social Security Values
Program 27.2: Testing the Regular Expression for US ZIP Codes
Program 27.3: Using a Regex to Check for Phone Numbers in Standard Form
Program 27.4: Converting Phone Numbers to Standard Form
Program 27.5: Demonstrating a Combination of PRXPARSE and PRXMATCH Functions
Program 27.6: Rewriting Program 27.5 to Demonstrate a Program Written by a Compulsive Programmer