Mastering the SAS DS2 Procedure

Book description

Enhance your SAS data-wrangling skills with high-precision and parallel data manipulation using the DS2 programming language.

Now in its second edition, this book addresses the DS2 programming language from SAS, which combines the precise procedural power and control of the Base SAS DATA step language with the simplicity and flexibility of SQL. DS2 provides simple, safe syntax for performing complex data transformations in parallel and enables manipulation of native database data types at full precision. It also covers PROC FEDSQL, a modernized SQL language that blends perfectly with DS2. You will learn to harness the power of parallel processing to speed up CPU-intensive computing processes in Base SAS and how to achieve even more speed by processing DS2 programs on massively parallel database systems. Techniques for leveraging internet APIs to acquire data, avoiding large data movements when working with data from disparate sources, and leveraging DS2's new data types for full-precision numeric calculations are presented, with examples of why these techniques are essential for the modern data wrangler.

Here's what's new in this edition:

  • how to significantly improve performance by using the new SAS Viya architecture with its SAS Cloud Analytic Services (CAS)

  • how to declare private variables and methods in a package

  • the new PROC DSTODS2

  • the PCRXFIND and PCRXREPLACE packages

While working though the code samples provided with this book, you will build a library of custom, reusable, and easily shareable DS2 program modules, execute parallelized DATA step programs to speed up a CPU-intensive process, and conduct advanced data transformations using hash objects and matrix math operations.

This book is part of the SAS Press Series.

Table of contents

  1. Dedication
  2. Foreword
  3. About This Book
  4. About the Author
  5. Chapter 1: Getting Started
    1. 1.1 Introduction
      1. 1.1.1 What is DS2?
      2. 1.1.2 Traditional SAS DATA Step versus DS2
      3. 1.1.3 What to Expect from This Book
      4. 1.1.4 Prerequisite Knowledge
    2. 1.2 Accessing SAS and Setting Up for Practice
  6. Chapter 2: Introduction to the DS2 Language
    1. 2.1 Introduction
    2. 2.2 DS2 Programming Basics
      1. 2.2.1 General Considerations
      2. 2.2.2 Program Structure
      3. 2.2.3 Procedure Options and Global Statements
      4. 2.2.4 Program Blocks
      5. 2.2.5 Methods
      6. 2.2.6 User-Defined Methods
      7. 2.2.7 Variable Identifiers and Scope
      8. 2.2.8 Data Program Execution
    3. 2.3 Converting a SAS DATA Step to a DS2 Data Program
      1. 2.3.1 A Traditional SAS DATA Step
      2. 2.3.2 Considerations
      3. 2.3.3 The Equivalent DS2 Data Program
      4. 2.3.4 More Complex Data Program Processing
      5. 2.3.5 Automatic Conversion with PROC DSTODS2
    4. 2.4 Review of Key Concepts
  7. Chapter 3: DS2 Data Program Details
    1. 3.1 Introduction
    2. 3.2 DS2 Data Programs versus Base SAS DATA Steps
      1. 3.2.1 General Considerations
      2. 3.2.2 The Seven Subtle Dissimilarities
      3. 3.2.3 DS2 “Missing„ Features
    3. 3.3 Data Types in DS2
      1. 3.3.1 DS2 and ANSI Data Types
      2. 3.3.2 Automatic Data Type Conversion
      3. 3.3.3 Non-coercible Data Types
      4. 3.3.4 Processing SAS Missing and ANSI Null Values
    4. 3.4 Review of Key Concepts
  8. Chapter 4: User-Defined Methods and Packages
    1. 4.1 Introduction
    2. 4.2 Diving into User-Defined Methods
      1. 4.2.1 Overview
      2. 4.2.2 Designing a User-Defined Method
    3. 4.3 User-Defined Packages
      1. 4.3.1 General Considerations
      2. 4.3.2 User-Defined Package Specifics
    4. 4.4 Object-Oriented Programming with DS2 Packages
      1. 4.4.1 General Considerations
      2. 4.4.2 Designing an Object
      3. 4.4.3 Using Objects as Building Blocks
    5. 4.4 Review of Key Concepts
  9. Chapter 5: Predefined Packages
    1. 5.1 Introduction
    2. 5.2 Executing FCMP Functions in DS2
      1. 5.2.1 The FCMP Package
      2. 5.2.2 FCMP Package Example
    3. 5.3 The Hash and Hiter (Hash Iterator) Packages
      1. 5.3.1 General
      2. 5.3.2 Hash Package Example
      3. 5.3.3 Hash Iterator Package Example
    4. 5.4 The HTTP and JSON Packages
      1. 5.4.1 General
      2. 5.4.2 HTTP Package Specifics
      3. 5.4.3 JSON Package Specifics
      4. 5.4.4 HTTP and JSON Packages Example
    5. 5.5 The Matrix Package
      1. 5.5.1 General
      2. 5.5.2 Matrix Package Example
    6. 5.6 The PCRXFIND and PCRXREPLACE Packages
      1. 5.6.1 General
      2. 5.6.2 PCRXFIND and PCRXREPLACE Package Examples
    7. 5.7 The SQLSTMT Package
      1. 5.7.1 General
      2. 5.7.2 SQLSTMT Package Example
    8. 5.8 The TZ (Time Zone) Package
      1. 5.8.1 General
      2. 5.8.2 TZ Package Example
    9. 5.9 Review of Key Concepts
  10. Chapter 6: Parallel Processing in DS2
    1. 6.1 Introduction
    2. 6.2 Understanding Threaded Processing
      1. 6.2.1 The Need for Speed
      2. 6.2.2 Loading Data to and from RAM
      3. 6.2.3 Manipulating Data in RAM
    3. 6.3 DS2 Thread Programs
      1. 6.3.1 Writing DS2 Thread Programs
      2. 6.3.2 Parallel Processing Data with DS2 Threads
    4. 6.4 DS2 and the SAS In-Database Code Accelerator
      1. 6.4.1 DS2 Program In-Database Processing
    5. 6.5 DS2 and SAS® Viya® and SAS Cloud Analytic Services (CAS)
      1. 6.5.1 A Brief Introduction to SAS Viya and CAS
      2. 6.5.2 Running DS2 Programs in CAS
    6. 6.6 Review of Key Concepts
  11. Chapter 7: Performance Tuning in DS2
    1. 7.1 Introduction
    2. 7.2 DS2_OPTIONS Statement
      1. 7.2.1 TRACE Option
    3. 7.3 Analyzing Performance with the SAS Log
      1. 7.3.1 Obtaining Performance Statistics
      2. 7.3.2 Analyzing Performance Statistics
      3. 7.3.3 Tuning Your Code
    4. 7.4 Learning and Troubleshooting Resources
      1. 7.4.1 SAS Learning Resources
      2. 7.4.2 SAS Support Communities
      3. 7.4.3 SAS Technical Support
    5. 7.5 Review of Key Concepts
    6. 7.6 Connecting with the Author
  12. Index

Product information

  • Title: Mastering the SAS DS2 Procedure
  • Author(s): Mark Jordan
  • Release date: March 2018
  • Publisher(s): SAS Institute
  • ISBN: 9781635266061