Contents

 

Chapter 1.  INTRODUCTION

Section 1.  SAS and this book

     Overview of SAS -- Overview of the book -- Begin SAS session

Section 2. SAS programs

Data set -- SAS statement -- How SAS Processes Programs

Section 3. View a data set

Section 4. How to write program

Writing style of SAS programs – comments -- Make life easy -- An easy misunderstanding -- SAS files – Let’s have some fun

Section 5. SAS variables

Different variables -- Name rules in SAS – data set names – variable names -- Variable attributes -- Type attribute -- Length attribute -- First appearance -- Format, informat and label -- Attribute summary -- View variable attributes

Section 6. Global statements

TITLE – OPTIONS -- Library and libref

Chapter 2. READ DATA FROM RAW DATA FILE

Section 1. Direct input

Section 2. Four ways to create data set in data step

Section 3. Read data using INPUT only (without LENGTH and INFORMAT)

How does INPUT work? -- Column input and list input -- INPUT examples -- simplification of INPUT statement

Section 4. Three special cases

disable width in informat -- ‘character’ pointer -- blanks within a value

Section 5.  Informat attribute

Usage of informats -- Syntax of informats-- Character informat -- Numeric informats -- Date informats -- FORMAT vs INFORMAT

Section 6. Number of variables in INPUT statement and that of values in a record

Rules between the number of values and the number of variables -- Long file -- Subset of observations

Section 7. Fat file

INPUT statement and OUTPUT statement -- More values (@ and @@)

Section 8. Difference between instream input and file input

Treat instream input as file input -- Critical term -- Practical examples -- informat and double trailing

Section 9. More than one file

Section 10. IMPOER wizard and PROC IMPORT

Other delimiter file -- Import wizard for database -- Import wizard for plain data file -- PROC IMPORT

Section 11. Write to a raw data file

EXPORT wizard and PROC EXPORT -- FILE statement and PUT statement

        Section 12. Excel file and DDE tool

 

CHAPTER 3 GETTING DATA SET FROM DATA SETS (SET OPERATIONS).

Section 1. Manipulating data set.

Section 2. Getting a subset from a data set

Subset of variables (KEEP and DROP) -- RENAME -- Subset of observations -- OUTPUT statement 

Section 3. Combine two data sets vertically

1. SET set1 set2;  -- 2. PROC APPEND; --3.  SET set1 set2; BY variable(s);  (interleaving merge) -- 4. UPDATE set1 set2; BY variable(s); -- 5. MODIFY set1 set2;  BY variable(s); 

Section 4. Combine two data sets horizontally

6. SET set1; SET set2; --7. MERGE set1 set2;  (one-to-one merge) -- 8. MERGE set1 set2; BY variable(s). (Match merge)

      Section 5. Section summary and comparison

Section 6. Set operations using IN= variables.

Section 7. One to n merge and calculating percentage

Section 8. Multi-dimension merge

 

CHAPTER 4. OPERATIONS, FUNCTIONS AND STATEMENTS IN DATA STEP

Section1. Tokens and expressions

Section 2. Operators

Section 3. Missing values

            Missing values in general -- Special missing values -- Missing value comparison

Section 4. Functions INPUT and PUT

     Functions INPUT and PUT -- Automatic type conversion

Section 5. Arithmetic functions

Arithmetic functions -- Variable list -- Statistical functions -- Arguments in statistical functions -- Some examples of statistical functions

Section 6. RETAIN and Sum statement

RETAIN statement -- sum statement --

Section 7. Character operator and commonly used functions

Section 8. Commonly used date functions.

Section 9. IF statement and WHERE statement

Section 10. Relation among KEEP (DROP), RENAME and WHERE

Section 11. Operators in WHERE statement

Section 12. DO-END statements and loop.

     DO-END loop -- End what you are doing

Section 13. IF-THEN/ELSE statements

Section 14. SELECT statement

Section 15. Working on array

 

CHAPTER 5. SOME BASIC PROCEDURES

Section 1 PROC SORT

Section 2 PROC PRINT

Section 3. PROC COMPARE

Section 4. PROC FORMAT

Type and name -- Range and value -- Width of format and informat -- Type of range value and formatted value -- Order of truncation and comparison -- Difference between INPUT statement and INPUT function -- Missing character value -- Value statement -- Nested format -- Picture statement -- invalue statement -- Save formats -- Search format -- Read formats and output formats to a data set -- Define format using data set – Unformat

Section 5. PROC TRANSPOSE

Section 6. PORC CHART

On the whole – VBAR – HBAR – BLOCK -- PIE – STAR -- Can you explain this?

Section 7. PROC PLOT

Section 8. Format again and CHART, PLOT

Chapter 6. PROCEDURES FOR DESCRIPTIVE STATISTICS

Section 1. Statistics, procedures and their syntax comparison

Section 2. Common rules for statistical procedures

Type of variables and type of statistics -- Class variables and analysis variables -- BY statement and format -- FREQ statement and WEIGHT statement -- SKEWNESS and KURTOSIS

Section 3. PROC MEANS

Section 4. PROC UNIVARIATE

Section 5. PROC FREQ

Section 6. PROC TABULATE

Section 7. PROC REPORT

COLUMN statement -- Spanned header -- DEFINE statement -- DISPLAY statement and ORDER statement -- DEFINE/ANALYSIS statement -- Variable names or statistics? -- BY statement, DEFINE/GROUP statement and DEFINE/ACROSS statement -- Class variables and missing values -- DEFINE/COMPUTED statement and item compute block -- Summary COMPUTE block -- BREAK and RBREAK statements – Paging -- Output to data set

Section 8. ORDER= option and FORMCHAR= option

ORDER= option -- PRELOADFMT option in PROC REPORT -- FORMCHAR= option

Chapter 7.  MACRO

Section 1. Macro elements

     Macro statement – macro -- Open code – Comments

Section 2. Macro variable

            Macro variable -- Automatic, global and local macro variables -- Concatenation

Section 3. MACRO

Simple Marco -- Macro with parameters -- Note on macro call -- macro process

Section 4. Local statements

%IF-%THEN/%ELSE  and %DO iteration

Section 5. Operations and functions

%EVAL and %SYSEVALF -- Character functions

Section 6. Quoting functions

Why quoting function? -- Which to mask and when to mask -- Compilation and execution -- Examples of quoting functions -- %BQUOTE and %NRBQUOTE -- Quoting functions and reference

Section 7. Special tokens and macro functions

Special tokens and functions %EVAL and %SYSEVALF -- Special tokens and all macro functions -- OTHER macro functions

Section 8. Talk to macro in DATA step

Assign values to macro variables in DATA step -- SYMGET and RESOLVE -- CALL EXECUTE

Section 9. Debug

SYMBOLGEN – MLOGIC – MPRINT

Section 10. %INCLUDE and autocall

 

Chapter 8. PROC SQL

Section 1. DATA step and PROC SQL

Section 2. View a table

SELECT clause -- WHERE clause -- ORDER BY clause -- GROUP BY clause -- HAVING clause -- Relations among clauses -- case expression -- Summary output

Section 2. Create table

      Create a table -- Names in PROC SQL -- Load data to a table

Section 3. Modify table

      ALTER statement -- UPDATE – DELATE – DROP table

Section 4. Operations

Section 5. Macro variables

Section 6. Combine table

          Cartesian product -- Horizontal join -- Vertical join

Section 7. Ordering output and summary output

Section 8. Options in PROC SQL

Section 9. DATA step, PROC SQL and PROC REPORT

Chapter 9. File output and ODS

Section 1. File output in general

            File output -- General options – Font type

Section 2. PROC PRINTTO

Section 3. FILE + PUT output

Section 4. HTML formatting tools

%OUT2HTM -- %DS2HTM -- %TAB2HTM

Section 5. ODS output

Overview – Get output objects and Trace -- Select output objects -- Table template -- Data set to file -- Style template -- Commonly used parameters -- More on HTML -- Web publishing -- Combining tables with text in HTML – rtf, pdf and comparison -- Three PROCs: PRINT, TABULATE and REPORT -- Style attributes for three procedures -- PROC PRINT -- Example for PROC REPORT -- Example for PROC TABULATE -- Traffic, call define and flag -- Atom level attributes -- RTF and PROC REPORT -- rtf and title (footnote) -- PDF file output -- Indent, Id back and page of -- Special characters –

Chapter 10. Debug and Miscellaneous

Section 1. Program style

Section 2. Debug 

Section 3. Debug DATA step

Section 4. sashelp and dictionary

Section 5. Command and keys

 

 

Tables

Table 1.1 Techniques viewing a data set

Table 1.2 Some communication variables.

Table 1.3 Name rules in SAS

Table 1.4 Attributes of variables

Table 2.1 Rules to read a value

Table 2.2 Three commonly used character informats and formats

Table 2.3 Rules to use optional d in informatw.d

Table 2.4 Numeric informats and formats

Table 2.5 Date informats and formats

Table 2.6 Results for critical term for instream input and file input

Table 2.7 database files working with SAS

Table 3.1 comparison of KEEP options and statement

            Table 3.2 Options in INFILE statement or SET statement to indicate the end

Table 3.3. The rules of option FORCE in PROC APPEND

Table 3.4 Comparisons between SET statement and MODIFY statement

Table 3.5 differences between UPDATE statement and MODIFY statement

Table 3.6 comparison of data set operation

 

Table 4.1 Numeric, comparison, logical and concatenation operators

Table 4.2 comparing character value ch with missing values in different statements

Table 4.3 Types of arguments in PUT and INPUT functions

Table 4.4 rules of type conversion.

Table 4.5 Arithmetic functions

Table 4.6 Usage of variable list

Table 4.7 Commonly used character operator and functions

Table 4.8 new concatenation functions (in version 9)

Table 4.9 character search functions

Table 4.10 Commonly used date functions.

Table 4.11 comparison between IF statement and WHERE statement

Table 4.12 relation between subseting and sorting

Table 4.13 operators for WHERE statement

Table 4.14 statements stop loop, iteration or SAS session

Table 4.15 Three array functions

Table 4.16 Array functions for multi-dimensional array

Table 5.1 Relations between steps with BY statement and sorting

Table 5.2 sorting order for DESCENDING option and REVERSE option.

Table 5.3 print out number of observations (using N= option)

Table 5.4 default width and min width, max width for user-defined format.

Table 5.5 rules to determine type of range and value

Table 5.6 some directives in PICTURE statement

Table 5.7 Relations between FMTLIB, CNTLOUT= and SELECT (EXCLUDE)

Table 5.8 options in statements in PROC CHART

Table 6.1 statistics and procedures

Table 6.2 Quantile statistic

Table 6.3 Hypothesis testing

Table 6.4 statements for descriptive procedures

Table 6.5 variable type, procedures and statistics

Table 6.6 Specify class variables and analysis variables

Table 6.7 Example to determine type and way for two CLASS variables gender and grade

Table 6.8 statements or options to determine grouping

Table 6.9 Comparison between data set output of MEANS and that of UNIVARIATE

Table 6.10 comparison between LIST option and OUT= option

Table 6.11 Is missing values counted for PROC FREQ?

Table 6.12 rules to remove heading in column or row in PROC TABULATE.

Table 6.13 comparison between COLUMN statement and DEFINE statement

Table 6.14 usage in DEFINE statement

Table 6.15 rules to reference variables

Table 6.16 initialization and retain rules for report variables and temporary variables.

Table 6.17 summary values for report items

Table 6.18 Relations between ORDER= option and procedures

Table 6.19 FORMCHAR setting for some procedures

Table 7.1 Rules in function %EVAL

Table 7.2 Some macro functions and their counterparts in DATA step

Table 7.3 Special tokens and quoting functions.

Table 7.4 quoting functions

Table 7.5 different behaviors of macro functions on special tokens

Table 7.6 DATA step functions and routines related to macro or macro variable

Table 7.7 Options for macro debug

Table 8.1 functions in PROC SQL, that not in DATA step.

Table 8.2 comparison of statistical functions in DATA step and PROC SQL

Table 8.3 operators in PROC SQL

Table 8.4 comparison of options in vertical joins

 

Table 9.1 Ways to set some options

Table 9.2 options for HTML formatting tools

Table 9.3 Page formatting for three macro functions

Table 9.4 color, font, size and tag options for %OUT2HTM

Table 9.5 Some common options for %DS2HTM and %TAB2THM

Table 9.6 Color, font, size, position options for %DS2HTM and %TAB2THM

Table 9.7 Pairs of ODS statements.

Table 9.8 commonly used fonts

Table 9.9 Commonly used width units

Table 9.10 comparison of some commonly used options among different destination

Table 9.11 options for different table regions

Table 9.12 RTF control word and corresponding style

Table 9.13 character for SAS Monospace

Table 9.14 ASCII code of characters (Times New Roman)

Table 9.15 ASCII(hex) for symbol font

Table 10.1 Views in sashelp and dictionary

Figures

Figure 4.1 relation between function INPUT and PUT

Figure 4.2 conversion rules of non-WHERE statement and WHERE statement.

Figure 4.3 Pseudo flow of options and statements in DATA step.

Figure 4.4 Pseudo flow of options and statement in some PROC

Figure 5.1 Format search order

Figure 7.1 Relations among sets of macro variables

Figure 8.1 SAS process flow

Figure 9.1 Illustration of ODS flow