Contents

 

I. View a SAS Data Set     1

 

Introduction            1

SAS Viewtable window     1

SAS System Viewer window     8

 

Table 1 Techniques for viewing a data set in SAS     8

Table 2. Comparison between the SAS Viewtable and the SAS System Viewer     10

 

II. Names in the SAS Language     11

 

Introduction     11

Data set names     11

Variable names      14

Array names     24

Format names and informat names     24

Names in PROC SQL     25

PROC REPORT: variable names or statistics?     28

Names in Macro     31

 

Table 1. Options in a BY statement     16

Table 2. Names forbidden or not good     33

 

III. Statements, Options, and their Order     35

 

Introduction     35

Definition statements     37

BY statement     41

WHERE statement     48

Effectiveness of declarative statements     53

Order of DROP, KEEP, and RENAME – statements and options     56  

RENAME statement and RENAME= option     59

WHERE= option     63

Order of statements and options        66

Order in PROC SQL     70

Mystery of PROC SORT     76

WHERE statement, BY statement and LENGTH statement     77

 

Table 1. Comparison between a BY statement and a WHERE statement     48

Table 2. Effectiveness of attributes and declarative statements     53

 

Figure 1. Pseudo flow of options and statements in DATA steps     68

Figure 2. Pseudo flow of options and statements in some PROC  steps   69

Figure 3. Pseudo flow in PROC SQL     73

 

IV. Options NOBS=, END=, and EOF=     79

 

Introduction     79

NOBS= option     79

END= option     80

EOF= option     84

 

Table 1. Options to indicate the end of a data set     79

 

V. Operators in the SAS language     89

 

Introduction     89

DATA step operators     91

Operators in a WHERE statement     96

Operators in PROC SQL     106

Operators in Macro     110

Operators in %EVAL     111

Operators in %SYSEVALF     117

Positive prefix +     118

 

Table 1. Operators in a DATA step    91

Table 2. Operators in a WHERE statement     96

Table 3. Rules to convert character values to Boolean  values   99

Table 4. Operators in PROC SQL    106

Table 5. Operators in function %EVAL    111

 

Figure 1. Conversion rules in a non-WHERE statement and in a WHERE statement     99

 

VI. Variable List     123

 

Introduction     123

Definition     123

Dash list (Numbered range list) ญญญญญญญ–Colon list (Name Prefix List) –Double dash list (Name range list) ญ– Type double dash list – Special SAS name list ญ– Array list

Usage     125

KEEP, DROP, and RENAME statements – FORMAT, INFORMAT, ARRAY, and RETAIN statements – PUT statement – INPUT statement – LENGTH statement –BY statement (in DATA step or in PROC) and VAR statement (in PROC) – Arguments in statistical functions

Summary     132

Missing elements     133

 

Table 1. Usage of variables lists     132

Table 2. Missing variables in variable lists     135

 

VII. Comparison between a WHERE Statement and a Subsetting IF statement     137

 

Table 1. Comparison between a subsetting IF statement and a WHERE statement     137

Table 2. Relationship between subsetting and sorting with a BY statement     141

 

VIII. Is .1+.2 Equal to .3?      145

 

Introduction     145

How does SAS store numeric values?      147

How does SAS do addition?      150

How can we avoid problems?      152

Magnitude and precision     153

Length attribute     154

Other softwares     157

 

Table 1. Conversion between binary values and hex values     146

 

IX. Binary Expression of Values and Related Formats and Informats     161

 

Introduction     161

BINARYw. format     161

BINARYw.d informat      162

HEXw. format     164

HEXw. informat     164

Hexdecimal expression     165

Characters and their hex values     166

Converting characters to binary values or hex values     171

Informat $BINARYw. and informat $HEXw.      172

 

Table 1. Characters and their hex values (SAS monospace font)      167

Table 2. Characters and their hex values (Courier New font)      167

Table 3. Some informats and formats and their width     173

 

X. Comparison among DATA Step, PROC SQL, and PROC REPORT     175

 

Introduction     175

Create an empty data set     175

Change order of variables     176

Create new variables     177

Remove duplicate rows     177

Sort tables     178

Combine with summary results     178

PROC REPORT and PCTSUM     179

Macro variable assignment     181

Examples of PROC SQL programming     183

 

XI. Table Operations in PROC SQL   191

 

Introduction   191

Match SELECT   191

Join operations     194

Union operations     196

UNION – OUTER UNION – EXCEPT – INTERSECT

INSERT INTO operation      200

Comparisons among table operations     200

Subquery     202

Examples of subqueries     206

 

Table 1. Comparison of options in union operations     198

Table 2. Comparisons among table operations     200

 

XII. Summary Report or Detail Report?  – PROC REPORT and PROC SQL     209

 

Introduction     209

PROC REPORT     209

Summary functions in PROC SQL     212

Summary report in PROC SQL     219

 

Table 1. Statistics in PROC REPORT     209

Table 2. Statistical functions in a DATA step     212

Table 3. Operands of MAX and MIN and arguments of some functions     215

Table 4. Summary functions in PROC SQL     217

 

XIII. Statistical Procedures and Formats     221

 

Introduction     221

General discussion     221

PROC FREQ     224

PROC MEANS     225

PROC TABULATE     226

PROC SQL     229

PROC REPORT     230

PCTN in PROC REPORT     232

 

Table 1. Specify class variables and analysis variables     222

Table 2. Non-classic formats in descriptive procedures     223

Table 3. Relationships between format and statistical values     223

 

XIV. Formats and BY statement     235

 

Introduction     235

Formats and BY statement     235

Types of formats     238

 

XV. Data Sets and Excel Files     243

 

Introduction     243

Compare an Excel file with a SAS data set     243

Import data     246

Import Wizard for an Excel file (Category 1)      247

DIMPORT command, libref and pass-through facility     254

Import wizard for a plain data file (category 2)      257

DATA step (category 3)      260

Comparison between methods in Category 1 (using SAS/ACCESS) and that in Category 2, 3 (not using SAS/ACCESS) when importing data     263

Summary     267

Output to Excel file     268

Limitations     268

Export Wizard and PROC EXPORT (Category 1)      269

Export Wizard and PROC EXPORT without SAS/ACCESS (Category 2)      271

DATA step (Category 3)      272

ODS tool (Category 4)      274

Other methods (Category 5)      275

Compare methods in Category 1 (using SAS/ACCESS) and that in Category 2, 3, 4, 5 (not using SAS/ACCESS) when exporting data     276

Summary     278

 

Table 1. Comparison of an Excel worksheet and a SAS data set on limitations            244

Table 2 Options in Import Wizard and statements in PROC IMPORT (for xls files) 251

Table 3. Options in libref and pass-through facility     256

Table 4 Options in Import Wizard and Statements in PROC IMPORT (for csv files)  259

Table 5 Comparison of ways to import data from an Excel file     267

Table 6 Comparison of ways to export data to an Excel file     279

 

XVI. SAS and File Editing     281

 

Introduction     281

CHKLOG program     281

Other programs     284

Wrapped text     286

More than one word     287

Text edit     288

Text count     289

Page x of y     289

Search in RTF files     292

Page number in RTF     293

 

XVII. RTF Output and Special Characters     299

 

Introduction     299

How many ways are there to insert a dagger into an ODS RTF output?      299

Use hex values for special characters     301

Symbol characters     303

How does RTF work?      304

Write a macro (FILE + PUT) to create RTF files     305

Unicode characters     308

 

Table 1. Comparison of ways to insert special characters into ODS RTF     302