Fundamentals of Programming in SAS. James Blum

Fundamentals of Programming in SAS - James Blum


Скачать книгу
for helping me write this acknowledgment!) Finally, I am eternally grateful for my parents, Bill and Teresa, who have provided enthusiastic encouragement during this project, just like they have done for all of my endeavors for longer than I can remember. This book would not have been possible without all of you.

      – Jonathan

      Chapter 1: Introduction to SAS

       1.1 Introduction

       1.2 Learning Objectives

       1.3 SAS Environments

       1.3.1 The SAS Windowing Environment

       1.3.2 SAS Studio and SAS University Edition

       1.4 SAS Fundamentals

       1.4.1 SAS Language Basics

       1.4.2 SAS DATA and PROC Steps

       1.4.3 SAS Libraries and Data Sets

       1.4.4 The SAS Log

       1.5 Output Delivery System

       1.6 SAS Language Basics

       1.6.1 SAS Language Structure

       1.6.2 SAS Naming Conventions

       1.7 Chapter Notes

       1.8 Exercises

      This chapter introduces basic concepts about SAS that are necessary to use it effectively. This chapter begins with an introduction to some of the available SAS environments and describes the basic functionality of each. Essentials of coding in SAS are also introduced through some pre-constructed sample programs. These programs rely on several data sets, some provided with SAS, others are provided separately with the textbook, including those that form the basis for the case study used throughout Chapters 2 through 7. Therefore, this chapter also introduces SAS data sets and libraries. In addition, an introduction to debugging code is included, which includes a discussion of the SAS log where notes, warnings, and error messages are provided for any code submitted.

      This chapter provides a basis for working in SAS, which is a necessary first step for successful mastery of the material contained in the remainder of this book. In detail, it is expected upon completion of this chapter that the following concepts are understood within the chosen SAS environment:

       Demonstrate the ability to open, edit, save, and submit a SAS program

       Apply the LIBNAME statement to create a user-defined library—including the BookData library that contains all files for this text, downloadable from the Author Page

       Demonstrate the ability to navigate through libraries and view data sets

       Think critically about all messages SAS places in the log to determine their cause and severity

       Apply ODS statements to manage output and output destinations

       Explain the basic rules and structure of the SAS language

       Demonstrate the ability to apply a template to customize output

      Use the concepts of this chapter to solve the problems in the wrap-up activity. Additional exercises and case-studies are also available to test these concepts.

      Interacting with SAS is possible in a variety of environments, including SAS from the command line, the SAS windowing environment, SAS Enterprise Guide, SAS Studio, and SAS University Edition; with most of these being available on multiple operating systems. This chapter introduces the SAS windowing environment, SAS Studio, and SAS University Edition on the Microsoft Windows operating system and points out key differences between those SAS environments. For further specifics on differences across SAS environments and operating systems, consult the appropriate SAS Documentation. In nearly all examples in this book, code is given outside of any specific environment and output is shown in generic RTF-style tables or standard image formats. Output may vary somewhat from the default styles across SAS environments on various operating systems, and examples later in this chapter demonstrate some of these differences. Later chapters give information about how to duplicate the table styles.

      The SAS windowing environment is shown in Figure 1.3.1 with three windows visible: Log, Explorer, and Editor (commonly referred to as the Enhanced Program Editor). The Results and Output windows are two other windows commonly available by default, but are typically obfuscated by other windows at launch. When code that generates output is executed, these windows (and possibly others) become relevant.

      Figure 1.3.1: SAS Windowing Environment on Microsoft Windows

Figure 1.3.1: SAS Windowing Environment on Microsoft Windows

      In the Microsoft Windows operating system, the menu and toolbars in the SAS windowing environment have a similar look and feel compared to other programs running on Windows. Exploring the menus reveals standard options under the File, Edit, and Help menus (such as Open, Save, Clear, Find). The View, Tools, Solutions, and Window menus have specialized options related to windows and utilities that are specific to SAS. The Run menu is dedicated to submissions of SAS code, including submissions to a remote session. As is typical in most applications, toolbar buttons in SAS provide quick access to common menu functions and vary depending on which window is active in the session. Some menu and toolbar options are reviewed below during the execution of the supplied sample code given in Program 1.3.1. This sample code is available from the author web pages for this book.

      Program 1.3.1: Demonstration Code

      options ps=100 ls=90 number pageno=1 nodate;

      data work.cars;

      set sashelp.cars;

      mpg_combo=0.6*mpg_city+0.4*mpg_highway;

      select(type);

      when(‘Sedan’,’Wagon’) typeB=’Sedan/Wagon’;

      when(‘SUV’,’Truck’) typeB=’SUV/Truck’;

      otherwise typeB=type;

      end;

      label mpg_combo=’Combined MPG’ typeB=’Simplified Type’;

      run;

      title ‘Combined MPG Means’;

      proc sgplot data=work.cars;

      hbar typeB / response=mpg_combo stat=mean limits=upper;

      where


Скачать книгу