Step by Step Programming with Base SAS 9 4 Second Edition Sas Institute instant download
Step by Step Programming with Base SAS 9 4 Second Edition Sas Institute instant download
https://textbookfull.com/product/step-by-step-programming-with-
base-sas-9-4-second-edition-sas-institute/
https://textbookfull.com/product/sas-certification-prep-guide-
base-programming-for-sas-9-4th-edition-sas-institute/
https://textbookfull.com/product/sas-certified-specialist-prep-
guide-base-programming-using-sas-9-4-sas/
https://textbookfull.com/product/sas-certification-prep-guide-
base-programming-for-sas-9-fifth-edition-edition-sas-sas-sas/
https://textbookfull.com/product/python-programming-a-step-by-
step-guide-from-beginner-to-advance-second-edition-eddison/
Learn to Program with Python 3: A Step-by-Step Guide to
Programming Irv Kalb
https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-irv-kalb/
https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-2nd-edition-irv-
kalb/
https://textbookfull.com/product/ansi-c-programming-learn-ansi-c-
step-by-step-1st-edition-yashavant-kanetkar/
https://textbookfull.com/product/serial-attached-
scsi-4-sas-4-r10b-6777/
https://textbookfull.com/product/visual-basic-for-kids-a-step-by-
step-computer-programming-tutorial-philip-conrod/
Step-by-Step Programming with
Base SAS 9.4 ®
Second Edition
SAS Documentation
®
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2016. Step-by-Step Programming
with Base SAS® 9.4, Second Edition. Cary, NC: SAS Institute Inc.
Step-by-Step Programming with Base SAS® 9.4, Second Edition
Copyright © 2016, SAS Institute Inc., Cary, NC, USA
ISBN 978-1-62959-894-9 (Hard copy)
ISBN 978-1-62960-806-8 (PDF)
All Rights Reserved. Produced in the United States of America.
For a hard-copy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission
of the publisher, SAS Institute Inc.
For a web download or e-book: Your use of this publication shall be governed by the terms established by the
vendor at the time you acquire this publication.
The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of
the publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not
participate in or encourage electronic piracy of copyrighted materials. Your support of others’ rights is appreciated.
U.S. Government License Rights; Restricted Rights: The Software and its documentation is commercial computer
software developed at private expense and is provided with RESTRICTED RIGHTS to the United States
Government. Use, duplication, or disclosure of the Software by the United States Government is subject
to the license terms of this Agreement pursuant to, as applicable, FAR 12.212, DFAR 227.7202-1(a), DFAR
227.7202-3(a), and DFAR 227.7202-4, and, to the extent required under U.S. federal law, the minimum restricted
rights as set out in FAR 52.227-19 (DEC 2007). If FAR 52.227-19 is applicable, this provision serves as notice under
clause (c) thereof and no other notice is required to be affixed to the Software or documentation. The Government’s
rights in Software and documentation shall be only those set forth in this Agreement.
SAS Institute Inc., SAS Campus Drive, Cary, NC 27513-2414
November 2016
SAS® and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS
Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.
SAS software may be provided with certain third-party software, including but not limited to open-source software,
which is licensed under its applicable third-party software license agreement. For license information about third-
party software distributed with SAS software, refer to http://support.sas.com/thirdpartylicenses.
9.4-P2:basess
Contents
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Chapter 22 • Conditionally Processing Observations from Multiple SAS Data Sets . . . . . . . . 349
Introduction to Conditional Processing from Multiple SAS Data Sets . . . . . . . . . . . . 349
Input SAS Data Sets for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Determining Which Data Set Contributed the Observation . . . . . . . . . . . . . . . . . . . . . 353
Contents vii
Chapter 23 • Analyzing Your SAS Session with the SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Introduction to Analyzing Your SAS Session with the SAS Log . . . . . . . . . . . . . . . . . 366
Understanding the SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Locating the SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Understanding the Log Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Writing to the SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Suppressing Information in the SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Changing the Appearance of the Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Chapter 29 • Creating Detail and Summary Reports with the REPORT Procedure . . . . . . . . . 501
Introduction to Creating Detail and Summary Reports with the REPORT Procedure . 501
Understanding How to Construct a Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
Input File and SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Creating Simple Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Creating More Sophisticated Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
Chapter 38 • Modifying SAS Data Set Names and Variable Attributes . . . . . . . . . . . . . . . . . . . 713
Introduction to Modifying SAS Data Set Names and Variable Attributes . . . . . . . . . . 713
Input Data Library for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
Renaming SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
Modifying Variable Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 839
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
xii Contents
xiii
Syntax Components
The components of the syntax for most language elements include a keyword and
arguments. For some language elements, only a keyword is necessary. For other
language elements, the keyword is followed by an equal sign (=). The syntax for
arguments has multiple forms in order to demonstrate the syntax of multiple arguments,
with and without punctuation.
keyword
specifies the name of the SAS language element that you use when you write your
program. Keyword is a literal that is usually the first word in the syntax. In a CALL
routine, the first two words are keywords.
In these examples of SAS syntax, the keywords are bold:
CHAR (string, position)
CALL RANBIN (seed, n, p, x);
ALTER (alter-password)
BEST w.
REMOVE <data-set-name>
In this example, the first two words of the CALL routine are the keywords:
CALL RANBIN(seed, n, p, x)
The syntax of some SAS statements consists of a single keyword without arguments:
DO;
xiv About This Book
In this example, string and substring are required arguments, whereas modifiers and
startpos are optional.
FIND(string, substring <, modifiers> <, startpos>
argument(s)
specifies that one argument is required and that multiple arguments are allowed.
Separate arguments with a space. Punctuation, such as a comma ( , ) is not required
between arguments.
The MISSING statement is an example of this form of multiple arguments:
MISSING character(s);
<LITERAL_ARGUMENT>argument-1<<LITERAL_ARGUMENT>argument-2 ... >
specifies that one argument is required and that a literal argument can be associated
with the argument. You can specify multiple literals and argument pairs. No
punctuation is required between the literal and argument pairs. The ellipsis (...)
indicates that additional literals and arguments are allowed.
The BY statement is an example of this argument:
BY <DESCENDING> variable-1 <<DESCENDING> variable-2 …>;
argument-1 <option(s)> <argument-2 <option(s)> ...>
specifies that one argument is required and that one or more options can be
associated with the argument. You can specify multiple arguments and associated
options. No punctuation is required between the argument and the option. The
ellipsis (...) indicates that additional arguments with an associated option are
allowed.
The FORMAT procedure PICTURE statement is an example of this form of multiple
arguments:
PICTURE name <(format-option(s))>
<value-range-set-1 <(picture-1-option(s))>
<value-range-set-2 <(picture-2-option(s))> …>>;
Syntax Conventions for the SAS Language xv
Style Conventions
The style conventions that are used in documenting SAS syntax include uppercase bold,
uppercase, and italic:
UPPERCASE BOLD
identifies SAS keywords such as the names of functions or statements. In this
example, the keyword ERROR is written in uppercase bold:
ERROR <message>;
UPPERCASE
identifies arguments that are literals.
In this example of the CMPMODEL= system option, the literals include BOTH,
CATALOG, and XML:
CMPMODEL=BOTH | CATALOG | XML |
italic
identifies arguments or values that you supply. Items in italic represent user-supplied
values that are either one of the following:
• nonliteral arguments. In this example of the LINK statement, the argument label
is a user-supplied value and therefore appears in italic:
LINK label;
• nonliteral values that are assigned to an argument.
In this example of the FORMAT statement, the argument DEFAULT is assigned
the variable default-format:
FORMAT variable(s) <format > <DEFAULT = default-format>;
Special Characters
The syntax of SAS language elements can contain the following special characters:
xvi About This Book
=
an equal sign identifies a value for a literal in some language elements such as
system options.
In this example of the MAPS system option, the equal sign sets the value of MAPS:
MAPS=location-of-maps
<>
angle brackets identify optional arguments. A required argument is not enclosed in
angle brackets.
In this example of the CAT function, at least one item is required:
CAT (item-1 <, item-2, …>)
|
a vertical bar indicates that you can choose one value from a group of values. Values
that are separated by the vertical bar are mutually exclusive.
In this example of the CMPMODEL= system option, you can choose only one of the
arguments:
CMPMODEL=BOTH | CATALOG | XML
...
an ellipsis indicates that the argument can be repeated. If an argument and the ellipsis
are enclosed in angle brackets, then the argument is optional. The repeated argument
must contain punctuation if it appears before or after the argument.
In this example of the CAT function, multiple item arguments are allowed, and they
must be separated by a comma:
CAT (item-1 <, item-2, …>)
'value' or "value"
indicates that an argument that is enclosed in single or double quotation marks must
have a value that is also enclosed in single or double quotation marks.
In this example of the FOOTNOTE statement, the argument text is enclosed in
quotation marks:
FOOTNOTE <n> <ods-format-options 'text' | "text">;
;
a semicolon indicates the end of a statement or CALL routine.
In this example, each statement ends with a semicolon:
data namegame;
length color name $8;
color = 'black';
name = 'jack';
game = trim(color) || name;
run;
Several methods of referring to SAS libraries and external files are available, and some
of these methods depend on your operating environment.
In the examples that use external files, SAS documentation uses the italicized phrase
file-specification. In the examples that use SAS libraries, SAS documentation uses the
italicized phrase SAS-library enclosed in quotation marks:
infile file-specification obs = 100;
libname libref 'SAS-library';
xviii About This Book
xix
Overview
Step-by-Step Programming with Base SAS 9.4 shows you how to create SAS programs
step by step. You are provided with conceptual information and examples that illustrate
the SAS concepts. You can execute the programs in this document and view the results.
This document contains the basic information that you need to begin writing and
debugging your SAS code.
The following enhancements have been made to the documentation:
• additional information about debugging SAS programs
• new method of concatenating SAS variables
• updated sections on Output Delivery System (ODS)
In the third maintenance release for SAS 9.4, the following enhancements have been
made to the documentation:
• discussion of the DSD option was added to the documentation about list input
• directions for viewing ODS style templates were updated (see “Customizing ODS
Output at the Level of a SAS Job” on page 667)
• discussion of the IN= data set option was added to the documentation about merging
data sets
Additional information and examples of SAS log output have been added. Items in the
SAS log are explained so that you can more easily debug your own SAS programs.
Documentation for the DATA step debugger has been added. The DATA step debugger
is a tool that enables you to find logic errors in your program. A description of the tool
and examples are provided. A list of commands that you use with the debugger is also
provided.
xx Step-by-Step Programming
A preferred method of concatenating SAS variables has been introduced. You use the
CAT function to return a concatenated character string.
The sections about the Output Delivery System (ODS) have been updated, and new
information has been added. ODS gives you greater flexibility in generating, storing, and
reproducing SAS procedure and DATA step output along with a wide range of
formatting options. ODS provides formatting functionality that is not available when
using individual procedures or the DATA step without ODS.
Beginning with SAS 9.3, the default destination in the SAS windowing environment is
HTML, and ODS Graphics is enabled by default. These new defaults have several
advantages. Graphs are integrated with tables, and all output is displayed in the same
HTML file using a new style. This new style, HTMLBlue, is an all-color style that is
designed to integrate tables and modern statistical graphics. The examples in this
document now show HTML output.
xxi
Overview
For information about the accessibility of Base SAS, see the SAS 9.4 Companion for
Windows.
xxii Accessibility Features of Step-by-Step Programming with Base SAS 9.4
1
Part 1
Chapter 1
What is the SAS System? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2
Working with Output Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2
3
Chapter 1
What is the SAS System?
How you use SAS depends on what you want to accomplish. Some people use many of
the capabilities of the SAS System, and others use only a few.
At the core of the SAS System is Base SAS software, which is the software product that
you will learn to use in this documentation. This section presents an overview of Base
SAS. It introduces the capabilities of Base SAS, addresses methods of running SAS, and
outlines various types of output.
variable
data value
In a SAS data set, each row represents information about an individual entity and is
called an observation. Each column represents the same type of information and is called
a variable. Each separate piece of information is a data value. In a SAS data set, an
observation contains all the data values for an entity; a variable contains the same type of
data value for all entities.
Components of Base SAS Software 5
To build a SAS data set with Base SAS, you write a program that uses statements in the
SAS programming language. A SAS program that begins with a DATA statement and
typically creates a SAS data set or a report is called a DATA step.
The following SAS program creates a SAS data set named WEIGHT_CLUB from the
health club data:
data weight_club; 1
input IdNumber 1-4 Name $ 6-24 Team $ StartWeight EndWeight; 2
Loss=StartWeight-EndWeight; 3
datalines; 4
1023 David Shaw red 189 165 5
1049 Amelia Serrano yellow 145 124 5
1219 Alan Nance red 210 192 5
1246 Ravi Sinha yellow 194 177 5
1078 Ashley McKnight red 127 118 5
;6
The following list corresponds to the numbered items in the preceding program:
1 The DATA statement tells SAS to begin building a SAS data set named
WEIGHT_CLUB.
2 The INPUT statement identifies the fields to be read from the input data and names
the SAS variables to be created from them (IdNumber, Name, Team, StartWeight,
and EndWeight).
3 The third statement is an assignment statement. It calculates the weight each person
lost and assigns the result to a new variable, Loss.
4 The DATALINES statement indicates that data lines follow.
5 The data lines follow the DATALINES statement. This approach to processing raw
data is useful when you have only a few lines of data. (Later sections show ways to
access larger amounts of data that are stored in files.)
6 The semicolon signals the end of the raw data, and is a step boundary. It tells SAS
that the preceding statements are ready for execution.
Note: By default, the data set WEIGHT_CLUB is temporary. It exists only for the
current job or session. For information about how to create a permanent SAS data
set, see “Introduction to DATA Step Processing” on page 27.
Programming Language
This procedure, known as the PRINT procedure, displays the variables in a simple,
organized form. The following output displays the results:
To produce a table showing mean starting weight, ending weight, and weight loss for
each team, use the TABULATE procedure.
proc tabulate data=weight_club;
class team;
var StartWeight EndWeight Loss;
table team, mean*(StartWeight EndWeight Loss);
title 'Mean Starting Weight, Ending Weight,';
title2 'and Weight Loss';
run;
A portion of a SAS program that begins with a PROC (procedure) statement and ends
with a RUN statement (or is ended by another PROC or DATA statement) is called a
PROC step. Both of the PROC steps that create the previous two outputs comprise the
following elements:
• a PROC statement, which includes the word PROC, the name of the procedure that
you want to use, and the name of the SAS data set that contains the values. (If you
omit the DATA= option and data set name, the procedure uses the SAS data set that
was most recently created in the program.)
• additional statements that give SAS more information about what you want to do, for
example, the CLASS, VAR, TABLE, and TITLE statements.
• a RUN statement, which indicates that the preceding group of statements is ready to
be executed.
Another Random Scribd Document
with Unrelated Content
CHAPTER NINE
THE JUDGEMENT OF SOLOMON
"The King hailed his keeper, an Arab
As glossy and black as a scarab,
And bade him make sport and at once stir
Up and out of his den the old monster....
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com