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.3.1 The SAS Windowing Environment
1.3.2 SAS Studio and SAS University Edition
1.4.3 SAS Libraries and Data Sets
1.1 Introduction
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.
1.2 Learning Objectives
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.
1.3 SAS Environments
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.
1.3.1 The SAS Windowing Environment
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
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