SAS 9.2 Language Reference: Dictionary, Second

SAS 9.2 Language Reference: Dictionary, Second
®
SAS 9.2 Language
Reference Databases
Dictionary
Second Edition
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2009.
SAS ® 9.2 Language Reference: Dictionary, Second Edition. Cary, NC: SAS Institute Inc.
SAS® 9.2 Language Reference: Dictionary, Second Edition
Copyright © 2009, SAS Institute Inc., Cary, NC, USA
ISBN 978-1-60764-189-6
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.
U.S. Government Restricted Rights Notice. Use, duplication, or disclosure of this
software and related documentation by the U.S. government is subject to the Agreement
with SAS Institute and the restrictions set forth in FAR 52.227–19 Commercial Computer
Software-Restricted Rights (June 1987).
SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513.
1st electronic book, September 2009
1st printing, October 2009
SAS® Publishing provides a complete selection of books and electronic products to help
customers use SAS software to its fullest potential. For more information about our
e-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web site
at support.sas.com/publishing or call 1-800-727-3228.
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 registered trademarks or trademarks of their
respective companies.
Contents
What’s New
vii
Overview
vii
SAS System Features viii
SAS Language Elements x
PART
1
Dictionary of Language Elements
Chapter 1
1
4 Introduction to the SAS 9.2 Language Reference: Dictionary
3
The SAS Language Reference: Dictionary 3
Syntax Conventions for the SAS Language 4
Chapter 2
4 SAS Data Set Options
9
Definition of Data Set Options
10
Syntax
10
Using Data Set Options
10
Data Set Options by Category
12
Dictionary 14
Data Set Options Documented in Other SAS Publications
Chapter 3
4 Formats
71
81
Definition of Formats 84
Syntax
84
Using Formats 85
Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms
Data Conversions and Encodings 89
Working with Packed Decimal and Zoned Decimal Data
90
Working with Dates and Times Using the ISO 8601 Basic and Extended Notations
Formats by Category
99
Dictionary 108
Formats Documented in Other SAS Publications 277
Chapter 4
4 Functions and CALL Routines
287
Definitions of Functions and CALL Routines
297
Syntax
297
Using Functions and CALL Routines
299
Function Compatibility with SBCS, DBCS, and MBCS Character Sets
Using Random-Number Functions and CALL Routines
305
Date and Time Intervals 318
Pattern Matching Using Perl Regular Expressions (PRX) 323
Using Perl Regular Expressions in the DATA Step 324
Writing Perl Debug Output to the SAS Log
333
Perl Artistic License Compliance
334
304
88
94
iv
Base SAS Functions for Web Applications 334
Functions and CALL Routines by Category
335
Dictionary
360
Functions and CALL Routines Documented in Other SAS Publications
References
1197
Chapter 5
4 Informats
1191
1199
Definition of Informats
1201
Syntax
1202
Using Informats
1203
Byte Ordering for Integer Binary Data on Big Endian and Little Endian
1205
Platforms
Working with Packed Decimal and Zoned Decimal Data
1207
Reading Dates and Times Using the ISO 860 Basic and Extended Notations
Informats by Category
1216
Dictionary
1222
Informats Documented in Other Base SAS Publications
1353
Chapter 6
4 Statements
1361
Definition of Statements
1363
DATA Step Statements
1363
Global Statements 1369
Dictionary
1372
SAS Statements Documented in Other SAS Publications
Chapter 7
4 SAS System Options
1746
1753
Definition of System Options
1757
Syntax
1757
Using SAS System Options
1758
Comparisons
1766
SAS System Options by Category
1766
Dictionary
1779
SAS System Options Documented in Other SAS Publications
PART
2
1989
Dictionary of Component Object Language Elements
Chapter 8
4 Component Objects
2013
DATA Step Component Objects 2013
The DATA Step Component Interface
2013
Dot Notation and DATA Step Component Objects
Rules When Using Component Objects 2015
2014
4 Hash and Hash Iterator Object Language Elements
Chapter 10 4 Java Object Language Elements 2075
Chapter 9
Java Object Methods by Category
Dictionary
2076
2011
2075
2017
1211
v
PART
3
Appendixes
Appendix 1
2101
4 DATA Step Debugger
Introduction
Basic Usage
2103
2104
2105
Advanced Usage: Using the Macro Facility with the Debugger
Examples
2107
Commands 2119
Dictionary
Appendix 2
2121
4 Perl Regular Expression (PRX) Metacharacters
Tables of Perl Regular Expression (PRX) Metacharacters
4 SAS Utility Macro 2143
Appendix 4 4 Recommended Reading
2147
Appendix 3
Recommended Reading
Index
2106
2149
2147
2135
2135
vi
vii
What’s New
Overview
The SAS 9.2 Base new features, language elements, and enhancements to the
language elements continue to expand the capabilities of SAS:
3 SAS now supports the next generation Internet Protocol, IPv6, as well as IPv4.
3 The DATA step component Java object enables instantiation of Java classes and
accessing fields and methodsChapter 10, “Java Object Language Elements,” on
page 2075 on resultant objects.
3 The SAS logging facility is a new logging subsystem that can be used to collect,
categorize, and filter log events and write them to various output devices. The
logging facility can be used to log SAS server events or events that are initiated
from SAS programs. This feature is new for SAS 9.2 Phase 2.
3 In addition to SAS Monospace and SAS Monospace Bold TrueType fonts, new
TrueType fonts are available when you install SAS.
3 Universal Printing now supports Scalable Vector Graphics (SVG), Portable
Network Graphics (PNG), and PDFA-1b print output formats.
3 You can access remote files by using the Secure File Transfer Protocol (SFTP)
access method.
3 SAS now reads and writes ISO 8601 dates, time, and intervals.
3 In support of batch programming, if a program terminates without completion, the
new checkpoint mode enables programs to be resubmitted in restart mode,
resuming with the DATA or PROC step that was executing when the program
terminated.
3 In the “Functions and CALL Routines ”section there are several new and
enhanced functions as well as functions that were previously in other products and
that are now part of Base SAS. The functions that moved from the Risk
Dimensions product calculate the call and put prices from European options on
futures, based on various models. The functions that moved from SAS/ETS return
information about various date and time intervals. The functions from SAS
High-Performance Forecasting return specific dates.
3 The documentation for string functions and CALL routines now has a restriction
that identifies whether theses functions and CALL routines support Single Byte
viii
What’s New
Character Sets (SBCS), Double Byte Character Sets (DBCS), or Multi-Byte
Character Sets (MBCS). This distinction is important because improper use of
these functions and CALL routines can result in unexpected behavior in programs
that are written in a non-English language. The description for the restrictions is
located in the Function Compatibility with DBCS, MBCS, and SBCS Character
Sets section of the documentation.
3 In a DATA step, you can track the execution of code within a DO group. The DATA
statement has an optional argument for you to write a note to the SAS log when
the DO statement begins and ends.
3 New SAS system options enable you to set a default record length, specify options
for accessing PDF files, specify values for Scalable Vector Graphics, support the
checkpoint mode and the restart mode, and support fonts.
3 Some of the new features for the DATA step object attributes, operators, and
methods remove all items from the hash object without deleting the instance of the
hash object, consolidate the FIND and ADD methods into a single method call,
return the number of items in the hash object, and specifies a starting key item for
iteration.
3 In previous versions of SAS Language Reference: Dictionary, references to
language elements in other publications were included in their respective
dictionary for each language element type. For example, you could find a reference
for the $BIDI format in the format dictionary entries. You can now find references
to language elements that are documented in other publications within each
section for the language element types. Online, this section appears just before the
dictionary entries for each language element type. In the PDF or print copy, this
section appears as the last topic for each language element type.
A section that describes how SAS syntax is written has been added. This section
contains examples of how to interpret the syntax.
SAS System Features
Checkpoint Mode and Restart Mode
If a batch program terminates before it completes and it was started in checkpoint
mode, the program can be resubmitted in restart mode, resuming with the DATA or
PROC step that was executing when the program terminated. DATA and PROC steps
that have already completed do not need to be rerun. See “Checkpoint Mode and
Restart Mode” in SAS Language Reference: Concepts.
Support for ISO 8601 Basic and Extended Time Notations
In SAS 9.1.3, the formats and informats that support the ISO 8601 basic and
extended time notations were documented in the SAS 9.1.3 XML LIBNAME: User’s
Guide. These formats and informats have been renamed and are now documented in
SAS Language Reference: Dictionary.
The new names clearly distinguish the basic and extended formats and informats.
You can see the renamed formats and informats in their respective sections in the
topics that follow. In addition, a new CALL routine, IS8601_CONVERT, converts ISO
8601 intervals to datetime and duration values, and datetime and duration values to an
ISO 8601 interval.
What’s New ix
Support for IPv6
SAS 9.2 introduces support for the "next generation" of Internet Protocol, IPv6,
which is the successor to the current Internet Protocol, IPv4. Rather than replacing
IPv4 with IPv6, SAS 9.2 supports both protocols. A primary reason for the new protocol
is that the limited supply of 32-bit IPv4 address spaces is being depleted. IPv6 uses a
128-bit address scheme, which provides more IP addresses than IPv4 did.
For more information, see Internet Protocol Version 6 (IPV6) in SAS Language
Reference: Concepts.
Universal Printing and New TrueType Fonts
In SAS 9.2, all Universal Printers and many SAS/GRAPH devices use the FreeType
engine to render TrueType fonts for output in all of the operating environments that
SAS software supports. In addition, by default, many SAS/GRAPH device drivers and
all Universal Printers generate output using ODS styles, and these ODS styles use
TrueType fonts.
In addition to SAS Monospace and SAS Monospace Bold, 40 additional fonts
(TrueType) are available when you install SAS:
3
3
3
3
Three Latin fonts compatible with Microsoft
Ten graphic symbol fonts
Eight multilingual Unicode fonts
Nineteen monolingual Asian fonts
New Universal printers include the following:
PDFA
produces an archivable PDF compliant with PDF/A-1b .
PNG
produces Portable Network Graphics, which is a raster image format
that is designed to replace the older simple GIF and the more
complex TIFF format.
PNGt
produces transparent Portable Network Graphics.
SVG
produces Scalable Vector Graphics, which is a language for
describing two-dimensional graphics and graphical applications in
XML.
SVGt
produces transparent Scalable Vector Graphics.
SVGnotip
produces Scalable Vector Graphics without tooltips.
SVGView
produces Scalable Vector Graphics with controls to navigate through
multi-page SVG documents.
SVGZ
produces compressed Scalable Vector Graphics.
For more information, see Printing with SAS in SAS Language Reference: Concepts.
SAS Logging Facility Language Elements
The SAS logging facility is a flexible, configurable logging subsystem that you can
use to collect, categorize, and filter log events and write them to a variety of output
devices. The SAS language now includes autocall macros, functions, and DATA step
component objects for creating logging facility components that categorize log events.
The logging facility and the SAS log are two separate logging systems. For more
x
What’s New
information, including the reference documentation for the logging facility language
elements, see SAS Logging: Configuration and Programming Reference. This feature is
new for SAS 9.2 Phase 2.
WHERE-Expression Processing
In a WHERE expression, the LIKE operator now supports an escape character. The
escape character enables you to search for the percent sign (%) and the underscore (_)
characters in values. For more information, see “Syntax of WHERE Expression” in SAS
Language Reference: Concepts.
DATA Step Java Object
The DATA step component Java object enables you to instantiate Java classes and
access fields and methods on the resultant objects. Although the documentation for the
DATA step component Java object for SAS 9.2 Phase 1 has been available on
http://support.sas.com, the documentation is available in SAS Help and
Documentation for SAS 9.2 Phase 2.
Viewing Help and ODS Output in the Remote Browser
The remote browser has been used in some operating environments in prior releases
of SAS to view SAS Help and ODS HTML output. You can now view SAS Help and
ODS HTML output, and PDF and RTF output under z/OS, OpenVMS, UNIX, and
Windows 64-bit environments. Windows 32-bit environments use the SAS browser to
view Help and ODS output.
You enable remote browsing by configuring these system options:
HELPBROWSER= specifies whether you want to use the remote browser or the SAS
browser.
HELPHOST=
specifies the name of the computer where the remote browser sends
Help and ODS output.
HELPPORT=
specifies the port number for the remote browser client.
For more information about remote browsing, see the Help documentation for your
operating environment: OpenVMS, UNIX, Windows, z/OS
SAS Language Elements
Data Set Options
The DLDMGACTION=NOINDEX data set option has a new argument.
The NOINDEX argument automatically repairs the data set without the indexes and
integrity constraints, deletes the index file, updates the data file to reflect the disabled
indexes and integrity constraints, and limits the data file to be opened only in INPUT
mode.
What’s New xi
Formats
3 The following formats are new:
$BASE64X
converts character data to ASCII text using Base 64 encoding.
$N8601B
writes ISO 8601 duration, datetime, and interval forms using the basic
notations PnYnMnDTnHnMnS and yyyymmddThhmmss.
$N8601BA
writes ISO 8601 duration, datetime, and interval forms using the basic
notations PyyyymmddThhmmss and yyyymmddThhmmss.
$N8601E
writes ISO 8601 duration, datetime, and interval forms using the extended
notations PnYnMnDTnHnMnS and yyyy-mm-ddThh:mm:ss.
$N8601EA
writes ISO 8601 duration, datetime, and interval forms using the extended
notations Pyyyy-mm-ddThh:mm:ss and yyyy-mm-ddThh:mm:ss.
$N8601EH
writes ISO 8601 duration, datetime, and interval forms for the extended
notations Pyyyy-mm-ddThh:mm:ss and yyyy-mm-ddThh:mm:ss, using a
hyphen ( - )for omitted components.
$N8601EX
writes ISO 8601 duration, datetime, and interval forms for the extended
notations Pyyyy-mm-ddThh:mm:ss and yyyy-mm-ddThh:mm:ss, using an x for
each digit of an omitted component.
$N8601H
writes ISO 8601 duration, datetime, and interval forms PnYnMnDTnHnMnS
and yyyy-mm-ddThh:mm:ss, dropping omitted components in duration values
and using a hyphen ( - )for omitted components in datetime values.
$N8601X
writes ISO 8601 duration, datetime, and interval forms PnYnMnDTnHnMnS
and yyyy-mm-ddThh:mm:ss, dropping omitted components in duration values
and using an x for each digit of an omitted component in datetime values.
B8601DA
writes date values using the IOS 8601 base notation yyyymmdd.
B8601DN
writes the date from a datetime value using the ISO 8601 basic notation
yyyymmdd.
B8601DT
writes datetime values in the ISO 8601 basic notation
yyyymmddThhmmssffffff.
B8601DZ
writes datetime values in the Coordinated Universal Time (UTC) time scale
using the ISO 8601 datetime and time zone basic notation
yyyymmddThhmmss+|–hhmm.
xii What’s New
B8601LZ
writes time values as local time by appending a time zone offset difference
between the local time and UTC, using the ISO 8601 basic time notation
hhmmss+|–hhmm.
B8601TM
writes time values using the ISO 8601 basic notation hhmmssffff.
B8601TZ
adjusts time values to the Coordinated Universal Time (UTC) and writes
them using the ISO 8601 basic time notation hhmmss+|–hhmm.
BESTD
prints numeric values, lining up decimal places for values of similar
magnitude, and prints integers without decimals.
E8601DA
writes date values using the ISO 8601 extended notation yyyy-mm-dd.
E8601DN
writes the date from a SAS datetime value using the ISO 8601 extended
notation yyyy-mm-dd.
E8601DT
writes datetime values in the ISO 8601 extended notation
yyyy-mm-ddThh:mm:ss.ffffff.
E8601DZ
writes datetime values in the Coordinated Universal Time (UTC) time scale
using the ISO 8601 datetime and time zone extended notation
yyyy-mm-ddThh:mm:ss+|–hh:mm.
E8601LX
writes time values as local time, appending the Coordinated Universal Time
(UTC) offset for the local SAS session, using the ISO 8601 extended time
notation hh:mm:ss+|–hh:mm.
E8601TM
writes time values using the ISO 8601 extended notation hh:mm:ss.ffffff.
E8601TZ
adjusts time values to the Coordinated Universal Time (UTC) and writes the
values using the ISO 8601 extended notation hh:mm:ss+|–hh:mm.
MDYAMPM
writes datetime values in the form mm/dd/yy<yy> hh:mm AM|PM. The year
can be either two or four digits. This feature is new for SAS 9.2 Phase 2 and
later.
PERCENTN
produces percentages, using a minus sign for negative values.
SIZEK
writes a numeric value in the form nK for kilobytes. This feature is new for
SAS 9.2 Phase 2 and later.
SIZEKB
writes a numeric value in the form nKB for kilobytes. This feature is new for
SAS 9.2 Phase 2 and later.
SIZEKMG
writes a numeric value in the form nKB for kilobytes, nMB for megabytes, or
nGB for gigabytes. This feature is new for SAS 9.2 Phase 2 and later.
What’s New xiii
VMSZN
generates VMS and MicroFocus COBOL zoned numeric data.
3 The following formats were previously documented in other publications and are
now part of this document:
WEEKUw.
writes a week number in decimal format by using the U algorithm.
WEEKVw.
writes a week number in decimal format by using the V algorithm.
WEEKWw.
writes a week number in decimal format by using the W algorithm.
3 The following format is enhanced:
DATEw.
In addition to writing dates in the form ddmmmyy or ddmmmyyyy, the
DATEw. format now writes dates in the form dd-mmm-yyyy.
Functions and CALL Routines
3 In the second maintenance release after SAS 9.2, best practices for custom interval
names for date and time functions is new.
3 The following functions and CALL routines are new:
ALLCOMB
generates all combinations of the values of n variables taken k at a time in a
minimal change order.
ALLPERM
generates all permutations of the values of several variables in a minimal
change order.
ARCOSH
returns the inverse hyperbolic cosine.
ARSINH
returns the inverse hyperbolic sine.
ARTANH
returns the inverse hyperbolic tangent.
CALL ALLCOMB
generates all combinations of the values of n variables taken k at a time in a
minimal change order.
CALL ALLCOMBI
generates all combinations of the indices of n objects taken k at a time in a
minimal change order.
CALL GRAYCODE
generates all subsets of n items in a minimal change order.
CALL ISO8601_CONVERT
converts an ISO 8601 interval to datetime and duration values, or converts
datetime and duration values to an ISO 8601 interval.
xiv
What’s New
CALL LEXCOMB
generates all distinct combinations of the non-missing values of n variables
taken k at a time in lexicographic order.
CALL LEXCOMBI
generates all combinations of the indices of n objects taken k at a time in
lexicographic order.
CALL LEXPERK
generates all distinct permutations of the non-missing values of n variables
taken k at a time in lexicographic order.
CALL LEXPERM
generates all distinct permutations of the non-missing values of several
variables in lexicographic order.
CALL SORTC
sorts the values of character arguments.
CALL SORTN
sorts the values of numeric arguments.
CATQ
concatenates character or numeric values by using a delimiter to separate
items and by adding quotation marks to strings that contain the delimiter.
CHAR
returns a single character from a specified position in a character string.
CMISS
counts the number of missing arguments.
COUNTW
counts the number of words in a character expression.
DIVIDE
returns the result of a division that handles special missing values for ODS
output.
ENVLEN
returns the length of an environment variable.
EUCLID
returns the Euclidean norm of the non-missing arguments.
FINANCE
computes financial calculations such as deprecation, maturation, accrued
interest, net present value, periodic savings, and internal rates of return.
FINDW
searches a character string for a word.
FIRST
returns the first character in a character string.
GCD
returns the greatest common divisor for one or more integers.
GEODIST
returns the geodetic distance between two latitude and longitude coordinates.
GRAYCODE
generates all subsets of n items in a minimal change order.
INTFIT
returns a time interval that is aligned between two dates.
What’s New xv
INTGET
returns an interval based on three date or datetime values.
INTSHIFT
returns the shift interval that corresponds to the base interval.
INTTEST
returns 1 if a time interval is valid, and returns 0 if a time interval is invalid.
LCM
returns the smallest multiple that is exactly divisible by every number in a
set of numbers.
LCOMB
computes the logarithm of the COMB function—that is, the logarithm of the
number of combinations of n objects taken r at a time.
LEXCOMB
generates all distinct combinations of the non-missing values of n variables
taken k at a time in lexicographic order.
LEXCOMBI
generates all combinations of the indices of n objects taken k at a time in
lexicographic order.
LEXPERK
generates all distinct permutations of the non-missing values of n variables
taken k at a time in lexicographic order.
LEXPERM
generates all distinct permutations of the non-missing values of several
variables in lexicographic order.
LFACT
computes the logarithm of the FACT (factorial) function.
LOG1PX
returns the log of 1 plus the argument.
LPERM
computes the logarithm of the PERM function—that is, the logarithm of the
number of permutations of n objects, with the option of including r number of
elements.
LPNORM
returns the Lp norm of the second argument and subsequent non-missing
arguments.
MD5
returns the result of the message digest of a specified string.
MODEXIST
determines whether a software image exists in the version of SAS that you
have installed.
MSPLINT
returns the ordinate of a monotonicity-preserving interpolating spline.
RENAME
renames a member of a SAS library, an external file, or a directory.
SUMABS
returns the sum of the absolute values of the non-missing arguments.
xvi
What’s New
TRANSTRN
removes or replaces all occurrences of a substring in a character string.
WHICHC
searches for a character value that is equal to the first argument, and returns
the index of the first matching value.
WHICHN
searches for a numeric value that is equal to the first argument, and returns
the index of the first matching value.
ZIPCITYDISTANCE
returns the geodetic distance between two ZIP code locations.
3 The descriptions of the arguments in the following functions are enhanced:
DOPEN
opens a directory, and returns a directory identifier value.
EXIST
verifies the existence of a SAS library member.
FOPEN
opens an external file and returns a file identifier value.
FEXIST
verifies the existence of an external file that is associated with a fileref.
FILENAME
assigns or deassigns a fileref to an external file, a directory, or an output
device.
FILEREF
verifies whether a fileref has been assigned for the current SAS session.
LIBNAME
assigns or deassigns a libref for a SAS library.
LIBREF
verifies that a libref has been assigned.
MOPEN
opens a file by directory ID and member name, and returns either the file
identifier or a 0.
PATHNAME
returns the physical name of a SAS library or an external file, or returns a
blank.
3 The following functions were previously in Risk Dimensions, and are now in Base
SAS:
BLACKCLPRC
calculates the call price for European options on futures, based on the Black
model.
BLACKPTPRC
calculates the put price for European options on futures, based on the Black
model.
BLKSHCLPRT
calculates the call price for European options, based on the Black-Scholes
model.
What’s New xvii
BLKSHPTPRT
calculates the put price for European options, based on the Black-Scholes
model.
GARKHCLPRC
calculates the call price for European options on stocks, based on the
Garman-Kohlhagen model.
GARKHPTPRC
calculates the put price for European options on stocks, based on the
Garman-Kohlhagen model.
MARGRCLPRC
calculates the call price for European options on stocks, based on the
Margrabe model.
MARGRPTPRC
calculates the put price for European options on stocks, based on the
Margrabe model.
3 The following functions were previously in SAS/ETS, and are now in Base SAS:
INTCINDEX
returns the cycle index, given a date, time, or datetime value.
INTCYCLE
returns the date, time, or datetime interval at the next higher seasonal cycle,
given a date, time, or datetime interval.
INTFMT
returns a recommended format, given a date, time, or datetime interval.
INTINDEX
returns the seasonal index, given a date, time, or datetime interval and value.
INTSEAS
returns the length of the seasonal cycle, given a date, time, or datetime
interval.
3 The following functions were previously in SAS High-Performance Forecasting,
and are now in Base SAS:
HOLIDAY
returns the date of the specified holiday for the specified year.
NWKDOM
returns the date for the nth occurrence of a weekday for the specified month
and year.
3 The following functions were moved from SAS Language Reference: Dictionary to
the SAS/IML documentation:
MODULEIC
calls an external routine and returns a character value (in the IML
environment only).
MODULEIN
calls an external routine and returns a numeric value (in the IML
environment only).
CALL MODULEI
calls an external routine without any return code (in the IML environment
only).
xviii What’s New
3 The following functions and CALL routines are enhanced:
CALL POKE
can now write floating-point numbers directly into memory on a 32–bit
platform.
CALL POKELONG
can now write floating-point numbers directly into memory on 32-bit and
64-bit platforms.
CALL SCAN
returns the position and length of a given word from a character expression.
DATDIF
now has new values for the basis argument, and has a reference to a
document that is published by the Securities Industry Association.
FSEP
now has an optional argument for a hexadecimal character delimiter.
INDEX
now has an example that shows how leading and trailing spaces are handled.
INDEXW
can now have alternate delimiters. If you use an alternate delimiter, then
INDEXW does not recognize the end of the text as the end data. Another
example has also been added to the function.
INTCK
now has a fifth argument in the syntax. Retail calendar intervals that are
ISO 8601 compliant, and custom intervals have been added.
INTNX
can now use retail calendar intervals that are ISO 8601 compliant.
INTCINDEX, INTCYCLE, INTFIT, INTFMT, INTGET, INTINDEX, INTSEAS,
INTSHIFT, and INTTEST
are now able to use retail calendar intervals that are ISO 8601 compliant.
LAG
now has more information about memory limits.
LIBNAME
now has sections that explain how to use the LIBNAME function with one,
two, three, and four arguments.
OPEN
has a new fourth argument. This argument specifies whether the first
argument is a two-level name (data set name) or a filename.
SCAN
returns the nth word from a character expression.
TRANSTRN
has been rewritten.
TRANWRD
has an updated Comparisons section and a new example.
WEEK
now has enhanced documentation for the U, V, and W descriptors.
What’s New xix
ZIPSTATE
now has information about Army Post Office (APO) and Fleet Post Office
(FPO) codes.
3 The RX set of functions and CALL routines have been removed from the
documentation. They have been replaced by a set of PRX functions and CALL
routines, which have been available in previous versions of SAS, and which
provide superior functionality.
The following table lists the RX functions and CALL routines and their PRX
replacements:
RX Function
PRX Replacement
CALL RXCHANGE
CALL PRXCHANGE
CALL RXFREE
CALL PRXFREE
CALL RXSUBSTR
CALL PRXSUBSTR
RXMATCH
PRXMATCH
RXPARSE
PRXPARSE
3 The SCANQ function and the CALL SCANQ routine have been removed from the
documentation and replaced by the superior functionality of the SCAN function
and CALL SCAN routine.
Informats
3 The following informats are new:
$BASE64X
converts ASCII text to character data by using Base 64 encoding.
$N8601B
reads complete, truncated, and omitted forms of ISO 8601 duration, datetime,
and interval values that are specified in either the basic or extended
notations.
$N8601E
reads ISO 8601 duration, datetime, and interval values that are specified in
the extended notation.
B8601DA
reads date values that are specified in the ISO 8601 basic notation yyyymmdd.
B8601DN
reads date values that are specified the ISO 8601 basic notation yyyymmdd
and returns SAS datetime values where the time portion of the value is
000000.
B8601DT
reads datetime values that are specified in the ISO 8601 basic notation
yyyymmddThhmmssffffff.
B8601DZ
reads datetime values that are specified in the Coordinated Universal Time
(UTC) time scale using the ISO 8601 datetime basic notation
yyyymmddThhmmss+|–hhmm or yyyymmddThhmmssffffffZ.
xx
What’s New
B8601TM
reads time values that are specified in the ISO 8601 basic notation
hhmmssffffff.
B8601TZ
reads time values that are specified in the ISO 8601 basic time notation
hhmmssfffff+|–hhmm or hhmmssffffffZ.
E8601DA
reads date values that are specified in the ISO 8601 extended notation
yyyy-mm-dd.
E8601DN
reads date values that are specified in the ISO 8601 extended notation
yyyy-mm-dd and returns SAS datetime values where the time portion of the
value is 000000.
E8601DT
reads datetime values that are specified in the ISO 8601 extended notation
yyyy-mm-ddThh:mm:ss.ffffff.
E8601DZ
reads datetime values that are specified in the Coordinated Universal Time
(UTC) time scale using the ISO 8601 datetime extended notation
hh:mm:ss+|–hh:mm.fffff orhh:mm:ss.fffffZ.
E8601LZ
reads Coordinated Universal Time (UTC) values that are specified in the ISO
8601 extended notation hh:mm:ss+|–hh:mm.fffff or hh:mm:ss.fffffZ and
converts them to the local time.
E8601TM
reads time values that are specified in the ISO 8601 extended notation
hh:mm:ss.ffffff.
E8601TZ
reads time values that are specified in the ISO 8601 extended time notation
hh:mm:ss+|–hh:mm.ffffff or hh:mm:ssZ.
S3270FZDB
reads zoned decimal data in which zeros have been left blank. This feature is
new for SAS 9.2 Phase 2 and later.
SIZEKMG
reads numeric data that is appended to the letters K, M, or G. This feature is
new for SAS 9.2 Phase 2 and later.
VMSZN
reads VMS and MicroFocus COBOL zoned numeric data.
3 The following informat is enhanced:
TRAILSGN
In addition to reading trailing plus (+) and minus (–) signs, the TRAILSGN
informat now reads values that contain commas.
3 The following informats were previously documented in other publications and are
now part of this document:
WEEKUw.
reads the format of the number-of-week value within the year and returns a
SAS date value using the U algorithm.
What’s New xxi
WEEKVw.
reads the format of the number-of-week value within the year and returns a
SAS date value using the V algorithm.
WEEKWw.
reads the format of the number-of-week value within the year and returns a
SAS date value using the W algorithm.
Statements
3 The following statements are new:
CHECKPOINT EXECUTE_ALWAYS
enables you to execute the DATA or PROC step that immediately follows
without considering the checkpoint-restart data.
FILENAME, SFTP Access Method
enables you to access remote files by using the SFTP protocol.
SYSECHO
enables IOM clients to manually track the progress of a segment of a
submitted SAS program.
3 The following statements are enhanced:
%INCLUDE
3 The filename of a file that is located in an aggregate storage location
and does not have a valid SAS name can be used as a fileref if the
filename is enclosed in quotation marks.
3 The maximum line limit is now 6K.
ABORT
Two new optional arguments enable you to do the following:
3 cause the execution of the submitted statements to be canceled.
3 suppress the output of all variables to the SAS log.
ATTRIB
The TRANSCODE=NO attribute is not supported by some SAS Workspace
Server clients. In SAS 9.2, if the attribute is not supported, variables with
TRANSCODE=NO are replaced (masked) with asterisks (*). Before SAS 9.2,
variables with TRANSCODE=NO were transcoded.
BY
The BY statement honors the linguistic collation of data that is sorted by
using the SORT procedure with the SORTSEQ=LINGUISTIC option.
DATA
Three new optional arguments enable you to do the following:
3 write a note to the SAS log for the beginning and end of each level of
nesting DO statements.
3 specify the maximum number of nested LINK statements.
3 suppress the output of all variables to the SAS log.
DECLARE
3 Data set options can now be used with the dataset: argument tag.
3 Three new argument tags enable you to do the following:
3 maintain a summary count of hash object keys.
xxii What’s New
3 ignore duplicate keys when loading a data set into the hash object.
3 specify whether multiple data items are allowed for each key.
FILE
3 The filename of a file that is located in an aggregate storage location
and does not have a valid SAS name can be used as a fileref if the
filename is enclosed in quotation marks.
3 A new option enables you to specify a character string as an alternate
delimiter (other than a blank) to be used for LIST output.
FILENAME, CATALOG Access Method
You can now specify RECFM=S (stream–record format).
FILENAME, EMAIL (SMTP) Access Method
3 You can now specify a file attachment without an extension.
3 A new option enables you to specify the priority of the e-mail message.
FILENAME, FTP Access Method
Seven new FTP options enable you to do the following:
3 specify the name of an authentication domain metadata object that
references credentials (user ID and password) in order to connect to the
FTP server without your having to explicitly specify the credentials.
3 specify that the member type of DATA is automatically appended to the
member name when you use the DIR option.
3 enable autocall macro retrieval of lowercase directory or member names
from FTP servers.
3 save the user ID and password after the user ID and password prompt
are successfully executed.
3 specify the line delimiter to use for variable-record formats: carriage
return followed by a line feed, a line feed only, or a NULL character.
3 specify the length of the FTP server response message.
3 in the second maintenance release after SAS 9.2, specify an FTP
response wait time in milliseconds.
FILENAME, SFTP Access Method
In SAS 9.2 Phase 2 and later, two new SFTP options enable you to do the
following:
3 specify the fully qualified pathname and the filename of the batch file
that contains the SFTP commands. These commands are submitted
when the SFTP access method is executed.
3 specify an SFTP response wait time in milliseconds.
FILENAME, URL Access Method
3 N can now be used as an alias for a stream-record format (RECFM=S).
3 Five new URL options enable you to do the following:
3 specify the name of an authentication domain metadata object that
references credentials (user ID and password) in order to connect to
the proxy or Web server without your having to explicitly specify the
credentials.
3 specify a fileref to which the header information is written when a file
is opened using the URL access method. The header information is
the same information that is written to the SAS log.
3 specify a user name with which you can access the proxy server.
What’s New
xxiii
3 specify a password with which you can access the proxy server.
3 specify the line delimiter to use when RECFM=V.
FILENAME, WebDAV Access Method
3 For SAS 9.2 Phase 2 and later, the FILENAME statement, WebDAV
Access Method is available for use in the z/OS operating environment.
3 The SASBAMW keyword in the FILENAME statement syntax has been
changed to WEBDAV.
3 Three new WebDAV options enable you to do the following:
3 access directory files.
3 specify that a file extension is automatically appended to the filename
when you use the DIR option.
3 retry lowercase directory or member names from WebDAV servers by
using an autocall macro.
FOOTNOTE
a new argument enables you to specify formatting options for the ODS
HTML, RTF, and PRINTER(PDF) destinations.
INFILE
3 The filename of a file that is located in an aggregate storage location
and does not have a valid SAS name can be used as a fileref if the
filename is enclosed in quotation marks.
3 A new option enables you to specify a character string as an alternate
delimiter (other than a blank) to be used for LIST input.
3 A new optional argument specifies the type of device or the access
method that is used if the fileref points to an input or output device or
location that is not a physical file.
LIBNAME for WebDAV Server Access
3 When you assign a libref to a file on a WebDAV server, the path (URL
location), user ID, and password are associated with that libref. After
the first libref is assigned, the user ID and password will be validated
on subsequent attempts to assign another libref to the same library.
3 SAS will honor a lock request on a file on a WebDAV server only if the
file is already locked by another user.
3 Two new WebDAV options enable you to do the following:
3 specify the name of an authentication domain metadata object that
references credentials (user ID and password) in order to connect to
the WebDAV server without your having to explicitly specify the
credentials.
3 prompt the user for an ID and password.
MERGE
a new argument enables you to specify at least two existing SAS data sets by
using either a numbered range list or a named prefix list.
SET
3 a new argument creates and names a variable that stores the name of
the SAS data set from which the current observation is read. The stored
name can be a data set name or a physical name. The physical name is
the name by which the operating environment recognizes the file.
xxiv
What’s New
3 a new argument enables you to specify at least two existing SAS data
sets by using either a numbered range list or a named prefix list.
TITLE
added an argument that enables you to specify formatting options for the
ODS HTML, RTF, and PRINTER(PDF) destinations.
System Options
3 The following system options are new:
CGOPTIMIZE
specifies the level of optimization to perform during code optimization. This
feature is new for SAS 9.2 Phase 2 and later.
CMPMODEL=
specifies the output model type for the MODEL procedure.
DEFLATION=
specifies the level of compression for device drivers that support the Deflate
compression algorithm.
DMSPGMLINESIZE=
specifies the maximum number of characters in a Program Editor line.
EMAILFROM
when sending an e-mail that uses SMTP, specifies whether the e-mail option
FROM is required in either the FILE or the FILENAME statement.
FILESYNC=
specifies when operating system buffers that contain contents of permanent
SAS files are written to disk.
FONTEMBEDDING
specifies whether font embedding is enabled in Universal Printer and SAS/
GRAPH printing.
FONTRENDERING=
specifies whether SAS/GRAPH devices that are based on the SASGDGIF,
SASGDTIF, and SASGDIMG modules render fonts by using the operating
system or by using the FreeType font engine.
GSTYLE
specifies whether ODS styles can be used in the generation of graphs that are
stored as GRSEG catalog entries.
HELPBROWSER=
specifies the browser to use for SAS Help and ODS output. This feature is
new for SAS 9.2 Phase 2 and later.
HELPHOST=
specifies the name of the computer where the remote browser is to send Help
and ODS output. This feature is new for SAS 9.2 Phase 2 and later.
HELPPORT=
specifies the port number for the remote browser client. This feature is new
for SAS 9.2 Phase 2 and later.
HTTPSERVERPORTMAX=
specifies the highest port number that can be used by the SAS HTTP server
for remote browsing. This feature is new for SAS 9.2 Phase 2 and later.
What’s New
xxv
HTTPSERVERPORTMIN=
specifies the lowest port number that can be used by the SAS HTTP server
for remote browsing. This feature is new for SAS 9.2 Phase 2 and later.
IBUFNO=
specifies an optional number of extra buffers to be allocated for navigating an
index file. SAS automatically allocates a minimal number of buffers in order
to navigate the index file. Typically, you do not need to specify extra buffers.
However, using IBUFNO= to specify extra buffers could improve execution
time by limiting the number of input/output operations that are required for
a particular index file.
INTERVALDS=
specifies a SAS data set that contains user-supplied holidays that can be used
by the INTNX and INTCK functions. This feature is new for SAS 9.2 Phase 2
and later.
JPEGQUALITY
specifies the JPEG quality factor that determines the ratio of image quality
to the level of compression for JPEG files processed by the SAS/GRAPH
JPEG device driver.
LRECL=
specifies the default logical record length to use for reading and writing
external files.
PDFACCESS
specifies whether text and graphics from PDF documents can be read by
screen readers for the visually impaired.
PDFASSEMBLY
specifies whether PDF documents can be assembled.
PDFCOMMENT
specifies whether PDF document comments can be modified.
PDFCONTENT
specifies whether the contents of a PDF document can be changed.
PDFCOPY
specifies whether text and graphics from a PDF document can be copied.
PDFFILLIN
specifies whether PDF forms can be filled in.
PDFPAGELAYOUT
specifies the page layout for PDF documents.
PDFPAGEVIEW
specifies the page viewing mode for PDF documents.
PDFPASSWORD
specifies the password to use to open a PDF document and the password used
by a PDF document owner.
PDFPRINT
specifies the resolution to print PDF documents.
PDFSECURITY
specifies the printing permissions for PDF documents.
xxvi
What’s New
PRIMARYPROVIDERDOMAIN=
specifies the domain name of the primary authentication provider. This
feature is new for SAS 9.2 Phase 2 and later.
S2V
specifies the starting position to begin reading a file specified in a
%INCLUDE statement, an autoexec file, or an autocall macro file with a
variable length format.
SORTVALIDATE
specifies whether the SORT procedure verifies that a data set is sorted
according to the variables in the BY statement when the sort indicator
metadata indicates a user-specified sort order.
SQLCONSTDATETIME
specifies whether the SQL procedure replaces references to the DATE, TIME,
DATETIME, and TODAY functions in a query with their equivalent constant
values before the query executes.
SQLREDUCEPUT
for the SQL procedure, specifies the engine type that a query uses for which
optimization is performed by replacing a PUT function in a query with a
logically equivalent expression.
SQLREDUCEPUTOBS
for the SQL procedure when the SQLREDUCEPUT= system option is set to
NONE, specifies the minimum number of observations that must be in a
table for PROC SQL to consider optimizing the PUT function in a query.
SQLREDUCEPUTVALUES=
for the SQL procedure when the SQLREDUCEPUT= system option is set to
NONE, specifies the minimum number of SAS format values that can exist in
a PUT function expression in order for PROC SQL to consider optimizing the
PUT function in a query.
SQLREMERGE
specifies whether the SQL procedure can process queries that use remerging
of data.
SQLUNDOPOLICY=
specifies whether the SQL procedure keeps or discards updated data if errors
occur while the data is being updated.
STEPCHKPT
specifies whether to run a batch program in checkpoint-restart mode. In
checkpoint-restart mode, if a batch program terminates during execution, the
program can be restarted beginning with the DATA or PROC step that was
executing when the program terminated.
STEPCHKPTLIB
specifies the libref which identifies the library that contains the
checkpoint-restart data.
STEPRESTART
specifies whether to start a batch program using the checkpoint data.
SVGCONTROLBUTTONS
specifies whether to display the paging control buttons and an index in a
multi-page SVG document.
What’s New xxvii
SVGHEIGHT
specifies the height of the viewport unless the SVG output is embedded in
another SVG output; specifies the value of the HEIGHT attribute of the
outermost <svg> element in the SVG file.
SVGPRESERVEASPECTRATIO
specifies whether to force uniform scaling of SVG output; sets the
preserveAspectRatio attribute on the outermost <svg> element.
SVGTITLE
specifies the title in the title bar of the SVG output; specifies the value of the
<title> element in the SVG file.
SVGVIEWBOX
specifies the coordinates, width, and height that are used to set the viewBox
attribute on the outermost <svg> element, which enables SVG output to scale
to the viewport.
SVGWIDTH
specifies the width of the viewport unless the SVG output is embedded in
another SVG output; specifies the value of the width attribute of the
outermost <svg> element in the SVG file.
SVGX
specifies the x-axis coordinate of one corner of the rectangular region into
which an embedded <svg> element is placed; specifies the x attribute on the
outermost <svg> element of the SVG file.
SVGY
specifies the y-axis coordinate of one corner of the rectangular region into
which an embedded <svg> element is placed; specifies the y attribute on the
outermost <svg> element of the SVG file.
UPRINTCOMPRESSION
specifies whether to enable compression of Universal Printer and
SAS/GRAPH print files.
VARLENCHK=
specifies the type of message to write to the SAS log if the length of a
variable is increased when the input data set is read using the SET, MERGE,
UPDATE, or MODIFY statements. This option is new for SAS 9.2 Phase 2.
3 The following system options have a new argument:
DLDMGACTION=NOINDEX
For data sets, automatically repairs the data set without the indexes and
integrity constraints, deletes the index file, updates the data file to reflect the
disabled indexes and integrity constraints, and limits the data file to be
opened only in INPUT mode.
CMPOPT=FUNCDIFFERENCING
specifies whether analytic derivatives are computed for user-defined functions.
3 The following system options are enhanced:
ECHOAUTO
SAS writes the autoexec file statements to the SAS log.
EMAILHOST
You can now specify multiple Simple Mail Transfer Protocol (SMTP) mail
servers.
xxviii What’s New
E-mail system options
All e-mail system options can now be set at any time. They are no longer
restricted to being set when SAS starts.
OVP
The default value for the OVP system option is now NOOVP.
SYSPRINTFONT=
You can specify the name of a Universal Printer to which the
SYSPRINTFONT system option setting applies.
3 The syntax for the following system options is different when these system options
are used after SAS starts, as compared to the syntax that is used when SAS
starts. For the syntax to use when SAS starts, see the documentation for your
operating environment. This feature is new for SAS 9.2 Phase 2:
APPEND=
Appends a value to the existing value of the specified system option.
INSERT=
Inserts the specified value as the first value of the specified system option.
3 The following system options are no longer supported and have been removed from
the documentation:
BATCH
no longer has an impact on the settings for the LINESIZE, OVP, PAGESIZE,
and SOURCE system options when SAS executes.
GISMAPS
SAS 9.2 no longer supplies U.S. Census Tract maps for SAS/GIS.
DATA Step Object Attributes, Operators, and Methods
3 For SAS 9.2 Phase 2 and later, the Java object language elements in Chapter 10,
“Java Object Language Elements,” on page 2075 are now documented in SAS
Language Reference: Dictionary.
3 The following hash and hash iterator methods are new:
CLEAR
removes all items from the hash object without deleting the hash object
instance.
EQUALS
determines whether two hash objects are equal.
FIND_NEXT
sets the current list item to the next item in the current key’s multiple item
list and sets the data for the corresponding data variables.
FIND_PREV
sets the current list item to the previous item in the current key’s multiple
item list and sets the data for the corresponding data variables.
HAS_NEXT
determines whether there is a next item in the current key’s multiple data
item list.
HAS_PREV
determines whether there is a previous item in the current key’s multiple
data item list.
What’s New xxix
REF
consolidates the FIND and ADD methods into a single method call.
REMOVEDUP
removes the data that is associated with the specified key’s current data item
from the hash object.
REPLACEDUP
replaces the data that is associated with the current key’s current data item
with new data.
SETCUR
specifies a starting key item for iteration.
SUM
retrieves the summary value for a given key from the hash table and stores
the value in a DATA step variable.
SUMDUP
retrieves the summary value for the current data item of the current key and
stores the value in a DATA step variable.
3 The following hash object method is enhanced:
DEFINEDONE
added an optional argument that enables recovery from memory failure when
loading a data set into a hash object.
3 The following hash object attribute is new:
ITEM_SIZE
returns the number of items in the hash object.
3 The _NEW_ statement has been reclassified as an operator.
3 For SAS 9.2 Phase 2 and later, the items in a multiple data item list are now
maintained in the order in which you insert them.
xxx
What’s New
1
1
P A R T
Dictionary of Language Elements
Chapter
1. . . . . . . . . . Introduction to the SAS 9.2 Language Reference:
Dictionary 3
Chapter
2 . . . . . . . . . . SAS Data Set Options
Chapter
3 . . . . . . . . . . Formats
Chapter
4 . . . . . . . . . . Functions and CALL Routines
Chapter
5 . . . . . . . . . . Informats
Chapter
6 . . . . . . . . . . Statements
Chapter
7 . . . . . . . . . . SAS System Options
9
81
1199
1361
1753
287
2
3
CHAPTER
1
Introduction to the SAS 9.2
Language Reference: Dictionary
The SAS Language Reference: Dictionary 3
Syntax Conventions for the SAS Language 4
Overview of Syntax Conventions for the SAS Language
Syntax Components 4
Style Conventions 5
Special Characters 6
References to SAS Libraries and External Files 6
4
The SAS Language Reference: Dictionary
SAS Language Reference: Dictionary provides detailed reference information for the
major language elements of Base SAS software:
3
3
3
3
3
3
3
3
data set options
formats
functions and CALL routines
informats
statements
SAS system options.
hash and hash iterator DATA step component object attributes and methods
Java DATA step component object attributes and methods
It also includes the following four appendixes:
3
3
3
3
DATA step debugger
Perl Regular Expression (PRX) Metacharacters
SAS utility macro
Recommended reading.
For extensive conceptual information about the SAS System and the SAS language,
including the DATA step, see SAS Language Reference: Concepts.
4
Syntax Conventions for the SAS Language
4
Chapter 1
Syntax Conventions for the SAS Language
Overview of Syntax Conventions for the SAS Language
SAS uses standard conventions in the documentation of syntax for SAS language
elements. These conventions enable you to easily identify the components of SAS
syntax. The conventions can be divided into these parts:
3 syntax components
3 style conventions
3 special characters
3 references to SAS libraries and external files
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 (=).
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 the following examples of SAS syntax, the keywords are the
first words in the syntax:
CHAR (string, position)
CALL RANBIN (seed, n, p, x);
ALTER (alter-password)
BEST w.
REMOVE <data-set-name>
In the following 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;
... SAS code ...
END;
Some system options require that one of two keyword values be
specified:
DUPLEX | NODUPLEX
argument
specifies a numeric or character constant, variable, or expression.
Arguments follow the keyword or an equal sign after the keyword.
The arguments are used by SAS to process the language element.
Arguments can be required or optional. In the syntax, optional
arguments are enclosed between angle brackets.
SAS 9.2 Language Reference: Dictionary
4
Style Conventions
5
In the following example, string and position follow the keyword
CHAR. These arguments are required arguments for the CHAR
function:
CHAR (string, position)
Each argument has a value. In the following example of SAS
code, the argument string has a value of ’summer’, and the
argument position has a value of 4:
x=char(’summer’, 4);
In the following example, string and substring are required
arguments, while modifiers and startpos are optional.
FIND(string, substring < ,modifiers> <,startpos>
Note: In most cases, example code in SAS documentation is written in lowercase
with a monospace font. You can use uppercase, lowercase, or mixed case in the code
that you write. 4
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 the following example, the keyword ERROR is
written in uppercase bold:
ERROR<message>;
UPPERCASE
identifies arguments that are literals.
In the following example of the CMPMODEL= system option, the
literals include BOTH, CATALOG, and XML:
CMPMODEL = BOTH | CATALOG | XML
italics
identifies arguments or values that you supply. Items in italics
represent user-supplied values that are either one of the following:
3 nonliteral arguments
In the following example of the LINK statement, the
argument label is a user-supplied value and is therefore
written in italics:
LINK label;
3 nonliteral values that are assigned to an argument
In the following example of the FORMAT statement, the
argument DEFAULT is assigned the variable default-format:
FORMAT = variable-1 <, ..., variable-n format ><DEFAULT
= default-format>;
Items in italics can also be the generic name for a list of
arguments from which you can choose (for example, attribute-list). If
more than one of an item in italics can be used, the items are
expressed as item-1, ..., item-n.
6
Special Characters
4
Chapter 1
Special Characters
The syntax of SAS language elements can contain the following special characters:
=
an equal sign identifies a value for a literal in some language
elements such as system options.
In the following example of the MAPS system option, the equal
sign sets the value of MAPS:
MAPS = location-of-maps
<>
angle brackets identify optional arguments. Any argument that is
not enclosed in angle brackets is required.
In the following example of the CAT function, at least one item is
required:
CAT (item-1 <, ..., item-n>)
|
a verticle 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 the following example of the CMPMODEL= system option, you
can choose only one of the arguments:
CMPMODEL = BOTH | CATALOG | XML
...
an ellipsis indicates that the argument or group of arguments
following the ellipsis can be repeated. If the ellipsis and the
following argument are enclosed in angle brackets, then the
argument is optional.
In the following example of the CAT function, the ellipsis
indicates that you can have multiple optional items:
CAT (item-1 <, ..., item-n>)
’value’ or “value”
indicates that an argument enclosed in single or double quotation
marks must have a value that is also enclosed in single or double
quotation marks.
In the following 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 the following example each statement ends with a semicolon:
data namegame;
length color name $8;
color = ’black’;
name = ’jack’;
game = trim(color) || name;
run;
References to SAS Libraries and External Files
Many SAS statements and other language elements refer to SAS libraries and
external files. You can choose whether to make the reference through a logical name (a
SAS 9.2 Language Reference: Dictionary
4
References to SAS Libraries and External Files
7
libref or fileref) or use the physical filename enclosed in quotation marks. If you use a
logical name, you usually have a choice of using a SAS statement (LIBNAME or
FILENAME) or the operating environment’s control language to make the association.
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. Note that SAS-library is enclosed in quotation marks:
infile file-specification obs = 100;
libname libref ’SAS-library’;
8
9
CHAPTER
2
SAS Data Set Options
Definition of Data Set Options 10
Syntax 10
Using Data Set Options 10
Using Data Set Options with Input or Output SAS Data Sets
How Data Set Options Interact with System Options 11
Data Set Options by Category 12
Dictionary 14
ALTER= Data Set Option 14
BUFNO= Data Set Option 15
BUFSIZE= Data Set Option 16
CNTLLEV= Data Set Option 17
COMPRESS= Data Set Option 19
DLDMGACTION= Data Set Option 20
DROP= Data Set Option 21
ENCRYPT= Data Set Option 23
FILECLOSE= Data Set Option 24
FIRSTOBS= Data Set Option 25
GENMAX= Data Set Option 27
GENNUM= Data Set Option 28
IDXNAME= Data Set Option 29
IDXWHERE= Data Set Option 31
IN= Data Set Option 32
INDEX= Data Set Option 34
KEEP= Data Set Option 35
LABEL= Data Set Option 36
OBS= Data Set Option 38
OBSBUF= Data Set Option 43
OUTREP= Data Set Option 45
POINTOBS= Data Set Option 47
PW= Data Set Option 48
PWREQ= Data Set Option 49
READ= Data Set Option 50
RENAME= Data Set Option 51
REPEMPTY= Data Set Option 53
REPLACE= Data Set Option 54
REUSE= Data Set Option 55
SORTEDBY= Data Set Option 56
SPILL= Data Set Option 58
TOBSNO= Data Set Option 65
TYPE= Data Set Option 65
WHERE= Data Set Option 66
10
10
Definition of Data Set Options
4
Chapter 2
WHEREUP= Data Set Option 68
WRITE= Data Set Option 70
Data Set Options Documented in Other SAS Publications 71
SAS Companion for Windows 71
SAS Companion for OpenVMS on HP Integrity Servers 71
SAS Companion for UNIX Environments 71
SAS Companion for z/OS 72
SAS National Language Support: Reference Guide 72
SAS Scalable Performance Data Engine: Reference 73
SAS/ACCESS for Relational Databases: References 74
Definition of Data Set Options
Data set options specify actions that apply only to the SAS data set with which they
appear. They let you perform the following operations:
3
3
3
3
renaming variables
selecting only the first or last n observations for processing
dropping variables from processing or from the output data set
specifying a password for a data set
Syntax
Specify a data set option in parentheses after a SAS data set name. To specify
several data set options, separate them with spaces.
(option-1=value-1<...option-n=value-n>)
These examples show data set options in SAS statements:
3
data scores(keep=team game1 game2 game3);
3
data mydata(index=(b k) label=’label for my data set’ drop=p read=secret);
3
data new(drop=i n index=(j combo=(x1 a1 a20 b1 b50 )));
3
data idxdup2(compress=yes index=(ok1 ok2 ssn/unique ok3));
3
proc print data=new(drop=year);
3
set old(rename=(date=Start_Date));
Using Data Set Options
Using Data Set Options with Input or Output SAS Data Sets
Most SAS data set options can apply to either input or output SAS data sets in DATA
steps or procedure (PROC) steps. If a data set option is associated with an input data
set, the action applies to the data set that is being read. If the option appears in the
DATA statement or after an output data set specification in a PROC step, SAS applies
the action to the output data set. In the DATA step, data set options for output data
sets must appear in the DATA statement, not in any OUTPUT statements that might
be present.
SAS Data Set Options
4
How Data Set Options Interact with System Options
11
Some data set options, such as COMPRESS=, are meaningful only when you create a
SAS data set because they set attributes that exist for the duration of the data set. To
change or cancel most data set options, you must re-create the data set. You can change
other options (such as PW= and LABEL=) with PROC DATASETS. For more
information, see the “DATASETS Procedure” in Base SAS Procedures Guide.
When data set options appear on both input and output data sets in the same DATA
or PROC step, first SAS applies data set options to input data sets. Then SAS evaluates
programming statements or applies data set options to output data sets. Likewise, data
set options that are specified for the data set being created are applied after
programming statements are processed. For example, when using the RENAME= data
set option, the new names are not associated with the variables until the DATA step
ends.
In some instances, data set options conflict when they are used in the same
statement. For example, you cannot specify both the DROP= and KEEP= data set
options for the same variable in the same statement. Timing can also be an issue in
some cases. For example, if using KEEP= and RENAME= on a data set specified in the
SET statement, KEEP= needs to use the original variable names. SAS processes
KEEP= before the data set is read. The new names specified in RENAME= apply to the
programming statements that follow the SET statement.
How Data Set Options Interact with System Options
Many system options and data set options share the same name and have the same
function. System options remain in effect for all DATA and PROC steps in a SAS job or
session unless they are respecified.
The data set option overrides the system option for the data set in the step in which
it appears. In this example, the OBS= system option in the OPTIONS statement
specifies that only the first 100 observations are processed from any data set within the
SAS job. The OBS= data set option in the SET statement, however, overrides the
system option for data set TWO and specifies that only the first five observations are
read from data set TWO. The PROC PRINT step prints the data set FINAL. This data
set contains the first 5 observations from data set TWO, followed by the first 100
observations from data set THREE:
options obs=100;
data final;
set two(obs=5) three;
run;
proc print data=final;
run;
12
Data Set Options by Category
4
Chapter 2
Data Set Options by Category
Table 2.1 Categories and Descriptions of SAS Data Set Options
Category
SAS Data Set Options
Description
Data Set Control
“ALTER= Data Set
Option” on page 14
Assigns an ALTER password to a SAS file that prevents
users from replacing or deleting the file, and enables
access to a read- and write-protected file.
“BUFNO= Data Set
Option” on page 15
Specifies the number of buffers to be allocated for
processing a SAS data set.
“BUFSIZE= Data Set
Option” on page 16
Specifies the size of a permanent buffer page for an
output SAS data set.
“CNTLLEV= Data Set
Option” on page 17
Specifies the level of shared access to a SAS data set.
“COMPRESS= Data Set
Option” on page 19
Specifies how observations are compressed in a new
output SAS data set.
“DLDMGACTION= Data
Set Option” on page 20
Specifies the action to take when a SAS data set in a
SAS library is detected as damaged.
“ENCRYPT= Data Set
Option” on page 23
Specifies whether to encrypt an output SAS data set.
“GENMAX= Data Set
Option” on page 27
Requests generations for a new data set, modifies the
number of generations for an existing data set, and
specifies the maximum number of versions.
“GENNUM= Data Set
Option” on page 28
Specifies a particular generation of a SAS data set.
“INDEX= Data Set Option”
on page 34
Defines an index for a new output SAS data set.
“LABEL= Data Set
Option” on page 36
Specifies a label for a SAS data set.
“OBSBUF= Data Set
Option” on page 43
Determines the size of the view buffer for processing a
DATA step view.
“OUTREP= Data Set
Option” on page 45
Specifies the data representation for the output SAS data
set.
“PW= Data Set Option” on
page 48
Assigns a READ, WRITE, and ALTER password to a SAS
file, and enables access to a password-protected SAS file.
“PWREQ= Data Set
Option” on page 49
Specifies whether to display a dialog box to enter a SAS
data set password.
“READ= Data Set Option”
on page 50
Assigns a READ password to a SAS file that prevents
users from reading the file, unless they enter the
password.
“REPEMPTY= Data Set
Option” on page 53
Specifies whether a new, empty data set can overwrite an
existing SAS data set that has the same name.
SAS Data Set Options
Category
4
Data Set Options by Category
SAS Data Set Options
Description
“REPLACE= Data Set
Option” on page 54
Specifies whether a new SAS data set that contains data
can overwrite an existing data set that has the same
name.
“REUSE= Data Set
Option” on page 55
Specifies whether new observations can be written to
freed space in compressed SAS data sets.
“SORTEDBY= Data Set
Option” on page 56
Specifies how a data set is currently sorted.
“SPILL= Data Set Option”
on page 58
Specifies whether to create a spill file for non-sequential
processing of a DATA step view.
“TOBSNO= Data Set
Option” on page 65
Specifies the number of observations to send in a client/
server transfer.
“TYPE= Data Set Option”
on page 65
Specifies the data set type for a specially structured SAS
data set.
“WRITE= Data Set
Option” on page 70
Assigns a WRITE password to a SAS file that prevents
users from writing to a file, unless they enter the
password.
Miscellaneous
“FILECLOSE= Data Set
Option” on page 24
Specifies how a tape is positioned when a SAS data set is
closed.
Observation Control
“FIRSTOBS= Data Set
Option” on page 25
Specifies the first observation that SAS processes in a
SAS data set.
“IN= Data Set Option” on
page 32
Creates a Boolean variable that indicates whether the
data set contributed data to the current observation.
“OBS= Data Set Option”
on page 38
Specifies the last observation that SAS processes in a
data set.
“POINTOBS= Data Set
Option” on page 47
Specifies whether SAS creates compressed data sets
whose observations can be randomly accessed or
sequentially accessed.
“WHERE= Data Set
Option” on page 66
Specifies specific conditions to use to select observations
from a SAS data set.
“WHEREUP= Data Set
Option” on page 68
Specifies whether to evaluate new observations and
modified observations against a WHERE expression.
“IDXNAME= Data Set
Option” on page 29
Directs SAS to use a specific index to match the
conditions of a WHERE expression.
“IDXWHERE= Data Set
Option” on page 31
Specifies whether SAS uses an index search or a
sequential search to match the conditions of a WHERE
expression.
“DROP= Data Set Option”
on page 21
For an input data set, excludes the specified variables
from processing; for an output data set, excludes the
specified variables from being written to the data set.
User Control of SAS Index
Usage
Variable Control
13
14
Dictionary
4
Chapter 2
Category
SAS Data Set Options
Description
“KEEP= Data Set Option”
on page 35
For an input data set, specifies the variables to process;
for an output data set, specifies the variables to write to
the data set.
“RENAME= Data Set
Option” on page 51
Changes the name of a variable.
Dictionary
ALTER= Data Set Option
Assigns an ALTER password to a SAS file that prevents users from replacing or deleting the file,
and enables access to a read- and write-protected file.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
See:
ALTER= Data Set Option in the documentation for your operating environment.
Syntax
ALTER=alter-password
Syntax Description
alter-password
must be a valid SAS name. See “Rules for Words and Names in the SAS Language”
in SAS Language Reference: Concepts.
Details
The ALTER= option applies to all types of SAS files except catalogs. You can use this
option to assign a password to a SAS file or to access a read-protected, write-protected,
or alter-protected SAS file.
When replacing a SAS data set that is protected with an ALTER password, the new
data set inherits the ALTER password. To change the ALTER password for the new
data set, use the MODIFY statement in the DATASETS procedure.
Note: A SAS password does not control access to a SAS file beyond the SAS system.
You should use the operating system-supplied utilities and file-system security controls
in order to control access to SAS files outside of SAS. 4
SAS Data Set Options
4
BUFNO= Data Set Option
15
See Also
Data Set Options:
“ENCRYPT= Data Set Option” on page 23
“PW= Data Set Option” on page 48
“READ= Data Set Option” on page 50
“WRITE= Data Set Option” on page 70
“File Protection” in SAS Language Reference: Concepts
“Manipulating Passwords” in “The DATASETS Procedure” in Base SAS Procedures
Guide
BUFNO= Data Set Option
Specifies the number of buffers to be allocated for processing a SAS data set.
DATA step and PROC steps
Category: Data Set Control
See: BUFNO= Data Set Option in the documentation for your operating environment.
Valid in:
Syntax
BUFNO= n | nK | hexX | MIN | MAX
Syntax Description
n | nK
specifies the number of buffers in multiples of 1 (bytes); 1,024 (kilobytes). For
example, a value of 8 specifies 8 buffers, and a value of 1k specifies 1024 buffers.
hexX
specifies the number of buffers as a hexadecimal value. You must specify the value
beginning with a number (0-9), followed by an X. For example, the value 2dx sets the
number of buffers to 45 buffers.
MIN
sets the minimum number of buffers to 0, which causes SAS to use the minimum
optimal value for the operating environment. This is the default.
MAX
sets the number of buffers to the maximum possible number in your operating
31
environment, up to the largest four-byte, signed integer, which is 2 -1, or
approximately 2 billion.
Details
The buffer number is not a permanent attribute of the data set; it is valid only for the
current SAS session or job.
16
4
BUFSIZE= Data Set Option
Chapter 2
BUFNO= applies to SAS data sets that are opened for input, output, or update.
A larger number of buffers can speed up execution time by limiting the number of
input and output (I/O) operations that are required for a particular SAS data set.
However, the improvement in execution time comes at the expense of increased memory
consumption.
To reduce I/O operations on a small data set as well as speed execution time, allocate
one buffer for each page of data to be processed. This technique is most effective if you
read the same observations several times during processing.
Operating Environment Information: The default value for BUFNO= is determined by
your operating environment and is set to optimize sequential access. To improve
performance for direct (random) access, you should change the value for BUFNO=. For
the default setting and possible settings for direct access, see the BUFNO= data set
option in the SAS documentation for your operating environment. 4
Comparisons
3 If the BUFNO= data set option is not specified, then the value of the BUFNO=
system option is used. If both are specified in the same SAS session, the value
specified for the BUFNO= data set option overrides the value specified for the
BUFNO= system option.
3 To request that SAS allocate the number of buffers based on the number of data
set pages and index file pages, use the SASFILE global statement.
See Also
Data Set Options:
“BUFSIZE= Data Set Option” on page 16
System Options:
“BUFNO= System Option” on page 1786
Statements:
“SASFILE Statement” on page 1692
BUFSIZE= Data Set Option
Specifies the size of a permanent buffer page for an output SAS data set.
Valid in:
DATA step and PROC steps
Category:
Restriction:
See:
Data Set Control
Use with output data sets only.
BUFSIZE= Data Set Option in the documentation for your operating environment.
Syntax
BUFSIZE= n | nK | nM | nG | hexX | MAX
SAS Data Set Options
4
CNTLLEV= Data Set Option
17
Syntax Description
n | nK | nM | nG
specifies the page size in multiples of 1 (bytes); 1,024 (kilobytes); 1,048,576
(megabytes); or 1,073,741,824 (gigabytes). For example, a value of 8 specifies a page
size of 8 bytes, and a value of 4k specifies a page size of 4096 bytes.
The default is 0, which causes SAS to use the minimum optimal page size for the
operating environment.
hexX
specifies the page size as a hexadecimal value. You must specify the value beginning
with a number (0-9), followed by an X. For example, the value 2dx sets the page size
to 45 bytes.
MAX
sets the page size to the maximum possible number in your operating environment,
31
up to the largest four-byte, signed integer, which is 2 -1, or approximately 2 billion
bytes.
Details
The page size is the amount of data that can be transferred for a single I/O operation to
one buffer. The page size is a permanent attribute of the data set and is used when the
data set is processed.
A larger page size can speed up execution time by reducing the number of times SAS
has to read from or write to the storage medium. However, the improvement in
execution time comes at the cost of increased memory consumption.
To change the page size, use a DATA step to copy the data set and either specify a
new page or use the SAS default. To reset the page size to the default value in your
operating environment, use BUFSIZE=0.
Note: If you use the COPY procedure to copy a data set to another library that is
allocated with a different engine, the specified page size of the data set is not retained.
Operating Environment Information: The default value for BUFSIZE= is determined
by your operating environment and is set to optimize sequential access. To improve
performance for direct (random) access, you should change the value for BUFSIZE=.
For the default setting and possible settings for direct access, see the BUFSIZE= data
set option in the SAS documentation for your operating environment. 4
See Also
Data Set Options:
“BUFNO= Data Set Option” on page 15
System Options:
“BUFSIZE= System Option” on page 1787
CNTLLEV= Data Set Option
Specifies the level of shared access to a SAS data set.
4
18
CNTLLEV= Data Set Option
4
Chapter 2
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Restriction:
Specify for input data sets only.
Syntax
CNTLLEV=LIB | MEM | REC
Syntax Description
LIB
specifies that concurrent access is controlled at the library level. Library-level control
restricts concurrent access to only one update process to the library.
MEM
specifies that concurrent access is controlled at the SAS data set (member) level.
Member-level control restricts concurrent access to only one update or output process
to the SAS data set. If the data set is open for an update or output process, then no
other operation can access the data set. If the data set is open for an input process,
then other concurrent input processes are allowed but no update or output process is
allowed.
REC
specifies that concurrent access is controlled at the observation (record) level.
Record-level control allows more than one update access to the same SAS data set,
but it denies concurrent update of the same observation.
Details
The CNTLLEV= option specifies the level at which shared update access to a SAS data
set is denied. A SAS data set can be opened concurrently by more than one SAS session
or by more than one statement, window, or procedure within a single session. By
default, SAS procedures permit the greatest degree of concurrent access possible while
they guarantee the integrity of the data and the data analysis. Therefore, you do not
typically use the CNTLLEV= data set option.
Use this option when
3 your application controls the access to the data, such as in SAS Component
Language (SCL), SAS/IML software, or DATA step programming
3 you access data through an interface engine that does not provide member-level
control of the data.
If you use CNTLLEV=REC and the SAS procedure needs member-level control for
integrity of the data analysis, SAS prints a warning to the SAS log that inaccurate or
unpredictable results can occur if the data are updated by another process during the
analysis.
Examples
Example 1: Changing the Shared Access Level
In the following example, the first SET
statement includes the CNTLLEV= data set option in order to override the default level
SAS Data Set Options
4
COMPRESS= Data Set Option
19
of shared access from member-level control to record-level control. The second SET
statement opens the SAS data set with the default member-level control.
set datalib.fuel (cntllev=rec) point=obsnum;
.
.
.
set datalib.fuel;
by area;
COMPRESS= Data Set Option
Specifies how observations are compressed in a new output SAS data set.
DATA step and PROC steps
Category: Data Set Control
Restriction: Use with output data sets only.
Valid in:
Syntax
COMPRESS=NO | YES | CHAR | BINARY
Syntax Description
NO
specifies that the observations in a newly created SAS data set are uncompressed
(fixed-length records).
YES | CHAR
specifies that the observations in a newly created SAS data set are compressed
(variable-length records) by SAS using RLE (Run Length Encoding). RLE compresses
observations by reducing repeated consecutive characters (including blanks) to
two-byte or three-byte representations.
Alias: ON
Tip: Use this compression algorithm for character data.
Note: COMPRESS=CHAR is accepted by Version 7 and later versions. 4
BINARY
specifies that the observations in a newly created SAS data set are compressed
(variable-length records) by SAS using RDC (Ross Data Compression). RDC
combines run-length encoding and sliding-window compression to compress the file.
Tip: This method is highly effective for compressing medium to large (several
hundred bytes or larger) blocks of binary data (numeric variables). Because the
compression function operates on a single record at a time, the record length needs
to be several hundred bytes or larger for effective compression.
Details
Compressing a file is a process that reduces the number of bytes required to represent
each observation. Advantages of compressing a file include reduced storage
20
DLDMGACTION= Data Set Option
4
Chapter 2
requirements for the file and fewer I/O operations necessary to read or write to the data
during processing. However, more CPU resources are required to read a compressed file
(because of the overhead of uncompressing each observation), and there are situations
where the resulting file size might increase rather than decrease.
Use the COMPRESS= data set option to compress an individual file. Specify the
option for output data sets only—that is, data sets named in the DATA statement of a
DATA step or in the OUT= option of a SAS procedure. Use the COMPRESS= data set
option only when you are creating a SAS data file (member type DATA). You cannot
compress SAS views, because they contain no data.
After a file is compressed, the setting is a permanent attribute of the file, which
means that to change the setting, you must re-create the file. That is, to uncompress a
file, specify COMPRESS=NO for a DATA step that copies the compressed file.
Comparisons
The COMPRESS= data set option overrides the COMPRESS= option in the LIBNAME
statement and the COMPRESS= system option.
The data set option POINTOBS=YES, which is the default, determines that a
compressed data set can be processed with random access (by observation number)
rather than sequential access. With random access, you can specify an observation
number in the FSEDIT procedure and the POINT= option in the SET and MODIFY
statements.
When you create a compressed file, you can also specify REUSE=YES (as a data set
option or system option) in order to track and reuse space. With REUSE=YES, new
observations are inserted in space freed when other observations are updated or
deleted. When the default REUSE=NO is in effect, new observations are appended to
the existing file.
POINTOBS=YES and REUSE=YES are mutually exclusive—that is, they cannot be
used together. REUSE=YES takes precedence over POINTOBS=YES. That is, if you set
REUSE=YES, SAS automatically sets POINTOBS=NO.
The TAPE engine supports the COMPRESS= data set option, but the engine does not
support the COMPRESS= system option.
The XPORT engine does not support compression.
See Also
Data Set Options:
“POINTOBS= Data Set Option” on page 47
“REUSE= Data Set Option” on page 55
Statements:
“LIBNAME Statement” on page 1592
System Options:
“COMPRESS= System Option” on page 1806
“REUSE= System Option” on page 1915
“Compressing Data Files” in SAS Language Reference: Concepts
DLDMGACTION= Data Set Option
Specifies the action to take when a SAS data set in a SAS library is detected as damaged.
SAS Data Set Options
4
DROP= Data Set Option
21
DATA step and PROC steps
Category: Data Set Control
Valid in:
Syntax
DLDMGACTION=FAIL | ABORT | REPAIR | NOINDEX | PROMPT
Syntax Description
FAIL
stops the step, issues an error message to the log immediately. This is the default for
batch mode.
ABORT
terminates the step, issues an error message to the log, and terminates the SAS
session.
REPAIR
automatically repairs and rebuilds indexes and integrity constraints, unless the data
file is truncated. You use the REPAIR statement in PROC DATASETS to restore a
truncated data set. It issues a warning message to the log. This is the default for
interactive mode.
NOINDEX
automatically repairs the data file without the indexes and integrity constraints,
deletes the index file, updates the data file to reflect the disabled indexes and
integrity constraints, and limits the data file to be opened only in INPUT mode. A
warning is written to the SAS log instructing you to execute the PROC DATASETS
REBUILD statement to correct or delete the disabled indexes and integrity
constraints.
See also: “REBUILD Statement” in the “DATASETS Procedure” in Base SAS
Procedures Guide
“Recovering Disabled Indexes and Integrity Constraints” in SAS Language
Reference: Concepts
PROMPT
displays a dialog box that asks you to select the FAIL, ABORT, REPAIR, or
NOINDEX action.
DROP= Data Set Option
For an input data set, excludes the specified variables from processing; for an output data set,
excludes the specified variables from being written to the data set.
Valid in:
DATA step and PROC steps
Category: Variable Control
Syntax
DROP=variable-1 <...variable-n>
22
4
DROP= Data Set Option
Chapter 2
Syntax Description
variable-1 <...variable-n>
lists one or more variable names. You can list the variables in any form that SAS
allows.
Details
If the option is associated with an input data set, the variables are not available for
processing. If the DROP= data set option is associated with an output data set, SAS
does not write the variables to the output data set, but they are available for processing.
Comparisons
3 The DROP= data set option differs from the DROP statement in these ways:
3 In DATA steps, the DROP= data set option can apply to both input and
output data sets. The DROP statement applies only to output data sets.
3 In DATA steps, when you create multiple output data sets, use the DROP=
data set option to write different variables to different data sets. The DROP
statement applies to all output data sets.
3 In PROC steps, you can use only the DROP= data set option, not the DROP
statement.
3 The KEEP= data set option specifies a list of variables to be included in processing
or to be written to the output data set.
Examples
Example 1: Excluding Variables from Input
In this example, the variables SALARY
and GENDER are not included in processing and they are not written to either output
data set:
data plan1 plan2;
set payroll(drop=salary gender);
if hired<’01jan98’d then output plan1;
else output plan2;
run;
You cannot use SALARY or GENDER in any logic in the DATA step because DROP=
prevents the SET statement from reading them from PAYROLL.
Example 2: Processing Variables without Writing Them to a Data Set
In this example,
SALARY and GENDER are not written to PLAN2, but they are written to PLAN1:
data plan1 plan2(drop=salary gender);
set payroll;
if hired<’01jan98’d then output plan1;
else output plan2;
run;
SAS Data Set Options
4
ENCRYPT= Data Set Option
23
See Also
Data Set Options:
“KEEP= Data Set Option” on page 35
Statements:
“DROP Statement” on page 1434
ENCRYPT= Data Set Option
Specifies whether to encrypt an output SAS data set.
Valid in:
DATA step and PROC steps
Category: Data Set Control
Restriction:
Use with output data sets only.
Syntax
ENCRYPT=YES | NO
Syntax Description
YES
encrypts the file. This encryption uses passwords that are stored in the data set. At
a minimum, you must specify the READ= or the PW= data set option at the same
time that you specify ENCRYPT=YES. Because the encryption method uses
passwords, you cannot change any password on an encrypted data set without
re-creating the data set.
CAUTION:
Record all passwords when using ENCRYPT=YES. If you forget the passwords, you
cannot reset it without assistance from SAS. The process is time-consuming and
resource-intensive. 4
NO
does not encrypt the file.
Details
When using ENCRYPT=YES, the following list applies:
3 To copy an encrypted data file, the output engine must support the encryption.
Otherwise, the data file is not copied.
3 Encrypted files work only in SAS 6.11 or later.
3 You cannot encrypt SAS views, because they contain no data.
3 If the data file is encrypted, all associated indexes are also encrypted.
3 Encryption requires approximately the same amount of CPU resources as
compression.
3 You cannot use PROC CPORT on SAS Proprietary encrypted data files.
24
FILECLOSE= Data Set Option
4
Chapter 2
Using the ENCRYPT=YES Option
This example creates an encrypted SAS data set using encryption:
data salary(encrypt=yes read=green);
input name $ yrsal bonuspct;
datalines;
Muriel
34567 3.2
Bjorn
74644 2.5
Freda
38755 4.1
Benny
29855 3.5
Agnetha
70998 4.1
;
To use this data set, specify the read password:
proc contents data=salary(read=green);
run;
See Also
Data Set Options:
“ALTER= Data Set Option” on page 14
“PW= Data Set Option” on page 48
“READ= Data Set Option” on page 50
“WRITE= Data Set Option” on page 70
“SAS Data File Encryption” in SAS Language Reference: Concepts
FILECLOSE= Data Set Option
Specifies how a tape is positioned when a SAS data set is closed.
Valid in:
DATA step and PROC steps
Category:
Miscellaneous
FILECLOSE= Data Set Option in the documentation for your operating
environment.
See:
Syntax
FILECLOSE=DISP | LEAVE | REREAD | REWIND
Syntax Description
DISP
positions the tape volume according to the disposition specified in the operating
environment’s control language.
SAS Data Set Options
4
FIRSTOBS= Data Set Option
25
LEAVE
positions the tape at the end of the file that was just processed. Use
FILECLOSE=LEAVE if you are not repeatedly accessing the same files in a SAS
program but you are accessing one or more subsequent SAS files on the same tape.
REREAD
positions the tape volume at the beginning of the file that was just processed. Use
FILECLOSE=REREAD if you are accessing the same SAS data set on tape several
times in a SAS program.
REWIND
rewinds the tape volume to the beginning. Use FILECLOSE=REWIND if you are
accessing one or more previous SAS files on the same tape, but you are not
repeatedly accessing the same files in a SAS program.
Operating Environment Information: These values are not recognized by all operating
environments. Additional values are available on some operating environments. See
the appropriate sections of the SAS documentation for your operating environment for
more information about using SAS libraries that are stored on tape. 4
FIRSTOBS= Data Set Option
Specifies the first observation that SAS processes in a SAS data set.
DATA step and PROC steps
Category: Observation Control
Restriction: Valid for input (read) processing only.
Restriction: Cannot use with PROC SQL views.
Valid in:
Syntax
FIRSTOBS= n| nK | nM | nG | hexX | MIN | MAX
Syntax Description
n | nK | nM | nG
specifies the number of the first observation to process in multiples of 1 (bytes); 1,024
(kilobytes); 1,048,576 (megabytes); or 1,073,741,824 (gigabytes). For example, a value
of 8 specifies the 8th observation, and a value of 3k specifies 3,072.
hexX
specifies the number of the first observation to process as a hexadecimal value. You
must specify the value beginning with a number (0-9), followed by an X. For example,
the value 2dx sets the 45th observation as the first observation to process.
MIN
sets the number of the first observation to process to 1. This is the default.
MAX
sets the number of the first observation to process to the maximum number of
observations in the data set, up to the largest eight-byte, signed integer, which is
63
2 -1, or approximately 9.2 quintillion observations.
26
FIRSTOBS= Data Set Option
4
Chapter 2
Details
The FIRSTOBS= data set option affects a single, existing SAS data set. Use the
FIRSTOBS= system option to affect all steps for the duration of your current SAS
session.
FIRSTOBS= is valid for input (read) processing only. Specifying FIRSTOBS= is not
valid for output or update processing.
You can apply FIRSTOBS= processing to WHERE processing. For more information,
see “Processing a Segment of Data That Is Conditionally Selected” in SAS Language
Reference: Concepts.
Comparisons
3 The FIRSTOBS= data set option overrides the FIRSTOBS= system option for the
individual data set.
3 While the FIRSTOBS= data set option specifies a starting point for processing, the
OBS= data set option specifies an ending point. The two options are often used
together to define a range of observations to be processed.
3 When external files are read, the FIRSTOBS= option in the INFILE statement
specifies which record to read first.
Examples
This PROC step prints the data set STUDY beginning with observation 20:
proc print data=study(firstobs=20);
run;
This SET statement uses both FIRSTOBS= and OBS= to read-only observations 5
through 10 from the data set STUDY. Data set NEW contains six observations.
data new;
set study(firstobs=5 obs=10);
run;
See Also
Data Set Options:
“OBS= Data Set Option” on page 38
Statements:
“INFILE Statement” on page 1526
“WHERE Statement” on page 1728
System Options:
“FIRSTOBS= System Option” on page 1841
SAS Data Set Options
4
GENMAX= Data Set Option
27
GENMAX= Data Set Option
Requests generations for a new data set, modifies the number of generations for an existing data
set, and specifies the maximum number of versions.
Valid in:
DATA step and PROC steps
Category: Data Set Control
Restriction:
Use with output data sets only.
Syntax
GENMAX=number-of-generations
Syntax Description
number-of-generations
requests generations for a data set and specifies the maximum number of versions to
maintain. The value can be from 0 to 1000. The default is GENMAX=0, which means
that no generation data sets are requested.
Details
You use GENMAX= to request generations for a new data set and to modify the number
of generations for an existing data set. The first time the data set is replaced, SAS
keeps the replaced version and appends a four-character version number to its member
name, which includes # and a three-digit number. For example, for a data set named A,
a historical version would be A#001.
After generations of a data set are requested, the member name is limited to 28
characters (rather than 32), because the last four characters are reserved for the
appended version number. When the GENMAX= data set option is set to 0, the member
name can be up to 32 characters.
If you reduce the number of generations for an existing data set, SAS deletes the
oldest versions above the new limit.
Examples
Example 1: Requesting Generations When You Create a Data Set
This example shows
how to request generations for a new data set. The DATA step creates a data set named
WORK.A that can have as many as 10 generations (one current version and nine
historical versions):
data a(genmax=10);
x=1;
output;
run;
28
GENNUM= Data Set Option
4
Chapter 2
Example 2: Modifying the Number of Generations on an Existing Data Set
This
example shows how to change the number of generations on the data set MYLIB.A to 4:
proc datasets lib=mylib;
modify a(genmax=4);
run;
See Also
Data Set Option:
“GENNUM= Data Set Option” on page 28
“Understanding Generation Data Sets” in “SAS Data Files” in SAS Language
Reference: Concepts
GENNUM= Data Set Option
Specifies a particular generation of a SAS data set.
Valid in:
DATA step and PROC steps
Data Set Control
Category:
Restriction:
Use with input data sets only.
Syntax
GENNUM=integer
Syntax Description
integer
is a number that references a specific version from a generation group. Specifying a
positive number is an absolute reference to a specific generation number that is
appended to a data set’s name. Specifying a negative number is a relative reference
to a historical version in relation to the base version, from the youngest to the oldest.
Typically, a value of 0 refers to the current (base) version.
Note: The DATASETS procedure provides a variety of statements for which
specifying GENNUM= has additional functionality:
3 For the DATASETS and DELETE statements, GENNUM= supports the
additional values ALL, HIST, and REVERT.
3 For the CHANGE statement, GENNUM= supports the additional value ALL.
3 For the CHANGE statement, specifying GENNUM=0 refers to all versions
rather than just the base version.
4
SAS Data Set Options
4
IDXNAME= Data Set Option
29
Details
After generations for a data set have been requested using the GENMAX= data set
option, use GENNUM= to request a specific version. For example, specifying
GENNUM=3 refers to the historical version #003, while specifying GENNUM=-1 refers
to the youngest historical version.
Note that after 999 replacements, the youngest version would be #999. After 1,000
replacements, SAS rolls over the youngest version number to #000. Therefore, if you
want the historical version #000, specify GENNUM=1000.
Both an absolute reference and a relative reference refer to a specific version. A
relative reference does not skip deleted versions. Therefore, when working with a
generation group that includes one or more deleted versions, using a relative reference
results in an error if the version being referenced has been deleted. For example, if you
have the base version AIR and three historical versions (AIR#001, AIR#002, and
AIR#003) and you delete AIR#002, the following statements return an error, because
AIR#002 does not exist. SAS does not assume you mean AIR#003:
proc print data=air (gennum= -2);
run;
Examples
Example 1: Requesting a Version Using an Absolute Reference
This example prints
the historical version #003 for data set A, using an absolute reference:
proc print data=a(gennum=3);
run;
Example 2: Requesting A Version Using a Relative Reference
The following PRINT
procedure prints the data set three versions back from the base version:
proc print data=a(gennum=-3);
run;
See Also
Data Set Option:
“GENMAX= Data Set Option” on page 27
“Understanding Generation Data Sets” in “SAS Data Files” in SAS Language
Reference: Concepts
“The DATASETS Procedure” in Base SAS Procedures Guide
IDXNAME= Data Set Option
Directs SAS to use a specific index to match the conditions of a WHERE expression.
DATA step and PROC steps
Category: User Control of SAS Index Usage
Restriction: Use with input data sets only
Restriction: Mutually exclusive with IDXWHERE= data set option
Valid in:
30
IDXNAME= Data Set Option
4
Chapter 2
Syntax
b IDXNAME=index-name
Syntax Description
index-name
specifies the name (up to 32 characters) of a simple or composite index for the SAS
data set. SAS does not attempt to determine whether the specified index is the best
one or whether a sequential search might be more resource efficient.
Interaction: The specification is not a permanent attribute of the data set and is
valid only for the current use of the data set.
To request that IDXNAME= usage be noted in the SAS log, specify the system
option MSGLEVEL=I.
Tip:
Details
By default, to satisfy the conditions of a WHERE expression for an indexed SAS data
set, SAS identifies zero or more candidate indexes that could be used to optimize the
WHERE expression. From the list of candidate indexes, SAS determines the one that
provides the best performance, or rejects all of the indexes if a sequential pass of the
data is expected to be more efficient.
Because the index SAS selects might not always provide the best optimization, you
can direct SAS to use one of the candidate indexes by specifying the IDXNAME= data
set option. If you specify an index that SAS does not identify as a candidate index, then
IDXNAME= does not process the request. That is, IDXNAME= does not allow you to
specify an index that would produce incorrect results.
Comparisons
IDXWHERE= enables you to override the SAS decision about whether to use an index.
Example
This example uses the IDXNAME= data set option in order to direct SAS to use a
specific index to optimize the WHERE expression. SAS then disregards the possibility
that a sequential search of the data set might be more resource efficient and does not
attempt to determine whether the specified index is the best one. (Note that the
EMPNUM index was not created with the NOMISS option.)
data mydata.empnew;
set mydata.employee (idxname=empnum);
where empnum < 2000;
run;
SAS Data Set Options
4
IDXWHERE= Data Set Option
31
See Also
Data Set Option:
“IDXWHERE= Data Set Option” on page 31
“Using an Index for WHERE Processing” in SAS Language Reference: Concepts
“WHERE-Expression Processing” in SAS Language Reference: Concepts
IDXWHERE= Data Set Option
Specifies whether SAS uses an index search or a sequential search to match the conditions of a
WHERE expression.
Valid in:
DATA step and PROC steps
Category: User Control of SAS Index Usage
Restriction:
Restriction:
Use with input data sets only.
Mutually exclusive with IDXNAME= data set option
Syntax
IDXWHERE=YES | NO
Syntax Description
YES
tells SAS to choose the best index to optimize a WHERE expression, and to disregard
the possibility that a sequential search of the data set might be more
resource-efficient.
NO
tells SAS to ignore all indexes and satisfy the conditions of a WHERE expression
with a sequential search of the data set.
Note: You cannot use IDXWHERE= to override the use of an index to process a
BY statement. 4
Details
By default, to satisfy the conditions of a WHERE expression for an indexed SAS data
set, SAS decides whether to use an index or to read the data set sequentially. The
software estimates the relative efficiency and chooses the method that is more efficient.
You might need to override the software’s decision by specifying the IDXWHERE=
data set option because the decision is based on general rules that might occasionally
not produce the best results. That is, by specifying the IDXWHERE= data set option,
you are able to determine the processing method.
Note: The specification is not a permanent attribute of the data set and is valid only
for the current use of the data set. 4
Note: If you issue the system option MSGLEVEL=I, you can request that
IDXWHERE= usage be noted in the SAS log if the setting affects index processing.
4
32
IN= Data Set Option
4
Chapter 2
Comparisons
IDXNAME= enables you to direct SAS to use a specific index.
Examples
Example 1: Specifying Index Usage
This example uses the IDXWHERE= data set
option to tell SAS to decide which index is the best to optimize the WHERE expression.
SAS then disregards the possibility that a sequential search of the data set might be
more resource-efficient:
data mydata.empnew;
set mydata.employee (idxwhere=yes);
where empnum < 2000;
Example 2: Specifying No Index Usage
This example uses the IDXWHERE= data set
option to tell SAS to ignore any index and to satisfy the conditions of the WHERE
expression with a sequential search of the data set:
data mydata.empnew;
set mydata.employee (idxwhere=no);
where empnum < 2000;
See Also
Data Set Option:
“IDXNAME= Data Set Option” on page 29
“Understanding SAS Indexes” in the “SAS Data Files” section in SAS Language
Reference: Concepts
“WHERE-Expression Processing” in SAS Language Reference: Concepts
IN= Data Set Option
Creates a Boolean variable that indicates whether the data set contributed data to the current
observation.
DATA step
Category: Observation Control
Valid in:
Restriction:
Use with the SET, MERGE, MODIFY, and UPDATE statements only.
Syntax
IN=variable
SAS Data Set Options
4
IN= Data Set Option
33
Syntax Description
variable
names the new variable whose value indicates whether that input data set
contributed data to the current observation. Within the DATA step, the value of the
variable is 1 if the data set contributed to the current observation, and 0 otherwise.
Details
Specify the IN= data set option in parentheses after a SAS data set name in the SET,
MERGE, MODIFY, and UPDATE statements only. Values of IN= variables are available
to program statements during the DATA step, but the variables are not included in the
SAS data set that is being created, unless they are assigned to a new variable.
When you use IN= with BY–group processing, and when a data set contributes an
observation for the current BY group, the IN= value is 1. The value remains as long as
that BY group is still being processed and the value is not reset by programming logic.
Examples
In this example, IN= creates a new variable, OVERSEAS, that denotes international
flights. The variable I has a value of 1 when the observation is read from the NONUSA
data set. Otherwise, it has a value of 0. The IF-THEN statement checks the value of I
to determine whether the data set NONUSA contributed data to the current
observation. If I=1, the variable OVERSEAS receives an asterisk (*) as a value.
data allflts;
set usa nonusa(in=i);
by fltnum;
if i then overseas=’*’;
run;
See Also
Statements:
“BY Statement” on page 1388
“MERGE Statement” on page 1615
“MODIFY Statement” on page 1620
“SET Statement” on page 1700
“UPDATE Statement” on page 1723
“BY-Group Processing” in SAS Language Reference: Concepts
34
INDEX= Data Set Option
4
Chapter 2
INDEX= Data Set Option
Defines an index for a new output SAS data set.
DATA step and PROC steps
Category: Data Set Control
Restriction: Use with output data sets only.
Valid in:
Syntax
INDEX=(index-specification-1 ...< index-specification-n>)
Syntax Description
index-specification
names and describes a simple or a composite index to be built. Index-specification
has this form:
index= (variable(s) </UNIQUE> </NOMISS>)
index
is the name of a variable that forms the index or the name you choose for a
composite index.
variable or variables
is a list of variables to use in making a composite index.
UNIQUE
specifies that the values of the key variables must be unique. If you specify
UNIQUE for a new data set and multiple observations have the same values for
the index variables, the index is not created. A slash (/) must precede the
UNIQUE option.
NOMISS
excludes all observations with missing values from the index. Observations with
missing values are still read from the data set but not through the index. A slash
(/) must precede the NOMISS option.
Examples
Example 1: Defining a Simple Index
The following INDEX= data set option defines a
simple index for the SSN variable:
data new(index=(ssn));
Example 2: Defining a Composite Index
The following INDEX= data set option defines
a composite index named CITYST that uses the CITY and STATE variables:
data new(index=(cityst=(city state)));
Example 3: Defining a Simple and a Composite Index
The following INDEX= data set
option defines a simple index for SSN and a composite index for CITY and STATE:
data new(index=(ssn cityst=(city state)));
SAS Data Set Options
4
KEEP= Data Set Option
35
Example 4: Defining a Simple Index with the UNIQUE Option
The following INDEX=
data set option defines a simple index for the SSN variable with unique values:
data new(index=(ssn /unique));
Example 5: Defining a Simple Index with the NOMISS Option
The following INDEX=
data set option defines a simple index for the SSN variable, excluding all observations
with missing values from the index:
data new(index=(ssn /nomiss));
Example 6: Defining Multiple Indexes Using the UNIQUE and NOMISS Options
The
following INDEX= data set option defines a simple index for the SSN variable and a
composite index for CITY and STATE. Each variable must have a UNIQUE and
NOMISS option:
data new(index=(ssn /unique/nomiss cityst=(city state)/unique/nomiss));
See Also
INDEX CREATE statement in “The DATASETS Procedure” in Base SAS Procedures
Guide
CREATE INDEX statement in “The SQL Procedure” in Base SAS Procedures Guide
“Understanding SAS Indexes” in the “SAS Data Files” section of SAS Language
Reference: Concepts
KEEP= Data Set Option
For an input data set, specifies the variables to process; for an output data set, specifies the
variables to write to the data set.
DATA step and PROC steps
Category: Variable Control
Valid in:
Syntax
KEEP=variable-1 <...variable-n>
Syntax Description
variable-1 <...variable-n>
lists one or more variable names. You can list the variables in any form that SAS
allows.
Details
If the KEEP= data set option is associated with an input data set, only those variables
that are listed after the KEEP= data set option are available for processing. If the
36
LABEL= Data Set Option
4
Chapter 2
KEEP= data set option is associated with an output data set, only the variables listed
after the option are written to the output data set, but all variables are available for
processing.
Comparisons
3 The KEEP= data set option differs from the KEEP statement in the following ways:
3 In DATA steps, the KEEP= data set option can apply to both input and
output data sets. The KEEP statement applies only to output data sets.
3 In DATA steps, when you create multiple output data sets, use the KEEP=
data set option to write different variables to different data sets. The KEEP
statement applies to all output data sets.
3 In PROC steps, you can use only the KEEP= data set option, not the KEEP
statement.
3 The DROP= data set option specifies variables to omit during processing or to omit
from the output data set.
Example
In this example, only IDNUM and SALARY are read from PAYROLL, and they are
the only variables in PAYROLL that are available for processing:
data bonus;
set payroll(keep=idnum salary);
bonus=salary*1.1;
run;
See Also
Data Set Options:
“DROP= Data Set Option” on page 21
Statements:
“KEEP Statement” on page 1584
LABEL= Data Set Option
Specifies a label for a SAS data set.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Syntax
LABEL=’label’
SAS Data Set Options
4
LABEL= Data Set Option
37
Syntax Description
’label’
specifies a text string of up to 256 characters. If the label text contains single
quotation marks, use double quotation marks around the label, or use two single
quotation marks in the label text and surround the string with single quotation
marks. To remove a label from a data set, assign a label that is equal to a blank that
is enclosed in quotation marks.
Details
You can use the LABEL= option on both input and output data sets. When you use
LABEL= on input data sets, it assigns a label for the file for the duration of that DATA
or PROC step. When it is specified for an output data set, the label becomes a
permanent part of that file and can be printed using the CONTENTS or DATASETS
procedure, and modified using PROC DATASETS.
A label assigned to a data set remains associated with that data set when you update
a data set in place, such as when you use the APPEND procedure or the MODIFY
statement. However, a label is lost if you use a data set with a previously assigned label
to create a new data set in the DATA step. For example, a label previously assigned to
data set ONE is lost when you create the new output data set ONE in this DATA step:
data one;
set one;
run;
Comparisons
3 The LABEL= data set option enables you to specify labels only for data sets. You
can specify labels for the variables in a data set using the LABEL statement.
3 The LABEL= option in the ATTRIB statement also enables you to assign labels to
variables.
Examples
These examples assign labels to data sets:
data w2(label=’1976 W2 Info, Hourly’);
data new(label=’Peter’’s List’);
data new(label="Hillside’s Daily Account");
data sales(label=’Sales For May(NE)’);
38
OBS= Data Set Option
4
Chapter 2
See Also
Statements:
“ATTRIB Statement” on page 1384
“LABEL Statement” on page 1586
“MODIFY Statement” on page 1620
“The CONTENTS Procedure” in Base SAS Procedures Guide
“The DATASETS Procedure” in Base SAS Procedures Guide
OBS= Data Set Option
Specifies the last observation that SAS processes in a data set.
Valid in:
DATA step and PROC steps
Observation Control
Category:
Default:
MAX
Restriction:
Use with input data sets only
Restriction:
Cannot use with PROC SQL views
Syntax
OBS= n | nK | nM | nG | nT | hexX | MIN | MAX
Syntax Description
n | nK | nM | nG | nT
specifies a number to indicate when to stop processing observations, with n being an
integer. Using one of the letter notations results in multiplying the integer by a
specific value. That is, specifying K (kilo) multiplies the integer by 1,024, M (mega)
multiplies by 1,048,576, G (giga) multiplies by 1,073,741,824, or T (tera) multiplies
by 1,099,511,627,776. For example, a value of 20 specifies 20 observations, while a
value of 3m specifies 3,145,728 observations.
hexX
specifies a number to indicate when to stop processing as a hexadecimal value. You
must specify the value beginning with a number (0–9), followed by an X. For
example, the hexadecimal value F8 must be specified as 0F8x in order to specify the
decimal equivalent of 248. The value 2dx specifies the decimal equivalent of 45.
MIN
sets the number to indicate when to stop processing to 0. Use OBS=0 in order to
create an empty data set that has the structure, but not the observations, of another
data set.
Interaction: If OBS=0 and the NOREPLACE option is in effect, then SAS can still
take certain actions because it actually executes each DATA and PROC step in the
SAS Data Set Options
4
OBS= Data Set Option
39
program, using no observations. For example, SAS executes procedures, such as
CONTENTS and DATASETS, that process libraries or SAS data sets.
MAX
sets the number to indicate when to stop processing to the maximum number of
63
observations in the data set, up to the largest 8-byte, signed integer, which is 2 -1, or
approximately 9.2 quintillion. This is the default.
Details
OBS= tells SAS when to stop processing observations. To determine when to stop
processing, SAS uses the value for OBS= in a formula that includes the value for OBS=
and the value for FIRSTOBS=. The formula is
(obs - firstobs) + 1 = results
For example, if OBS=10 and FIRSTOBS=1 (which is the default for FIRSTOBS=),
the result is ten observations, that is (10 - 1) + 1 = 10. If OBS=10 and
FIRSTOBS=2, the result is nine observations, that is (10 - 2) + 1 = 9. OBS= is
valid only when an existing SAS data set is read.
Comparisons
3 The OBS= data set option overrides the OBS= system option for the individual
data set.
3 While the OBS= data set option specifies an ending point for processing, the
FIRSTOBS= data set option specifies a starting point. The two options are often
used together to define a range of observations to be processed.
3 The OBS= data set option enables you to select observations from SAS data sets.
You can select observations to be read from external data files by using the OBS=
option in the INFILE statement.
Examples
Example 1: Using OBS= to Specify When to Stop Processing Observations
This
example illustrates the result of using OBS= to tell SAS when to stop processing
observations. This example creates a SAS data set and executes the PRINT procedure
with FIRSTOBS=2 and OBS=12. The result is 11 observations, that is (12 - 2) + 1 =
11. The result of OBS= in this situation appears to be the observation number that
SAS processes last, because the output starts with observation 2, and ends with
observation 12. This situation is only a coincidence.
data Ages;
input Name $ Age;
datalines;
Miguel 53
Brad 27
Willie 69
Marc 50
Sylvia 40
Arun 25
Gary 40
Becky 51
Alma 39
Tom 62
40
OBS= Data Set Option
4
Chapter 2
Kris 66
Paul 60
Randy 43
Barbara 52
Virginia 72
;
proc print data=Ages (firstobs=2 obs=12);
run;
Output 2.1
PROC PRINT Output Using OBS= and FIRSTOBS=
The SAS System
Obs
2
3
4
5
6
7
8
9
10
11
12
Name
1
Age
Brad
Willie
Marc
Sylvia
Arun
Gary
Becky
Alma
Tom
Kris
Paul
27
69
50
40
25
40
51
39
62
66
60
Example 2: Using OBS= with WHERE Processing
This example illustrates the result of
using OBS= along with WHERE processing. The example uses the data set that was
created in Example 1, which contains 15 observations.
First, here is the PRINT procedure with a WHERE statement. The subset of the
data results in 12 observations:
proc print data=Ages;
where Age LT 65;
run;
Output 2.2
PROC PRINT Output Using a WHERE Statement
The SAS System
Obs
1
2
4
5
6
7
8
9
10
12
13
14
Name
Miguel
Brad
Marc
Sylvia
Arun
Gary
Becky
Alma
Tom
Paul
Randy
Barbara
1
Age
53
27
50
40
25
40
51
39
62
60
43
52
Executing the PRINT procedure with the WHERE statement and OBS=10 results in
10 observations, that is (10 - 1) + 1 = 10. Note that with WHERE processing, SAS
first subsets the data and applies OBS= to the subset.
SAS Data Set Options
4
OBS= Data Set Option
41
proc print data=Ages (obs=10);
where Age LT 65;
run;
Output 2.3 PROC PRINT Output Using a WHERE Statement and OBS=
The SAS System
Obs
1
2
4
5
6
7
8
9
10
12
Name
2
Age
Miguel
Brad
Marc
Sylvia
Arun
Gary
Becky
Alma
Tom
Paul
53
27
50
40
25
40
51
39
62
60
The result of OBS= appears to be how many observations to process, because the
output consists of 10 observations, ending with the observation number 12. However,
the result is only a coincidence. If you apply FIRSTOBS=2 and OBS=10 to the subset,
then the result is nine observations, that is (10 - 2) + 1 = 9. OBS= in this situation
is neither the observation number to end with nor how many observations to process;
the value is used in the formula to determine when to stop processing.
proc print data=Ages (firstobs=2 obs=10);
where Age LT 65;
run;
Output 2.4 PROC PRINT Output Using WHERE Statement, OBS=, and FIRSTOBS=
The SAS System
Obs
2
4
5
6
7
8
9
10
12
Name
Brad
Marc
Sylvia
Arun
Gary
Becky
Alma
Tom
Paul
3
Age
27
50
40
25
40
51
39
62
60
Example 3: Using OBS= When Observations Are Deleted
This example illustrates the
result of using OBS= for a data set that has deleted observations. The example uses the
data set that was created in Example 1, with observation 6 deleted.
First, here is PROC PRINT output of the modified file:
proc print data=Ages;
run;
42
OBS= Data Set Option
4
Output 2.5
Chapter 2
PROC PRINT Output Showing Observation 6 Deleted
The SAS System
Obs
1
Name
1
2
3
4
5
7
8
9
10
11
12
13
14
15
Age
Miguel
Brad
Willie
Marc
Sylvia
Gary
Becky
Alma
Tom
Kris
Paul
Randy
Barbara
Virginia
53
27
69
50
40
40
51
39
62
66
60
43
52
72
Executing the PRINT procedure with OBS=12 results in 12 observations, that is (12
- 1) + 1 = 12:
proc print data=Ages (obs=12);
run;
Output 2.6
PROC PRINT Output Using OBS=
The SAS System
Obs
1
2
3
4
5
7
8
9
10
11
12
13
Name
2
Age
Miguel
Brad
Willie
Marc
Sylvia
Gary
Becky
Alma
Tom
Kris
Paul
Randy
53
27
69
50
40
40
51
39
62
66
60
43
The result of OBS= appears to be how many observations to process, because the
output consists of 12 observations, ending with the observation number 13. However, if
you apply FIRSTOBS=2 and OBS=12, the result is 11 observations, that is (12 - 2) +
1 = 11. OBS= in this situation is neither the observation number to end with nor how
many observations to process; the value is used in the formula to determine when to
stop processing.
proc print data=Ages (firstobs=2 obs=12);
run;
SAS Data Set Options
4
OBSBUF= Data Set Option
43
Output 2.7 PROC PRINT Output Using OBS= and FIRSTOBS=
The SAS System
Obs
2
3
4
5
7
8
9
10
11
12
13
Name
Brad
Willie
Marc
Sylvia
Gary
Becky
Alma
Tom
Kris
Paul
Randy
3
Age
27
69
50
40
40
51
39
62
66
60
43
See Also
Data Set Options:
“FIRSTOBS= Data Set Option” on page 25
Statements:
“INFILE Statement” on page 1526
“WHERE Statement” on page 1728
System Options:
“OBS= System Option” on page 1881
For more information about using OBS= with WHERE processing, see “Processing a
Segment of Data That Is Conditionally Selected” in SAS Language Reference:
Concepts.
OBSBUF= Data Set Option
Determines the size of the view buffer for processing a DATA step view.
Valid in:
DATA step and PROC steps
Category: Data Set Control
Restriction:
Valid only for a DATA step view
Syntax
OBSBUF=n
Syntax Description
n
specifies the number of observations that are read into the view buffer at a time.
44
OBSBUF= Data Set Option
4
Chapter 2
Default: 32K bytes of memory are allocated for the default view buffer, which
means that the default number of observations that can be read into the view
buffer at one time depends on the observation length. Therefore, the default is the
number of observations that can fit into 32K bytes. If the observation length is
larger than 32K, then only one observation can be read into the buffer at a time.
To determine the observation length, which is its size in bytes, use PROC
CONTENTS for the DATA step view.
Tip:
CAUTION:
The maximum value for the OBSBUF= option depends on the amount of available
memory. If you specify a value so large that the memory allocation of the view
buffer fails, an out-of- memory error results. If you specify a value that is larger
than the amount of available real memory and your operating environment allows
SAS to perform the allocation using virtual memory, the result can be a decrease
in performance due to excessive paging. 4
Details
The OBSBUF= data set option specifies the number of observations that can be read
into the view buffer at a time. The view buffer is a segment of memory that is allocated
to hold output observations that are generated from a DATA step view. The size of the
buffer determines how much data can be held in memory at one time. OBSBUF=
enables you to tune the performance of reading data from a DATA step view.
The view buffer is shared between the request that opens the DATA step view (for
example, a SAS procedure) and the DATA step view itself. Two computer tasks
coordinate between requesting data and generating and returning the data as follows:
1 When a request task, such as a PRINT procedure, requests data, task switching
occurs from the request task to the view task in order to execute the DATA step
view and generate the observations. The DATA step view fills the view buffer with
as many observations as possible.
2 When the view buffer is full, task switching occurs from the view task back to the
request task in order to return the requested data. The observations are cleared
from the view buffer.
The size of the view buffer determines how many generated observations can be held.
The number of generated observations then determines how many times the computer
must switch between the request task and the view task. For example, OBSBUF=1
results in task switching for each observation, while OBSBUF=10 results in 10
observations being read into the view buffer at a time. The larger the view buffer is,
the less task switching is needed to process a DATA step view, which can speed up
execution time.
To improve efficiency, first determine how many observations fits into the default
buffer size, then set the view buffer so that it can hold more generated observations.
Note: Using OBSBUF= can improve processing efficiency by reducing task
switching. However, the larger the view buffer size, the more time it takes to fill. This
delays the task switching from the view task back to the request task in order to return
the requested data. The delay is more apparent in interactive applications. For
example, when you use the Viewtable window, the larger the view buffer, the longer it
takes to display the requested observations, because the view buffer must be filled
before even one observation is returned to the Viewtable. Therefore, before you set a
very large view buffer size, consider the type of application that you are using to process
the DATA step view as well as the amount of memory that you have available. 4
SAS Data Set Options
4
OUTREP= Data Set Option
45
Example
For this example, the observation length is 10K, which means that the default view
buffer size, which is 32K, would result in three observations at a time to be read into the
view buffer. The default view buffer size causes the execution time to be slower, because
the computer must do task switching for every three observations that are generated.
To improve performance, the OBSBUF= data set option is set to 100, which causes
one hundred observations at a time to be read into the view buffer and reduces task
switching in order to process the DATA step view with the PRINT procedure:
data testview / view=testview;
... more SAS statements ...
run;
proc print data=testview (obsbuf=100);
run;
See Also
Data Set Options:
“SPILL= Data Set Option” on page 58
OUTREP= Data Set Option
Specifies the data representation for the output SAS data set.
Valid in:
DATA step and PROC steps
Category: Data Set Control
See:
OUTREP= Data Set Option in the documentation for your operating environment.
Syntax
OUTREP=format
Syntax Description
format
specifies the data representation, which is the form in which data is stored in a
particular operating environment. Different operating environments use different
standards or conventions for storing floating-point numbers (for example, IEEE or
IBM Mainframe); for character encoding (ASCII or EBCDIC); for the ordering of
bytes in memory (big Endian or little Endian); for word alignment (4-byte boundaries
or 8-byte boundaries); for integer data-type length (16-bit, 32-bit, or 64-bit); and for
doubles (byte-swapped or not).
Native data representation refers to an environment in which the data
representation is comparable to the CPU that is accessing the file. For example, a
46
OUTREP= Data Set Option
4
Chapter 2
file that is in Windows data representation is native to the Windows operating
environment.
By default, SAS creates a new SAS data set by using the native data
representation of the CPU that is running SAS. Specifying the OUTREP= option
enables you to create a SAS data set within the native environment that uses a
foreign environment data representation. For example, in a UNIX environment, you
can create a SAS data set that uses Windows data representation.
Values for OUTREP= are listed in the following table:
Table 2.2 Data Representation Values for OUTREP= Option
OUTREP= Value
Alias*
Environment
ALPHA_TRU64
ALPHA_OSF
Tru64 UNIX
ALPHA_VMS_32
ALPHA_VMS
OpenVMS on Alpha
ALPHA_VMS_64
OpenVMS on Alpha
HP_IA64
HP_ITANIUM
HP-UX on Itanium 64-bit platform
HP_UX_32
HP_UX
HP-UX on 32-bit platform
HP_UX_64
HP-UX on 64-bit platform
INTEL_ABI
ABI UNIX on Intel 32-bit platform
LINUX_32
LINUX
Linux for Intel Architecture on 32-bit
platform
LINUX_IA64
Linux for Itanium-based system on
64-bit platform
LINUX_X86_64
LINUX on x64 64-bit platform
MIPS_ABI
ABI UNIX on 32-bit platform
MVS_32
MVS
OS2
RS_6000_AIX_32
OS/2 on Intel 32-bit platform
RS_6000_AIX
RS_6000_AIX_64
SOLARIS_32
z/OS on 32-bit platform
AIX UNIX on 32-bit RS/6000
AIX UNIX on 64-bit RS/6000
SOLARIS
Solaris on SPARC 32-bit platform
SOLARIS_64
Solaris on SPARC 64-bit platform
SOLARIS_X86_64
Solaris on x64 64-bit platform
VAX_VMS
OpenVMS VAX
VMS_IA64
OpenVMS for HP Integrity servers
64-bit platform
WINDOWS_32
WINDOWS_64
WINDOWS
Microsoft Windows on 32-bit platform
Microsoft Windows 64-bit Edition (for
both Itanium-based systems and x64)
* It is recommended that you use the current values. The aliases are available for compatibility
only.
SAS Data Set Options
4
POINTOBS= Data Set Option
47
Details
CAUTION:
Transcoding could result in character data loss when encodings are incompatible. For
information about encoding and transcoding, see SAS National Language Support
(NLS): Reference Guide. 4
See Also
Statements:
OUTREP= option in “LIBNAME Statement” on page 1592
“Processing Data Using Cross-Environment Data Access (CEDA)” in SAS Language
Reference: Concepts
POINTOBS= Data Set Option
Specifies whether SAS creates compressed data sets whose observations can be randomly
accessed or sequentially accessed.
Valid in:
DATA step and PROC steps
Category: Observation Control
Restriction: POINTOBS= is effective only when creating a compressed data set.
Otherwise it is ignored.
Syntax
POINTOBS=YES | NO
Syntax Description
YES
causes SAS software to produce a compressed data set that might be randomly
accessed by observation number. This is the default.
Examples of accessing data directly by observation number are:
3 the POINT= option of the MODIFY and SET statements in the DATA step
3 going directly to a specific observation number with PROC FSEDIT.
Specifying POINTOBS=YES does not affect the efficiency of retrieving
information from a data set, but it does increase CPU usage by approximately 10%
when creating a compressed data set and when updating or adding information to
it.
Tip:
NO
suppresses the ability to randomly access observations in a compressed data set by
observation number.
48
PW= Data Set Option
4
Chapter 2
Specifying POINTOBS=NO is desirable for applications where the ability to
point directly to an observation by number within a compressed data set is not
important.
If you do not need to access data by observation number, then you can improve
performance by approximately 10% when creating a compressed data set and
when updating or adding observations to it by specifying POINTOBS=NO.
Tip:
Details
Note that REUSE=YES takes precedence over POINTOBS=YES. For example:
data test(compress=yes pointobs=yes reuse=yes);
results in a data set that has POINTOBS=NO. Because POINTOBS=YES is the default
when you use compression, REUSE=YES causes POINTOBS= to change to NO.
See Also
Data Set Options:
“COMPRESS= Data Set Option” on page 19
“REUSE= Data Set Option” on page 55
System Options:
“COMPRESS= System Option” on page 1806
“REUSE= System Option” on page 1915
PW= Data Set Option
Assigns a READ, WRITE, and ALTER password to a SAS file, and enables access to a
password-protected SAS file.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
See:
under UNIX in the documentation for your operating environment.
Syntax
PW=password
Syntax Description
password
must be a valid SAS name. See “Rules for Words and Names in the SAS Language”
in SAS Language Reference: Concepts.
SAS Data Set Options
4
PWREQ= Data Set Option
49
Details
The PW= option applies to all types of SAS files except catalogs. You can use this option
to assign a password to a SAS file or to access a password-protected SAS file.
When replacing a SAS data set that is protected by an ALTER password, the new
data set inherits the ALTER password. To change the ALTER password for the new
data set, use the MODIFY statement in the DATASETS procedure.
Operating Environment Information: See the appropriate sections of the SAS
documentation for your operating environment for more information about using
passwords. 4
Note: A SAS password does not control access to a SAS file beyond the SAS system.
You should use the operating system-supplied utilities and file-system security controls
in order to control access to SAS files outside of SAS. 4
See Also
Data Set Options:
“ALTER= Data Set Option” on page 14
“ENCRYPT= Data Set Option” on page 23
“READ= Data Set Option” on page 50
“WRITE= Data Set Option” on page 70
“Manipulating Passwords” in “The DATASETS Procedure” in Base SAS Procedures
Guide
“File Protection” in SAS Language Reference: Concepts
PWREQ= Data Set Option
Specifies whether to display a dialog box to enter a SAS data set password.
Valid in:
DATA and PROC steps
Category: Data Set Control
Syntax
PWREQ=YES | NO
Syntax Description
YES
specifies to display a dialog box.
NO
prevents a dialog box from displaying. If a missing or invalid password is entered,
the data set is not opened and an error message is written to the SAS log.
50
4
READ= Data Set Option
Chapter 2
Details
In an interactive SAS session, the PWREQ= option controls whether a dialog box
displays after a user enters an incorrect or a missing password for a SAS data set that
is password protected. PWREQ= applies to data sets with read, write, or alter
passwords. PWREQ= is most useful in SCL applications.
See Also
Data Set Options:
“ALTER= Data Set Option” on page 14
“ENCRYPT= Data Set Option” on page 23
“PW= Data Set Option” on page 48
“READ= Data Set Option” on page 50
“WRITE= Data Set Option” on page 70
READ= Data Set Option
Assigns a READ password to a SAS file that prevents users from reading the file, unless they enter
the password.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Syntax
READ=read-password
Syntax Description
read-password
must be a valid SAS name. See “Rules for Words and Names in the SAS Language”
in SAS Language Reference: Concepts.
Details
The READ= option applies to all types of SAS files except catalogs. You can use this
option to assign a password to a SAS file or to access a read-protected SAS file.
Note: A SAS password does not control access to a SAS file beyond the SAS system.
You should use the operating system-supplied utilities and file-system security controls
in order to control access to SAS files outside of SAS. 4
SAS Data Set Options
4
RENAME= Data Set Option
51
See Also
Data Set Options:
“ALTER= Data Set Option” on page 14
“ENCRYPT= Data Set Option” on page 23
“PW= Data Set Option” on page 48
“WRITE= Data Set Option” on page 70
“Manipulating Passwords” in “The DATASETS Procedure” in Base SAS Procedures
Guide
“File Protection” in SAS Language Reference: Concepts
RENAME= Data Set Option
Changes the name of a variable.
Valid in:
DATA step and PROC steps
Category: Variable Control
Syntax
RENAME=(old-name-1=new-name-1 < ...old-name-n=new-name-n>)
Syntax Description
old-name
the variable you want to rename.
new-name
the new name of the variable. It must be a valid SAS name.
Details
If you use the RENAME= data set option when you create a data set, the new variable
name is included in the output data set. If you use RENAME= on an input data set, the
new name is used in DATA step programming statements.
If you use RENAME= on an input data set that is used in a SAS procedure, SAS
changes the name of the variable in that procedure. If you use RENAME= with
WHERE processing such as a WHERE statement or a WHERE= data set option, the
new name is applied before the data is processed. You must use the new name in the
WHERE expression.
If you use RENAME= in the same DATA step with either the DROP= or the KEEP=
data set option, the DROP= and the KEEP= data set options are applied before
RENAME=. You must use the old name in the DROP= and KEEP= data set options.
You cannot drop and rename the same variable in the same statement.
Note: The RENAME= data set option has an effect only on data sets that are
opened in output mode. 4
52
RENAME= Data Set Option
4
Chapter 2
Comparisons
3 The RENAME= data set option differs from the RENAME statement in the
following ways:
3 The RENAME= data set option can be used in PROC steps and the RENAME
statement cannot.
3 The RENAME statement applies to all output data sets. If you want to
rename different variables in different data sets, you must use the
RENAME= data set option.
3 To rename variables before processing begins, you must use a RENAME=
data set option on the input data set or data sets.
3 Use the RENAME statement or the RENAME= data set option when program
logic requires that you rename variables such as two input data sets that have
variables with the same name. To rename variables as a file management task,
use the DATASETS procedure.
Examples
Example 1: Renaming a Variable at Time of Output
This example uses RENAME= in
the DATA statement to show that the variable is renamed at the time it is written to
the output data set. The variable keeps its original name, X, during the DATA step
processing:
data two(rename=(x=keys));
set one;
z=x+y;
run;
Example 2: Renaming a Variable at Time of Input
This example renames variable X to
a variable named KEYS in the SET statement, which is a rename before DATA step
processing. KEYS, not X, is the name to use for the variable for DATA step processing.
data three;
set one(rename=(x=keys));
z=keys+y;
run;
Example 3: Renaming a Variable for a SAS Procedure with WHERE Processing
This
example renames variable Score1 to a variable named Score2 for the PRINT procedure.
Because the new name is applied before the data is processed, the new name must be
specified in the WHERE statement.
proc print data=test (rename=(score1=score2));
where score2 gt 75;
run;
See Also
Data Set Options:
“DROP= Data Set Option” on page 21
“KEEP= Data Set Option” on page 35
Statements:
“RENAME Statement” on page 1680
“The DATASETS Procedure” in Base SAS Procedures Guide
SAS Data Set Options
4
REPEMPTY= Data Set Option
53
REPEMPTY= Data Set Option
Specifies whether a new, empty data set can overwrite an existing SAS data set that has the same
name.
DATA step and PROC steps
Valid in:
Category: Data Set Control
Restriction:
Use with output data sets only.
Syntax
REPEMPTY=YES | NO
Syntax Description
YES
specifies that a new empty data set with a given name replaces an existing data set
with the same name. This is the default.
Interaction: When REPEMPTY=YES and REPLACE=NO, then the data set is not
replaced.
NO
specifies that a new empty data set with a given name does not replace an existing
data set with the same name.
Use REPEMPTY=NO to prevent the following syntax error from replacing the
existing data set B with the new empty data set B that is created by mistake:
Tip:
data mylib.a set b;
For both the convenience of replacing existing data sets with new ones that
contain data and the protection of not overwriting existing data sets with new
empty ones that are created by accident, set REPLACE=YES and
REPEMPTY=NO.
Tip:
Comparisons
3 For an individual data set, the REPEMPTY= data set option overrides the
REPEMPTY= option in the LIBNAME statement.
3 The REPEMPTY= and REPLACE= data set options apply to both permanent and
temporary SAS data sets. The REPLACE system option, however, only applies to
permanent SAS data sets.
See Also
Data Set Options:
“REPLACE= Data Set Option” on page 54
Statement Options:
REPEMPTY= in the LIBNAME statement on page 1596
54
REPLACE= Data Set Option
4
Chapter 2
System Options:
“REPLACE System Option” on page 1914
REPLACE= Data Set Option
Specifies whether a new SAS data set that contains data can overwrite an existing data set that
has the same name.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Use with output data sets only.
Restriction: This option is valid only when creating a SAS data set.
Restriction:
Syntax
REPLACE=NO | YES
Syntax Description
NO
specifies that a new data set with a given name does not replace an existing data set
with the same name.
YES
specifies that a new data set with a given name replaces an existing data set with
the same name.
Comparisons
3 The REPLACE= data set option overrides the REPLACE system option for the
individual data set.
3 The REPLACE system option only applies to permanent SAS data sets.
Example
Using the REPLACE= data set option in this DATA statement prevents SAS from
replacing a permanent SAS data set named ONE in a library referenced by MYLIB:
data mylib.one(replace=no);
SAS writes a message in the log that tells you that the file has not been replaced.
SAS Data Set Options
4
REUSE= Data Set Option
55
See Also
System Options:
“REPLACE System Option” on page 1914
REUSE= Data Set Option
Specifies whether new observations can be written to freed space in compressed SAS data sets.
Valid in:
DATA step and PROC steps
Category: Data Set Control
Restriction:
Use with output data sets only.
Syntax
REUSE=NO | YES
Syntax Description
NO
does not track and reuse space in compressed data sets. New observations are
appended to the existing data set. Specifying the NO argument results in less
efficient data storage if you delete or update many observations in the SAS data set.
YES
tracks and reuses space in compressed SAS data sets. New observations are inserted
in the space that is freed when other observations are updated or deleted.
If you plan to use procedures that add observations to the end of SAS data sets
(for example, the APPEND and FSEDIT procedures) with compressed data sets, use
the REUSE=NO argument. REUSE=YES causes new observations to be added
wherever there is space in the file, not necessarily at the end of the file.
Details
By default, new observations are appended to existing compressed data sets. If you
want to track and reuse free space by deleting or updating other observations, use the
REUSE= data set option when you create a compressed SAS data set.
REUSE= has meaning only when you are creating new data sets with the
COMPRESS=YES data set option or system option. Using the REUSE= data set option
when you are accessing an existing SAS data set has no effect.
Comparisons
The REUSE= data set option overrides the REUSE= system option.
REUSE=YES takes precedence over POINTOBS=YES. For example, the following
statement results in a data set that has POINTOBS=NO:
data test(compress=yes pointobs=yes reuse=yes);
56
SORTEDBY= Data Set Option
4
Chapter 2
Because POINTOBS=YES is the default when you use compression, REUSE=YES
causes POINTOBS= to change to NO.
See Also
Data Set Options:
“COMPRESS= Data Set Option” on page 19
System Options:
“REUSE= System Option” on page 1915
SORTEDBY= Data Set Option
Specifies how a data set is currently sorted.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Syntax
SORTEDBY=by-clause </ collate-name> | _NULL_
Syntax Description
by-clause < / collate-name>
indicates how the data is currently sorted.
by-clause
names the variables and options that you use in a BY statement
in a PROC SORT step.
collate-name
names the collating sequence that is used for the sort. By default,
the collating sequence is that of your operating environment. A
slash (/) must precede the collating sequence.
Operating Environment Information: For details about collating
sequences, see the SAS documentation for your operating
environment. 4
_NULL_
removes any existing sort indicator.
Details
SAS determines whether a data set is already sorted by the key variable or variables in
ascending order by checking the sort indicator. The sort indicator is stored in the data
set descriptor information and is set from a previous sort. For detailed information
about how the sort indicator is used and how it improves performance, see “The Sort
Indicator” in SAS Language Reference: Concepts and the “SORTVALIDATE= System
Option” in the SAS Language Reference: Dictionary.
SAS Data Set Options
4
SORTEDBY= Data Set Option
57
The following example of the CONTENTS procedure Sort Information section
containing the Validated attribute set to NO, indicates that the data set was sorted
using the SORTEDBY= data set option.
Sort Information
Sortedby var1
Validated NO
Character Set ANSI
Comparisons
3 Use the CONTENTS statement in the DATASETS procedure to see how a data set
is sorted.
3 The SORTEDBY= option indicates how the data is sorted, but does not cause a
data set to be sorted.
Examples
This example uses the SORTEDBY= data set option to specify how the data are
currently sorted. The data set ORDERS is sorted by PRIORITY and by the descending
values of INDATE. Once the data set is created, the sort indicator is stored with it.
These statements create the data set ORDERS and record the sort indicator:
libname mylib ’SAS-library’;
options yearcutoff=1920;
data mylib.orders(sortedby=priority
descending indate);
input priority 1. +1 indate date7.
+1 office $ code $;
format indate date7.;
datalines;
1 03may01 CH J8U
1 21mar01 LA M91
1 01dec00 FW L6R
1 27feb99 FW Q2A
2 15jan00 FW I9U
2 09jul99 CH P3Q
3 08apr99 CH H5T
3 31jan99 FW D2W
;
See Also
The CONTENTS statement in “The DATASETS Procedure” in Base SAS Procedures
Guide
“The SORT Procedure” in Base SAS Procedures Guide
“The SQL Procedure” in Base SAS Procedures Guide
58
SPILL= Data Set Option
4
Chapter 2
SPILL= Data Set Option
Specifies whether to create a spill file for non-sequential processing of a DATA step view.
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Restriction:
Valid only for a DATA step view
Syntax
SPILL=YES | NO
Syntax Description
YES
creates a spill file for non-sequential processing of a DATA step view. This is the
default.
Interaction: A spill file is never created for sequential processing of a DATA step
view.
A DATA step view that generates large amounts of observations can result in a
very large spill file. You must have enough disk space to accommodate the spill file.
Tip:
NO
does not create a spill file or reduces the size of a spill file.
Interaction: For direct (random) access, a spill file is always created even if you
specify SPILL=NO.
If you do not have enough disk space to accommodate a resulting spill file from
a DATA step view that generates a large amount of data, specify SPILL=NO.
Tip:
For SAS procedures that process BY-group data, consider specifying
SPILL=NO in order to write only the current BY group to the spill file.
Tip:
Details
When a DATA step view is opened for non-sequential processing, a spill file is created
by default. The spill file contains the observations that are generated by a DATA step
view. Subsequent requests for data read the observations from the spill file rather than
execute the DATA step view again. The spill file is a temporary file in the WORK library.
Non-sequential processing includes the following access methods, which are
supported by several SAS statements and procedures. How the SPILL= data set option
operates with each of the access methods is described below:
random access
retrieves observations directly either by an observation number or by
the value of one or more variables through an index without reading
all observations sequentially. Whether SPILL=YES or SPILL=NO, a
spill file is always created, because the processing time to restart a
DATA step view for each observation would be costly.
BY-group access
uses a BY statement to process observations that are ordered,
grouped, or indexed according to the values of one or more variables.
SPILL=YES creates a spill file the size of all the data that is
SAS Data Set Options
4
SPILL= Data Set Option
59
requested from the DATA step view. SPILL=NO writes only the
current BY group to the spill file. The largest size of the spill file is
a size to store the largest BY group.
two-pass access
performs multiple sequential passes through the data. With
SPILL=NO, no spill file is created. Instead, after the first pass
through the data, the DATA step view is restarted for each
subsequent pass through the data. If small amounts of data are
returned by the DATA step view for each restart, the processing
time to restart the view might become significant.
Note: With SPILL=NO, subsequent passes through the data
could result in generating different data. Some processing might
require using a spill file; for example, results from using random
functions and computing values that are based on the current time
of day could affect the data. 4
Examples
Example 1: Using a Spill File for a Small Number of Large BY Groups
This example
creates a DATA step view that generates a large amount of random data and uses the
UNIVARIATE procedure with a BY statement. The example illustrates the effects of
SPILL= with a small number of large BY groups.
With SPILL=YES, all observations that are requested from the DATA step view are
written to the spill file. With SPILL=NO, only the observations that are in the current
BY group are written to the spill file. The information messages that are produced by
this example show that the size of the spill file is reduced with SPILL=NO. However,
the time to truncate the spill file for each BY group might add to the overall processing
time for the DATA step view.
options msglevel=i;
data vw_few_large / view=vw_few_large;
drop i;
do byval = ’Group A’, ’Group B’, ’Group C’;
do i = 1 to 500000;
r = ranuni(4);
output;
end;
end;
run;
proc univariate data=vw_few_large (spill=yes) noprint;
var r;
by byval;
run;
proc univariate data=vw_few_large (spill=no) noprint;
var r;
by byval;
run;
60
SPILL= Data Set Option
Output 2.8
1
2
3
4
5
6
7
8
9
10
11
4
Chapter 2
SAS Log Output
options msglevel=i;
data vw_few_large / view=vw_few_large;
drop i;
do byval = ’Group A’, ’Group B’, ’Group C’;
do i = 1 to 500000;
r = ranuni(4);
output;
end;
end;
run;
NOTE: DATA STEP view saved on file WORK.VW_FEW_LARGE.
NOTE: A stored DATA STEP view cannot run under a different operating system.
NOTE: DATA statement used (Total process time):
real time
21.57 seconds
cpu time
1.31 seconds
12
proc univariate data=vw_few_large (spill=yes) noprint;
INFO: View WORK.VW_FEW_LARGE open mode: BY-group rewind.
13
var r;
14
by byval;
15
run;
INFO: View WORK.VW_FEW_LARGE opening spill file for output observations.
INFO: View WORK.VW_FEW_LARGE deleting spill file. File size was 22506120 bytes.
NOTE: View WORK.VW_FEW_LARGE.VIEW used (Total process time):
real time
40.68 seconds
cpu time
12.71 seconds
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time
57.63 seconds
cpu time
13.12 seconds
16
17
proc univariate data=vw_few_large (spill=no) noprint;
INFO: View WORK.VW_FEW_LARGE open mode: BY-group rewind.
18
var r;
19
by byval;
20
run;
INFO: View WORK.VW_FEW_LARGE opening spill file for output observations.
INFO: View WORK.VW_FEW_LARGE truncating spill file. File size was 7502040 bytes.
NOTE: The above message was for the following by-group:
byval=Group A
INFO: View WORK.VW_FEW_LARGE truncating spill file. File size was 7534800 bytes.
NOTE: The above message was for the following by-group:
byval=Group B
INFO: View WORK.VW_FEW_LARGE truncating spill file. File size was 7534800 bytes.
NOTE: The above message was for the following by-group:
byval=Group C
INFO: View WORK.VW_FEW_LARGE deleting spill file. File size was 32760 bytes.
NOTE: View WORK.VW_FEW_LARGE.VIEW used (Total process time):
real time
11.03 seconds
cpu time
10.95 seconds
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time
11.04 seconds
cpu time
10.96 seconds
SAS Data Set Options
4
SPILL= Data Set Option
Example 2: Using a Spill File for a Large Number of Small BY Groups
61
This example
creates a DATA step view that generates a large amount of random data and uses the
UNIVARIATE procedure with a BY statement. This example illustrates the effects of
SPILL= with a large number of small BY groups.
With SPILL=YES, all observations that are requested from the DATA step view are
written to the spill file. With SPILL=NO, only the observations that are in the current
BY group are written to the spill file. The information messages that are produced by
this example show that the size of the spill file is reduced with SPILL=NO, and with
small BY groups, this results in a large disk space savings.
options msglevel=i;
data vw_many_small / view=vw_many_small;
drop i;
do byval = 1 to 100000;
do i = 1 to 5;
r = ranuni(4);
output;
end;
end;
run;
proc univariate data=vw_many_small (spill=yes) noprint;
var r;
by byval;
run;
proc univariate data=vw_many_small (spill=no) noprint;
var r;
by byval;
run;
62
SPILL= Data Set Option
Output 2.9
1
2
3
4
5
6
7
8
9
10
11
4
Chapter 2
SAS Log Output
options msglevel=i;
data vw_many_small / view=vw_many_small;
drop i;
do byval = 1 to 100000;
do i = 1 to 5;
r = ranuni(4);
output;
end;
end;
run;
NOTE: DATA STEP view saved on file WORK.VW_MANY_SMALL.
NOTE: A stored DATA STEP view cannot run under a different operating system.
NOTE: DATA statement used (Total process time):
real time
0.56 seconds
cpu time
0.03 seconds
12
proc univariate data=vw_many_small (spill=yes) noprint;
INFO: View WORK.VW_MANY_SMALL open mode: BY-group rewind.
13
var r;
14
by byval;
15
run;
INFO: View WORK.VW_MANY_SMALL opening spill file for output observations.
INFO: View WORK.VW_MANY_SMALL deleting spill file. File size was 8024240 bytes.
NOTE: View WORK.VW_MANY_SMALL.VIEW used (Total process time):
real time
30.73 seconds
cpu time
29.59 seconds
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time
30.96 seconds
cpu time
29.68 seconds
16
17
proc univariate data=vw_many_small (spill=no) noprint;
INFO: View WORK.VW_MANY_SMALL open mode: BY-group rewind.
18
var r;
19
by byval;
20
run;
INFO: View WORK.VW_MANY_SMALL opening spill file for output observations.
INFO: View WORK.VW_MANY_SMALL truncating spill file. File size was 65504 bytes.
NOTE: The above message was for the following by-group:
byval=410
INFO: View WORK.VW_MANY_SMALL truncating spill file. File size was 65504 bytes.
NOTE: The above message was for the following by-group:
byval=819
INFO: View WORK.VW_MANY_SMALL truncating spill file. File size was 65504 bytes.
NOTE: The above message was for the following by-group:
byval=1229
.
. Deleted many INFO and NOTE messages for BY groups
.
INFO: View WORK.VW_MANY_SMALL truncating spill file. File size was 65504 bytes.
NOTE: The above message was for the following by-group:
byval=99894
INFO: View WORK.VW_MANY_SMALL deleting spill file. File size was 32752 bytes.
NOTE: View WORK.VW_MANY_SMALL.VIEW used (Total process time):
real time
29.43 seconds
cpu time
28.81 seconds
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time
29.43 seconds
cpu time
28.81 seconds
SAS Data Set Options
4
SPILL= Data Set Option
Example 3: Using a Spill File with Two-Pass Access
63
This example creates a DATA
step view that generates a large amount of random data and uses the TRANSPOSE
procedure. The example illustrates the effects of SPILL= with a procedure that requires
two-pass access processing.
When PROC TRANSPOSE processes a DATA step view, the procedure must make
two passes through the observations that the view generates. The first pass counts the
number of observations and the second pass performs the transposition. With
SPILL=YES, a spill file is created during the first pass, and the second pass reads the
observations from the spill file. With SPILL=NO, a spill file is not created—after the
first pass, the DATA step view is restarted.
Note that for the first TRANSPOSE procedure, which does not include the SPILL=
data set option, even though a spill file is used by default, the informative message
about the open mode is not displayed. This action occurs to reduce the amount of
messages in the SAS log for users who are not using the SPILL= data set option.
options msglevel=i;
data vw_transpose/view=vw_transpose;
drop i j;
array x[10000];
do i = 1 to 10;
do j = 1 to dim(x);
x[j] = ranuni(4);
end;
output;
end;
run;
proc transpose data=vw_transpose out=transposed;
run;
proc transpose data=vw_transpose(spill=yes) out=transposed;
run;
proc transpose data=vw_transpose(spill=no) out=transposed;
run;
64
SPILL= Data Set Option
4
Output 2.10
1
2
3
4
5
6
7
8
9
10
11
Chapter 2
SAS Log Output
options msglevel=i;
data vw_transpose/view=vw_transpose;
drop i j;
array x[10000];
do i = 1 to 10;
do j = 1 to dim(x);
x[j] = ranuni(4);
end;
output;
end;
run;
NOTE: DATA STEP view saved on file WORK.VW_TRANSPOSE.
NOTE: A stored DATA STEP view cannot run under a different operating system.
NOTE: DATA statement used (Total process time):
real time
0.68 seconds
cpu time
0.18 seconds
12
13
proc transpose data=vw_transpose out=transposed;
run;
INFO: View WORK.VW_TRANSPOSE opening spill file for output observations.
INFO: View WORK.VW_TRANSPOSE deleting spill file. File size was 880000 bytes.
NOTE: View WORK.VW_TRANSPOSE.VIEW used (Total process time):
real time
2.37 seconds
cpu time
1.17 seconds
NOTE: There were 10 observations read from the data set WORK.VW_TRANSPOSE.
NOTE: The data set WORK.TRANSPOSED has 10000 observations and 11 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time
4.17 seconds
cpu time
1.51 seconds
14
proc transpose data=vw_transpose (spill=yes) out=transposed;
INFO: View WORK.VW_TRANSPOSE open mode: sequential.
15
run;
INFO:
INFO:
INFO:
NOTE:
View WORK.VW_TRANSPOSE reopen mode: two-pass.
View WORK.VW_TRANSPOSE opening spill file for output observations.
View WORK.VW_TRANSPOSE deleting spill file. File size was 880000 bytes.
View WORK.VW_TRANSPOSE.VIEW used (Total process time):
real time
0.95 seconds
cpu time
0.92 seconds
NOTE: There were 10 observations read from the data set WORK.VW_TRANSPOSE.
NOTE: The data set WORK.TRANSPOSED has 10000 observations and 11 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time
1.01 seconds
cpu time
0.98 seconds
16
proc transpose data=vw_transpose (spill=no) out=transposed;
INFO: View WORK.VW_TRANSPOSE open mode: sequential.
17
run;
INFO: View WORK.VW_TRANSPOSE reopen mode: two-pass.
INFO: View WORK.VW_TRANSPOSE restarting for another pass through the data.
NOTE: View WORK.VW_TRANSPOSE.VIEW used (Total process time):
real time
1.34 seconds
cpu time
1.32 seconds
NOTE: The View WORK.VW_TRANSPOSE was restarted 1 times. The following view statistics
only apply to the last view restart.
NOTE: There were 10 observations read from the data set WORK.VW_TRANSPOSE.
NOTE: The data set WORK.TRANSPOSED has 10000 observations and 11 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time
1.42 seconds
cpu time
1.40 seconds
SAS Data Set Options
4
TYPE= Data Set Option
65
See Also
Data Set Options:
“OBSBUF= Data Set Option” on page 43
TOBSNO= Data Set Option
Specifies the number of observations to send in a client/server transfer.
Valid in:
DATA step and PROC steps
Category: Data Set Control
Restriction: The TOBSNO= option is valid only for data sets that are accessed through a
SAS server via the REMOTE engine.
Syntax
TOBSNO=n
Syntax Description
n
specifies the number of observations to be transmitted.
Details
If the TOBSNO= option is not specified, its value is calculated based on the observation
length and the size of the server’s transmission buffers, as specified by the PROC
SERVER statement TBUFSIZE= option.
The TOBSNO= option is valid only for data sets that are accessed through a SAS
server via the REMOTE engine. If this option is specified for a data set opened for
update or accessed via another engine, it is ignored.
See Also
“FOPEN Function” in SAS Component Language: Reference.
TYPE= Data Set Option
Specifies the data set type for a specially structured SAS data set.
Valid in:
DATA step and PROC steps
Category: Data Set Control
66
4
WHERE= Data Set Option
Chapter 2
Syntax
TYPE=data-set-type
Syntax Description
data-set-type
specifies the special type of the data set.
Details
Use the TYPE= data set option in a DATA step to create a special SAS data set in the
proper format, or to identify the special type of the SAS data set in a procedure
statement.
You can use the CONTENTS procedure to determine the type of a data set.
Most SAS data sets do not have a specified type. However, there are several specially
structured SAS data sets that are used by some SAS/STAT procedures. These SAS data
sets contain special variables and observations, and they are usually created by SAS
statistical procedures. Because most of the special SAS data sets are used with
SAS/STAT software, they are described in the SAS/STAT User’s Guide. Some of the
special data sets are CORR, COV, SSPC, EST, or FACTOR.
Other values are available in other SAS software products and are described in the
appropriate documentation.
Note: If you use a DATA step with a SET statement to modify a special SAS data
set, you must specify the TYPE= option in the DATA statement. The data-set-type is not
automatically copied to the data set that is created. 4
See Also
“Special SAS Data Sets” in the SAS/STAT User’s Guide
“The CONTENTS Procedure” in the Base SAS Procedures Guide
WHERE= Data Set Option
Specifies specific conditions to use to select observations from a SAS data set.
Valid in:
DATA step and PROC steps
Category:
Observation Control
Restriction: Cannot be used with the POINT= option in the SET and MODIFY
statements.
Syntax
WHERE=(where-expression-1<logical-operator where-expression-n>)
SAS Data Set Options
4
WHERE= Data Set Option
67
Syntax Description
where-expression
is an arithmetic or logical expression that consists of a sequence of operators,
operands, and SAS functions. An operand is a variable, a SAS function, or a
constant. An operator is a symbol that requests a comparison, logical operation, or
arithmetic calculation. The expression must be enclosed in parentheses.
logical-operator
can be AND, AND NOT, OR, or OR NOT.
Details
3 Use the WHERE= data set option with an input data set to select observations
that meet the condition specified in the WHERE expression before SAS brings
them into the DATA or PROC step for processing. Selecting observations that
meet the conditions of the WHERE expression is the first operation SAS performs
in each iteration of the DATA step.
You can also select observations that are written to an output data set. In
general, selecting observations at the point of input is more efficient than selecting
them at the point of output. However, there are some cases when selecting
observations at the point of input is not practical or not possible.
3 You can apply OBS= and FIRSTOBS= processing to WHERE processing. For more
information see “Processing a Segment of Data That is Conditionally Selected” in
SAS Language Reference: Concepts.
3 You cannot use the WHERE= data set option with the POINT= option in the SET
and MODIFY statements.
3 If you use both the WHERE= data set option and the WHERE statement in the
same DATA step, SAS ignores the WHERE statement for data sets with the
WHERE= data set option. However, you can use the WHERE= data set option
with the WHERE command in SAS/FSP software.
Note: Using indexed SAS data sets can improve performance significantly when you
are using WHERE expressions to access a subset of the observations in a SAS data set.
See “Understanding SAS Indexes” in SAS Language Reference: Concepts for a complete
discussion of WHERE expression processing with indexed data sets and a list of
guidelines to consider before indexing your SAS data sets. 4
Comparisons
3 The WHERE statement applies to all input data sets, whereas the WHERE= data
set option selects observations only from the data set for which it is specified.
3 Do not confuse the purpose of the WHERE= data set option. The DROP= and
KEEP= data set options select variables for processing, while the WHERE= data
set option selects observations.
68
WHEREUP= Data Set Option
4
Chapter 2
Examples
Example 1: Selecting Observations from an Input Data Set
This example uses the
WHERE= data set option to subset the SALES data set as it is read into another data
set:
data whizmo;
set sales(where=(product=’whizmo’));
run;
Example 2: Selecting Observations from an Output Data Set
This example uses the
WHERE= data set option to subset the SALES output data set:
data whizmo(where=(product=’whizmo’));
set sales;
run;
See Also
Statements:
“WHERE Statement” on page 1728
“WHERE-Expression Processing” in SAS Language Reference: Concepts
WHEREUP= Data Set Option
Specifies whether to evaluate new observations and modified observations against a WHERE
expression.
Valid in:
Category:
DATA step and PROC steps
Observation Control
Syntax
WHEREUP=NO | YES
Syntax Description
NO
does not evaluate added observations and modified observations against a WHERE
expression.
YES
evaluates added observations and modified observations against a WHERE
expression.
SAS Data Set Options
4
WHEREUP= Data Set Option
Details
Specify WHEREUP=YES when you want any added observations or modified
observations to match a specified WHERE expression.
Examples
Example 1: Accepting Updates That Do Not Match the WHERE Expression
This
example shows how WHEREUP= permits observations to be updated and added even
though the modified observation does not match the WHERE expression:
data a;
x=1;
output;
x=2;
output;
run;
data a;
modify a(where=(x=1) whereup=no);
x=3;
replace; /* Update does not match WHERE expression */
output; /* Add does not match WHERE expression */
run;
In this example, SAS updates the observation and adds the new observation to the
data set.
Example 2: Rejecting Updates That Do Not Match the WHERE Expression
In this
example, WHEREUP= does not permit observations to be updated or added when the
update and the add do not match the WHERE expression:
data a;
x=1;
output;
x=2;
output;
run;
data a;
modify a(where=(x=1) whereup=yes);
x=3;
replace; /* Update does not match WHERE expression */
output; /* Add does not match WHERE expression */
run;
In this example, SAS does not update the observation nor does it add the new
observation to the data set.
See Also
Data Set Option:
“WHERE= Data Set Option” on page 66
69
70
WRITE= Data Set Option
4
Chapter 2
WRITE= Data Set Option
Assigns a WRITE password to a SAS file that prevents users from writing to a file, unless they
enter the password.
DATA step and PROC steps
Category: Data Set Control
Valid in:
Syntax
WRITE=write-password
Syntax Description
write-password
must be a valid SAS name.
See: “Rules for Words and Names in the SAS Language” in SAS Language
Reference: Concepts
Details
The WRITE= option applies to all types of SAS files except catalogs. You can use this
option to assign a password to a SAS file or to access a write-protected SAS file.
Note: A SAS password does not control access to a SAS file beyond the SAS system.
You should use the operating system-supplied utilities and file-system security controls
in order to control access to SAS files outside of SAS. 4
See Also
Data Set Options:
“ALTER= Data Set Option” on page 14
“ENCRYPT= Data Set Option” on page 23
“PW= Data Set Option” on page 48
“READ= Data Set Option” on page 50
“Manipulating Passwords” in “The DATASETS Procedure” in Base SAS Procedures
Guide
SAS Data Set Options
4
SAS Companion for UNIX Environments
Data Set Options Documented in Other SAS Publications
In addition to data set options documented in SAS Language Reference: Dictionary,
data set options are also documented in the following publications:
SAS Companion for Windows
Data Set Option
Description
SGIO=
Activates the Scatter/Gather I/O feature for a dataset.
SAS Companion for OpenVMS on HP Integrity Servers
The data set options listed here are documented only in SAS Companion for
OpenVMS on HP Integrity Servers. Other data set options in SAS Companion for
OpenVMS on HP Integrity Servers contain information specific to the OpenVMS
operating environment, where the main documentation is in SAS Language Reference:
Dictionary. These latter data set options are not listed here.
Data Set Option
Description
ALQ=
Specifies how many disk blocks to initially allocate to a new SAS
data set.
ALQMULT=
Specifies the number of pages that are preallocated to a file.
BKS=
Specifies the bucket size for a new data set.
CACHENUM=
Specifies the number of I/O data caches used per SAS file.
CACHESIZE=
Controls the size of the I/O data cache that is allocated for a SAS
file.
DEQ=
Specifies how many disk blocks to add when OpenVMS
automatically extends a SAS data set during a write operation.
DEQMULT=
Specifies the number of pages to extend a SAS file.
LOCKREAD
Specifies whether to read a record if a lock cannot be obtained for
the record.
LOCKWAIT
Indicates whether SAS should wait for a locked record.
MBF
Specifies the multibuffer count for a data set.
SAS Companion for UNIX Environments
The data set options listed here are documented only in SAS Companion for UNIX
Environments. Other data set options in SAS Companion for UNIX Environments
71
72
SAS Companion for z/OS
4
Chapter 2
contain information specific to the UNIX operating environment, where the main
documentation is in SAS Language Reference: Dictionary. These latter data set options
are not listed here.
Data Set Option
Description
ALTER=
Specifies a password for a SAS file that prevents users from replacing
or deleting the file, but permits read and write access.
BUFNO=
Specifies the number of buffers to be allocated for processing a SAS
data set.
BUFSIZE=
Specifies the size of a permanent buffer page for an output SAS data
set.
FILECLOSE=
Specifies how a tape is positioned when a SAS data set is closed.
PW=
Assigns a READ, WRITE, or ALTER password to a SAS file, and
enables access to a password-protected SAS file.
USEDIRECTIO
Turns on direct I/O for a library that contains the file to which the
ENABLEDIRECTIO option has been applied.
SAS Companion for z/OS
The data set options listed here are documented only in SAS Companion for z/OS.
Other data set options in SAS Companion for z/OS contain information specific to the
z/OS operating environment, where the main documentation is in SAS Language
Reference: Dictionary. These latter data set options are not listed here.
Data Set Option
Description
ALTER=
Assigns an alter password to a SAS file and enables access to a
password-protected SAS file.
BUFSIZE=
Specifies the permanent buffer page size for an output SAS data set.
FILEDISP=
Specifies the initial disposition for a sequential access bound SAS
data library.
SAS National Language Support: Reference Guide
Data Set Option
Description
ENCODING=
Overrides the encoding to use for reading or writing a SAS data set.
SAS Data Set Options
4
SAS Scalable Performance Data Engine: Reference
SAS Scalable Performance Data Engine: Reference
Data Set Option
Description
ASYNCINDEX=
Specifies to create the indexes in parallel when creating multiple
indexes on an SPD Engine data set.
BYNOEQUALS=
Specifies whether the output order of data set observations with
identical values for the BY variable are guaranteed to be in data set
order.
BYSORT=
Specifies for the SPD Engine to perform an automatic sort when it
encounters a BY statement.
COMPRESS=
Specifies to compress SPD Engine data sets on disk as they are being
created.
ENCRYPT=
Specifies whether to encrypt an output SPD Engine data set.
ENDOBS=
Specifies the end observation number in a user-defined range of
observations to be processed.
IDXWHERE=
Specifies to use indexes when processing WHERE expressions in the
SPD Engine.
IOBLOCKSIZE=
Specifies the number of observations in a block to be stored in or read
from an SPD Engine data component file that is compressed.
LISTFILES=
Specifies whether the CONTENTS procedure lists the complete
pathnames of all the component files.
PADCOMPRESS=
Specifies a number of bytes to add to compression blocks in a data set
opened for UPDATE.
PARTSIZE=
When an SPD Engine data set is created, specifies the largest size (in
megabytes) that the data component partitions can be. This is a fixed
size. This specification applies only to the data component files.
STARTOBS=
Specifies the starting observation number in a user-defined range of
observations to be processed.
SYNCADD=
Specifies to process one observation at a time or multiple observations
at a time.
THREADNUM=
Specifies the number of I/O threads the SPD Engine can spawn for
processing an SPD Engine data set.
UNIQUESAVE=
Specifies to save observations with non-unique key values (the
rejected observations) to a separate data set when appending or
inserting observations to data sets with unique indexes.
WHERENOINDEX=
Specifies, when making WHERE expression evaluations, a list of
indexes to exclude.
73
74
SAS/ACCESS for Relational Databases: References
4
Chapter 2
SAS/ACCESS for Relational Databases: References
Data Set Option
Description
AUTHID=
Enables you to qualify the specified table with an authorization ID,
user ID, or group ID.
AUTOCOMMIT=
Specifies whether to enable the DBMS autocommit capability.
BL_ALLOW_READ_ACCESS=Specifies that the original table data is still visible to readers during
bulk load.
BL_ALLOWWRITE_ACCESS=Specifies that table data is still accessible to readers and writers
while import is in progress.
BL_BADDATA_FILE=
Specifies where to put records that failed to process internally.
BL_BADFILE=
Identifies a file that contains records that were rejected during a bulk
load.
BL_CODEPAGE=
Identifies the codepage that the DBMS engine uses to convert SAS
character data to the current database codepage during a bulk load.
BL_CONTROL=
Identifies a file containing SQLLDR control statements that describe
the data to be included in a bulk load.
BL_COPY_LOCATION=
Specifies the directory to which DB2 saves a copy of the loaded data.
This option is valid only when used in conjunction with
BL_RECOVERABLE=YES.
BL_CPU_PARALLELISM=
Specifies the number of processes or threads that are used when
building table objects.
BL_DATA_BUFFER_SIZE=
Specifies the total amount of memory that is allocated for the bulk
load utility to use as a buffer for transferring data.
BL_DATAFILE=
Identifies the file that contains the data that is loaded or appended
into a DBMS table during a bulk load.
BL_DB2CURSOR=
Specifies a string that contains a valid DB2 SELECT statement that
points to either local or remote objects (tables or views).
BL_DB2DEVT_PERM=
Specifies the unit address or generic device type that is used for the
permanent data sets created by the LOAD utility, as well as SYSIN,
SYSREC, and SYSPRINT when they are allocated by SAS.
BL_DB2DEVT_TEMP=
Specifies the unit address or generic device type that is used for the
temporary data sets created by the LOAD utility (PNCH, COPY1,
COPY2, RCPY1, RCPY2, WORK1, WORK2).
BL_DB2DISC=
Specifies the SYSDISC data set name for the LOAD utility.
BL_DB2ERR=
Specifies the SYSERR data set name for the LOAD utility.
BL_DB2IN=
Specifies the SYSIN data set name for the LOAD utility
BL_DB2LDCT1=
Specifies a string in the LOAD utility control statement, between
LOAD DATA and INTO TABLE.
BL_DB2LDCT2=
Specifies a string in the LOAD utility control statement, between
INTO TABLE table-name and (field-specification).
BL_DB2LDCT3=
Specifies a string in the LOAD utility control statement, after
(field-specification)
SAS Data Set Options
4
SAS/ACCESS for Relational Databases: References
Data Set Option
Description
BL_DB2LDEXT=
Specifies the mode of execution for the DB2 LOAD utility.
BL_DB2MAP=
Specifies the SYSMAP data set name for the LOAD utility.
BL_DB2PRINT=
Specifies the SYSPRINT data set name for the LOAD utility.
BL_DB2PRNLOG=
Determines whether the SYSPRINT output is written to the SAS log.
BL_DB2REC=
Specifies the SYSREC data set name for the LOAD utility
BL_DB2RECSP=
Determines the number of cylinders to specify as the primary
allocation for the SYSREC data set when it is created.
BL_DB2RSTRT=
Tells the LOAD utility whether the current load is a restart and, for a
restart, indicates where to begin.
BL_DB2SPC_PERM=
Determines the number of cylinders to specify as the primary
allocation for the permanent data sets that are created by the LOAD
utility.
BL_DB2SPC_TEMP=
Determines the number of cylinders to specify as the primary
allocation for the temporary data sets that are created by the LOAD
utility.
BL_DB2TBLXST=
Indicates whether the LOAD utility runs against an existing table
BL_DB2UTID=
Specifies a unique identifier for a given run of the DB2 LOAD utility.
BL_DELETE_DATAFILE=
Deletes the data file that is created for the DBMS bulk load facility.
BL_DELIMITER=
Specifies override of the default delimiter character for separating
columns of data during data transfer or retrieval during bulk load or
bulk unload.
BL_DIRECT_PATH=
Sets the Oracle SQL*Loader DIRECT option.
BL_DISCARDFILE=
Identifies the file that contains the records that were filtered out of a
bulk load because they did not match the criteria specified in the
CONTROL file.
BL_DISCARDS=
"Specifies whether and when to stop processing a job, based on the
number of discarded records.
BL_DISK_PARALLELISM=
Specifies the number of processes or threads that are used when
writing data to disk.
BL_ERRORS=
Specifies whether and when to stop processing a job based on the
number of failed records.
BL_EXCEPTION=
Specifies the exception table into which rows in error are copied.
BL_FAILEDDATA=
Specifies where to put records that could not be written to the
database.
BL_INDEX_OPTIONS=
Enables you to specify SQL*Loader Index options with bulk loading.
BL_INDEXING_MODE=
Used to indicate which scheme the DB2 load utility should use with
respect to index maintenance.
BL_KEEPIDENTITY=
Determines whether the identity column that is created during a
bulk load is populated with values generated by Microsoft SQL
Server or with values provided by the user.
BL_KEEPNULLS=
Indicates how NULL values in Microsoft SQL Server columns that
accept NULL are handled during a bulk load.
75
76
SAS/ACCESS for Relational Databases: References
4
Chapter 2
Data Set Option
Description
BL_LOAD_METHOD=
Specifies the method by which data is loaded into an Oracle table
during bulk loading.
BL_LOAD_REPLACE=
Specifies whether DB2 appends or replaces rows during bulk loading
BL_LOG=
Identifies a log file that contains information such as statistics and
error information for a bulk load.
BL_METHOD=
Specifies which bulk loading method to use for DB2.
BL_OPTIONS=
Passes options to the DBMS bulk load facility, affecting how it loads
and processes data.
BL_PARFILE=
Creates a file that contains the SQL*Loader command line options.
BL_PORT_MAX=
Sets the highest available port number for concurrent uploads.
BL_PORT_MIN=
Sets the lowest available port number for concurrent uploads.
BL_PRESERVE_BLANKS=
Determines how the SQL*Loader handles requests to insert blank
spaces into CHAR/VARCHAR2 columns with the NOT NULL
constraint.
BL_RECOVERABLE=
Determines whether the LOAD process is recoverable.
BL_REMOTE_FILE=
Specifies the base filename and location of DB2 LOAD temporary files.
BL_RETRIES=
Specifies the number of attempts to make for a job.
BL_RETURN_
WARNINGS_AS_
ERRORS=
Specifies whether SQL*Loader (bulkload) warnings should surface in
SAS through the SYSERR macro warnings or as errors.
BL_SERVER_DATAFILE=
Specifies the name and location of the data file as seen by the DB2
server instance.
BL_SQLLDR_PATH=
Specifies the location of the SQLLDR executable file.
BL_SUPPRESS_NULLIF=
Indicates whether to suppress the NULLIF clause for the specified
columns when a table is created in order to increase performance.
BL_USE_PIPE=
Specifies a named pipe for data transfer.
BL_WARNING_COUNT=
Specifies the maximum number of row warnings to allow before you
abort the load operation.
BUFFERS=
Specifies the number of shared memory buffers to be used for
transferring data from SAS to Teradata.
BULK_BUFFER=
Specifies the number of bulk rows that the SAS/ACCESS engine can
buffer for output.
BULKLOAD=
Loads rows of data as one unit.
BULKUNLOAD
Rapidly retrieves (fetches) large number of rows from a data set.
CAST=
Specifies whether data conversions should be performed on the
Teradata DBMS server or by SAS.
CAST_OVERHEAD_
MAXPERCENT=
Specifies the overhead limit for data conversions to be performed in
Teradata instead of SAS.
COMMAND_TIMEOUT=
Specifies the number of seconds to wait before a command times out.
CURSOR_TYPE=
Specifies the cursor type for read only and updatable cursors.
SAS Data Set Options
4
SAS/ACCESS for Relational Databases: References
Data Set Option
Description
DBCOMMIT=
Causes an automatic COMMIT (a permanent writing of data to the
DBMS) after a specified number of rows have been processed.
DBCONDITION=
Specifies criteria for subsetting and ordering DBMS data.
DBCREATE_TABLE_OPTS= Specifies DBMS-specific syntax to be added to the CREATE TABLE
statement.
DBFORCE=
Specifies whether to force the truncation of data during insert
processing.
DBGEN_NAME=
Specifies how SAS renames columns automatically when they contain
characters that SAS does not allow.
DBINDEX=
Detects and verifies that indexes exist on a DBMS table. If they do
exist and are of the correct type, a join query that is passed to the
DBMS might improve performance.
DBKEY=
Specifies a key column to optimize DBMS retrieval. Can improve
performance when you are processing a join that involves a large
DBMS table and a small SAS data set or DBMS table.
DBLABEL=
Specifies whether to use SAS variable labels or SAS variable names
as the DBMS column names during output processing.
DBLINK=
Specifies a link from your default database to another database on
the server to which you are connected in the Sybase interface; and
specifies a link from your local database to database objects on
another server in the Oracle interface.
DBMASTER=
Designates which table is the larger table when you are processing a
join that involves tables from two different types of databases.
DBMAX_TEXT=
Determines the length of any very long DBMS character data type
that is read into SAS or written from SAS when you are using a SAS/
ACCESS engine.
DBNULL=
Indicates whether NULL is a valid value for the specified columns
when a table is created.
DBNULLKEYS=
Controls the format of the WHERE clause with regard to NULL
values when you use the DBKEY= data set option.
DBPROMPT=
Specifies whether SAS displays a window that prompts you to enter
DBMS connection information.
DBSASLABEL=
Specifies how the engine returns column labels.
DBSASTYPE=
Specifies data types to override the default SAS data types during
input processing.
DBSLICE=
Specifies user-supplied WHERE clauses to partition a DBMS query
for threaded reads.
DBSLICEPARM=
Controls the scope of DBMS threaded reads and the number of
DBMS connections.
DBTYPE=
Specifies a data type to use instead of the default DBMS data type
when SAS creates a DBMS table.
DEGREE=
Determines whether DB2 uses parallelism.
DISTRIBUTE_ON
Specifies a column name to use in the DISTRIBUTE ON clause of the
CREATE TABLE statement.
77
78
SAS/ACCESS for Relational Databases: References
4
Chapter 2
Data Set Option
Description
ERRLIMIT=
Specifies the number of errors that are allowed before SAS stops
processing and issues a rollback.
ESCAPE_BACKSLASH=
Specifies whether backslashes in literals are preserved during data
copy from a SAS data set to a table.
IGNORE_
READ_ONLY_COLUMNS=
Specifies whether to ignore or include columns whose data types are
read-only when generating an SQL statement for inserts or updates.
IN=
Enables you to specify the database or tablespace in which you want
to create a new table.
INSERT_SQL=
Determines the method that is used to insert rows into a data source.
INSERTBUFF=
Specifies the number of rows in a single DBMS insert.
KEYSET_SIZE=
Specifies the number of rows in the cursor that are key set driven.
LOCATION=
Enables you to further specify exactly where a table resides.
LOCKTABLE=
Places exclusive or shared locks on tables.
MBUFFSIZE=
Specifies the size of the shared memory buffers to be used for
transferring data from SAS to Teradata.
ML_CHECKPOINT=
Specifies the interval between checkpoint operation, in minutes.
ML_ERROR1=
Specifies the name of a temporary table that MultiLoad uses to track
errors that were generated during the acquisition phase of a
bulk-load operation.
ML_ERROR2=
Specifies the name of a temporary table that MultiLoad uses to track
errors that were generated during the application phase of a
bulk-load operation.
ML_LOG=
Specifies a prefix for the names of the temporary tables that
MultiLoad uses during a bulk-load operation.
ML_RESTART=
Specifies the name of a temporary table that is used by MultiLoad to
track checkpoint information.
ML_WORK=
Specifies the name of a temporary table that MultiLoad uses to store
intermediate data.
MULTILOAD=
Specifies whether Teradata insert and append operations should use
the Teradata MultiLoad utility.
MULTISTMT=
Specifies whether insert statements are to be sent to Teradata one at
a time or in a group.
NULLCHAR=
Indicates how missing SAS character values are handled during
insert, update, DBINDEX=, and DBKEY= processing.
NULLCHARVAL=
Defines the character string that replaces missing SAS character
values during insert, update, DBINDEX=, and DBKEY= processing.
OR_PARTITION=
Allows reading, updating, and deleting from a particular partition in
a partitioned table, also inserting and bulk-loading into a particular
partition in a partitioned table.
OR_UPD_NOWHERE=
Specifies whether SAS uses an extra WHERE clause when updating
rows with no lockingSpecifies whether SAS uses an extra WHERE
clause when updating rows with no locking.
SAS Data Set Options
4
SAS/ACCESS for Relational Databases: References
Data Set Option
Description
ORHINTS=
Specifies Oracle hints to pass to Oracle from a SAS statement or SQL
procedure.
PRESERVE_COL_NAMES=
Preserves spaces, special characters, and case-sensitivity in DBMS
column names when you create DBMS tables.
QUALIFIER=
Specifies the qualifier to use when you are reading database objects,
such as DBMS tables and views.
QUERY_TIMEOUT=
Specifies the number of seconds of inactivity to wait before canceling
a query.
READ_ISOLATION_LEVEL= Specifies which level of read isolation locking to use when you are
reading data.
READ_LOCK_TYPE=
Specifies how data in a DBMS table is locked during a read
transaction.
READ_MODE_WAIT=
Specifies during SAS/ACCESS read operations whether Teradata
waits to acquire a lock or fails your request when the DBMS resource
is locked by a different user.
READBUFF=
Specifies the number of rows of DBMS data to read into the buffer.
SASDATEFMT=
Changes the SAS date format of a DBMS column.
SCHEMA=
Enables you to read a data source, such as a DBMS table and view,
in the specified schema.
SEGMENT_NAME=
Enables you to control the segment in which you create a table.
SET=
Specifies whether duplicate rows are allowed when creating a table.
SLEEP=
Specifies the number of minutes that MultiLoad waits before it
retries logging in to Teradata.
TENACITY=
Specifies how many hours MultiLoad continues to retry logging on to
Teradata if the maximum number of Teradata utilities are already
running.
TRAP151=
Enables columns that cannot be updated to be removed from a FOR
UPDATE OF clause so updating of columns can proceed as normal.
UPDATE_ISOLATION_
LEVEL=
Defines the degree of isolation of the current application process from
other concurrently running application processes.
UPDATE_LOCK_TYPE=
Specifies how data in a DBMS table is locked during an update
transaction.
UPDATE_MODE_WAIT=
Specifies during SAS/ACCESS update operations whether the DBMS
waits to acquire a lock or fails your request when the DBMS resource
is locked by a different user.
UPDATE_SQL=
Determines the method that is used to update and delete rows in a
data source.
UPDATEBUFF=
Specifies the number of rows that are processed in a single DBMS
update or delete operation.
79
80
81
CHAPTER
3
Formats
Definition of Formats 84
Syntax 84
Using Formats 85
Ways to Specify Formats 85
PUT Statement 85
PUT Function 86
%SYSFUNC 86
FORMAT Statement 86
ATTRIB Statement 86
Permanent versus Temporary Association 87
User-Defined Formats 87
Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms 88
Definitions 88
How Bytes are Ordered Differently 88
Writing Data Generated on Big Endian or Little Endian Platforms 88
Integer Binary Notation and Different Programming Languages 89
Data Conversions and Encodings 89
Working with Packed Decimal and Zoned Decimal Data 90
Definitions 90
Types of Data 90
Packed Decimal Data 90
Zoned Decimal Data 91
Packed Julian Dates 91
Platforms Supporting Packed Decimal and Zoned Decimal Data 91
Languages Supporting Packed Decimal and Zoned Decimal Data 91
Summary of Packed Decimal and Zoned Decimal Formats and Informats 92
Working with Dates and Times Using the ISO 8601 Basic and Extended Notations 94
ISO 8601 Formatting Symbols 94
Writing ISO 8601 Date, Time, and Datetime Values 95
Writing ISO 8601 Duration, Datetime, and Interval Values 96
Duration, Datetime, and Interval Formats 96
Writing Omitted Components 97
Writing Truncated Duration, Datetime, and Interval Values 98
Normalizing Duration Components 98
Fractions in Durations, Datetime, and Interval Values 98
Formats by Category 99
Dictionary 108
$ASCIIw. Format 108
$BASE64Xw. Format 109
$BINARYw. Format 110
$CHARw. Format 111
82
Contents
4
Chapter 3
$EBCDICw. Format 112
$HEXw. Format 113
$MSGCASEw. Format 114
$N8601Bw.d Format 115
$N8601BAw.d Format 116
$N8601Ew.d Format 117
$N8601EAw.d Format 119
$N8601EHw.d Format 120
$N8601EXw.d Format 121
$N8601Hw.d Format 122
$N8601Xw.d Format 124
$OCTALw. Format 125
$QUOTEw. Format 126
$REVERJw. Format 127
$REVERSw. Format 128
$UPCASEw. Format 129
$VARYINGw. Format 130
$w. Format 131
BESTw. Format 132
BESTDw.p Format 134
BINARYw. Format 135
B8601DAw. Format 136
B8601DNw. Format 137
B8601DTw.d Format 138
B8601DZw. Format 139
B8601LZw. Format 141
B8601TMw.d Format 142
B8601TZw. Format 143
COMMAw.d Format 145
COMMAXw.d Format 146
Dw.p Format 147
DATEw. Format 148
DATEAMPMw.d Format 150
DATETIMEw.d Format 151
DAYw. Format 153
DDMMYYw. Format 154
DDMMYYxw. Format 155
DOLLARw.d Format 157
DOLLARXw.d Format 158
DOWNAMEw. Format 160
DTDATEw. Format 161
DTMONYYw. Format 162
DTWKDATXw. Format 163
DTYEARw. Format 164
DTYYQCw. Format 165
Ew. Format 166
E8601DAw. Format 167
E8601DNw. Format 168
E8601DTw.d Format 169
E8601DZw. Format 170
E8601LZw. Format 172
E8601TMw.d Format 174
E8601TZw.d Format 175
FLOATw.d Format 177
Formats
FRACTw. Format 178
HEXw. Format 179
HHMMw.d Format 180
HOURw.d Format 182
IBw.d Format 183
IBRw.d Format 184
IEEEw.d Format 186
JULDAYw. Format 187
JULIANw. Format 188
MDYAMPMw.d Format 189
MMDDYYw. Format 190
MMDDYYxw. Format 192
MMSSw.d Format 194
MMYYw. Format 195
MMYYxw. Format 196
MONNAMEw. Format 198
MONTHw. Format 199
MONYYw. Format 200
NEGPARENw.d Format 201
NUMXw.d Format 202
OCTALw. Format 204
PDw.d Format 205
PDJULGw. Format 207
PDJULIw. Format 208
PERCENTw.d Format 209
PERCENTNw.d Format 210
PIBw.d Format 212
PIBRw.d Format 213
PKw.d Format 215
PVALUEw.d Format 216
QTRw. Format 217
QTRRw. Format 218
RBw.d Format 219
ROMANw. Format 220
S370FFw.d Format 221
S370FIBw.d Format 222
S370FIBUw.d Format 223
S370FPDw.d Format 225
S370FPDUw.d Format 226
S370FPIBw.d Format 227
S370FRBw.d Format 228
S370FZDw.d Format 230
S370FZDLw.d Format 231
S370FZDSw.d Format 232
S370FZDTw.d Format 233
S370FZDUw.d Format 234
SIZEKw.d Format 235
SIZEKBw.d Format 236
SIZEKMGw.d Format 237
SSNw. Format 238
TIMEw.d Format 239
TIMEAMPMw.d Format 241
TODw.d Format 242
VAXRBw.d Format 244
4
Contents
83
84
Definition of Formats
4
Chapter 3
VMSZNw.d Format 245
w.d Format 246
WEEKDATEw. Format 247
WEEKDATXw. Format 249
WEEKDAYw. Format 250
WEEKUw. Format 251
WEEKVw. Format 253
WEEKWw. Format 255
WORDDATEw. Format 257
WORDDATXw. Format 258
WORDFw. Format 259
WORDSw. Format 260
YEARw. Format 261
YYMMw. Format 262
YYMMxw. Format 263
YYMMDDw. Format 265
YYMMDDxw. Format 266
YYMONw. Format 268
YYQw. Format 269
YYQxw. Format 270
YYQRw. Format 272
YYQRxw. Format 273
Zw.d Format 275
ZDw.d Format 276
Formats Documented in Other SAS Publications 277
SAS National Language Support (NLS): Reference Guide
277
Definition of Formats
A format is an instruction that SAS uses to write data values. You use formats to
control the written appearance of data values, or, in some cases, to group data values
together for analysis. For example, the WORDS22. format, which converts numeric
values to their equivalent in words, writes the numeric value 692 as six hundred
ninety-two.
Syntax
SAS formats have the following form:
<$>format< w>.< d>
where
$
indicates a character format; its absence indicates a numeric format.
format
names the format. The format is a SAS format or a user-defined format that was
previously defined with the VALUE statement in PROC FORMAT. For more
information about user-defined formats, see “The FORMAT Procedure” in Base
SAS Procedures Guide.
Formats
4
Ways to Specify Formats
85
w
specifies the format width, which for most formats is the number of columns in the
output data.
d
specifies an optional decimal scaling factor in the numeric formats.
Formats always contain a period (.) as a part of the name. If you omit the w and the d
values from the format, SAS uses default values. The d value that you specify with a
format tells SAS to display that many decimal places. Formats never change or
truncate the internally stored data values.
For example, in DOLLAR10.2, the w value of 10 specifies a maximum of 10 columns
for the value. The d value of 2 specifies that two of these columns are for the decimal
part of the value, which leaves eight columns for all the remaining characters in the
value. The remaining columns include the decimal point, the remaining numeric value,
a minus sign if the value is negative, the dollar sign, and commas, if any.
If the format width is too narrow to represent a value, SAS tries to squeeze the value
into the space available. Character formats truncate values on the right. Numeric
formats sometimes revert to the BESTw.d format. SAS prints asterisks if you do not
specify an adequate width. In the following example, the result is x=**.
x=123;
put x= 2.;
If you use an incompatible format, such as using a numeric format to write character
values, SAS first attempts to use an analogous format of the other type. If this attempt
fails, an error message that describes the problem appears in the SAS log.
When the value of d is greater than fifteen, the precision of the decimal value after
the 15th decimal place might not be accurate.
Using Formats
Ways to Specify Formats
You can use formats in the following ways:
3
3
3
3
3
in a PUT statement
with the PUT, PUTC, or PUTN functions
with the %SYSFUNC macro function
in a FORMAT statement in a DATA step or a PROC step
in an ATTRIB statement in a DATA step or a PROC step.
PUT Statement
The PUT statement with a format after the variable name uses a format to write
data values in a DATA step. For example, this PUT statement uses the DOLLARw.d
format to write the numeric value for AMOUNT as a dollar amount:
amount=1145.32;
put amount dollar10.2;
The DOLLARw.d format in the PUT statement produces this result:
$1,145.32
86
Ways to Specify Formats
4
Chapter 3
See “PUT Statement” on page 1644 for more information.
PUT Function
The PUT function converts a numeric variable, a character variable, or a constant
using any valid format and returns the resulting character value. For example, the
following statement converts the value of a numeric variable into a two-character
hexadecimal representation:
num=15;
char=put(num,hex2.);
The PUT function returns a value of 0F, which is assigned to the variable CHAR.
The PUT function is useful for converting a numeric value to a character value. See
“PUT Function” on page 1010 for more information.
%SYSFUNC
The %SYSFUNC (or %QSYSFUNC) macro function executes SAS functions or
user-defined functions and applies an optional format to the result of the function
outside a DATA step. For example, the following program writes a numeric value in a
macro variable as a dollar amount.
%macro tst(amount);
%put %sysfunc(putn(&amount,dollar10.2));
%mend tst;
%tst (1154.23);
For more information, see SAS Macro Language: Reference.
FORMAT Statement
The FORMAT statement permanently associates a format with a variable. SAS uses
the format to write the values of the variable that you specify. For example, the
following statement in a DATA step associates the COMMAw.d numeric format with
the variables SALES1 through SALES3:
format sales1-sales3 comma10.2;
Because the FORMAT statement permanently associates a format with a variable, any
subsequent DATA step or PROC step uses COMMA10.2 to write the values of SALES1,
SALES2, and SALES3. See “FORMAT Statement” on page 1511 for more information.
Note: If you assign formats with a FORMAT statement before a PUT statement, all
leading blanks are trimmed. Formats that are associated with variables by using a
FORMAT statement behave like formats that are used with a colon (:) modifier in a
subsequent PUT statement. For details about using the colon format modifier, see “PUT
Statement, List” on page 1668. 4
ATTRIB Statement
The ATTRIB statement can also associate a format, as well as other attributes, with
one or more variables. For example, in the following statement the ATTRIB statement
permanently associates the COMMAw.d format with the variables SALES1 through
SALES3:
attrib sales1-sales3 format=comma10.2;
Formats
4
User-Defined Formats
87
Because the ATTRIB statement permanently associates a format with a variable, any
subsequent DATA step or PROC step uses COMMA10.2 to write the values of SALES1,
SALES2, and SALES3. See “ATTRIB Statement” on page 1384 for more information.
Permanent versus Temporary Association
When you specify a format in a PUT statement, SAS uses the format to write data
values during the DATA step but does not permanently associate the format with a
variable. To permanently associate a format with a variable, use a FORMAT statement
or an ATTRIB statement in a DATA step. SAS permanently associates a format with
the variable by modifying the descriptor information in the SAS data set.
Using a FORMAT statement or an ATTRIB statement in a PROC step associates a
format with a variable for that PROC step, as well as for any output data sets that the
procedure creates that contain formatted variables. For more information about using
formats in SAS procedures, see Base SAS Procedures Guide.
User-Defined Formats
In addition to the formats that are supplied with Base SAS software, you can create
your own formats. In Base SAS software, PROC FORMAT allows you to create your
own formats for both character and numeric variables. For more information, see “The
FORMAT Procedure” in Base SAS Procedures Guide.
When you execute a SAS program that uses user-defined formats, these formats
should be available. The two ways to make these formats available are
3 to create permanent, not temporary, formats with PROC FORMAT
3 to store the source code that creates the formats (the PROC FORMAT step) with
the SAS program that uses them.
To create permanent SAS formats, see “The FORMAT Procedure” in Base SAS
Procedures Guide.
If you execute a program that cannot locate a user-defined format, the result depends
on the setting of the FMTERR system option. If the user-defined format is not found,
then these system options produce these results:
System Options
Results
FMTERR
SAS produces an error that causes the current DATA or
PROC step to stop.
NOFMTERR
SAS continues processing and substitutes a default format,
usually the BESTw. or $w. format.
Although using NOFMTERR enables SAS to process a variable, you lose the
information that the user-defined format supplies.
To avoid problems, make sure that your program has access to all user-defined
formats that are used.
88
Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms
4
Chapter 3
Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms
Definitions
Integer values for binary integer data are typically stored in one of three sizes:
one-byte, two-byte, or four-byte. The ordering of the bytes for the integer varies
depending on the platform (operating environment) on which the integers were
produced.
The ordering of bytes differs between the “big endian” and “little endian” platforms.
These colloquial terms are used to describe byte ordering for IBM mainframes (big
endian) and for Intel-based platforms (little endian). In the SAS System, the following
platforms are considered big endian: AIX, HP-UX, IBM mainframe, Macintosh, and
Solaris on SPARC. The following platforms are considered little endian: Intel ABI,
Linux, OpenVMS Alpha, OpenVMS Integrity, Solaris on x64, Tru64 UNIX, and
Windows.
How Bytes are Ordered Differently
On big endian platforms, the value 1 is stored in binary and is represented here in
hexadecimal notation. One byte is stored as 01, two bytes as 00 01, and four bytes as 00
00 00 01. On little endian platforms, the value 1 is stored in one byte as 01 (the same
as big endian), in two bytes as 01 00, and in four bytes as 01 00 00 00.
If an integer is negative, the “two’s complement” representation is used. The
high-order bit of the most significant byte of the integer will be set on. For example, –2
would be represented in one, two, and four bytes on big endian platforms as FE, FF FE,
and FF FF FF FE respectively. On little endian platforms, the representation would be
FE, FE FF, and FE FF FF FF. These representations result from the output of the
integer binary value –2 expressed in hexadecimal representation.
Writing Data Generated on Big Endian or Little Endian Platforms
SAS can read signed and unsigned integers regardless of whether they were
generated on a big endian or a little endian system. Likewise, SAS can write signed
and unsigned integers in both big endian and little endian format. The length of these
integers can be up to eight bytes.
The following table shows which format to use for various combinations of platforms.
In the Signed Integer column, “no” indicates that the number is unsigned and cannot be
negative. “Yes” indicates that the number can be either negative or positive.
Table 3.1 SAS Formats and Byte Ordering
Platform For Which the
Data Was Created
Platform That Writes the
Data
Signed
Integer
Format
big endian
big endian
yes
IB or S370FIB
big endian
big endian
no
PIB, S370FPIB,
S370FIBU
big endian
little endian
yes
S370FIB
Formats
4
Data Conversions and Encodings
Platform For Which the
Data Was Created
Platform That Writes the
Data
Signed
Integer
Format
big endian
little endian
no
S370FPIB
little endian
big endian
yes
IBR
little endian
big endian
no
PIBR
little endian
little endian
yes
IB or IBR
little endian
little endian
no
PIB or PIBR
big endian
either
yes
S370FIB
big endian
either
no
S370FPIB
little endian
either
yes
IBR
little endian
either
no
PIBR
89
Integer Binary Notation and Different Programming Languages
The following table compares integer binary notation according to programming
language.
Table 3.2 Integer Binary Notation and Programming Languages
Language
2 Bytes
4 Bytes
SAS
IB2. , IBR2., PIB2., PIBR2.,
S370FIB2., S370FIBU2.,
S370FPIB2.
IB4., IBR4., PIB4., PIBR4.,
S370FIB4., S370FIBU4.,
S370FPIB4.
PL/I
FIXED BIN(15)
FIXED BIN(31)
Fortran
INTEGER*2
INTEGER*4
COBOL
COMP PIC 9(4)
COMP PIC 9(8)
IBM assembler
H
F
C
short
long
Data Conversions and Encodings
An encoding maps each character in a character set to a unique numeric
representation, resulting in a table of all code points. A single character can have
different numeric representations in different encodings. For example, the ASCII
encoding for the dollar symbol $ is 24 hexadecimal. The Danish EBCDIC encoding for
the dollar symbol $ is 67 hexadecimal. In order for a version of SAS that normally uses
ASCII to properly interpret a data set that is encoded in Danish EBCDIC, the data
must be transcoded.
Transcoding is the process of moving data from one encoding to another. When
transcoding the ASCII dollar sign to the Danish EBCDIC dollar sign, the hexadecimal
representation for the character is converted from the value 24 to a 67.
If you want to know the encoding of a particular SAS data set, for SAS 9 and above
follow these steps:
1 Locate the data set with SAS Explorer.
90
Working with Packed Decimal and Zoned Decimal Data
4
Chapter 3
2 Right-click the data set.
3 Select Properties from the menu.
4 Click the Details tab.
5 The encoding of the data set is listed, along with other information.
Some situations where data might commonly be transcoded are:
3 when you share data between two different SAS sessions that are running in
different locales or in different operating environments,
3 when you perform text-string operations, such as converting to uppercase or
lowercase,
3 when you display or print characters from another language,
3 when you copy and paste data between SAS sessions running in different locales.
For more information about SAS features designed to handle data conversions from
different encodings or operating environments, see SAS National Language Support
(NLS): Reference Guide.
Working with Packed Decimal and Zoned Decimal Data
Definitions
Packed decimal
specifies a method of encoding decimal numbers by using each byte
to represent two decimal digits. Packed decimal representation
stores decimal data with exact precision. The fractional part of the
number is determined by the informat or format because there is no
separate mantissa and exponent.
An advantage of using packed decimal data is that exact precision
can be maintained. However, computations involving decimal data
might become inexact due to the lack of native instructions.
Zoned decimal
specifies a method of encoding decimal numbers in which each digit
requires one byte of storage. The last byte contains the number’s
sign as well as the last digit. Zoned decimal data produces a
printable representation.
Nibble
specifies 1/2 of a byte.
Types of Data
Packed Decimal Data
A packed decimal representation stores decimal digits in each “nibble” of a byte.
Each byte has two nibbles, and each nibble is indicated by a hexadecimal character. For
example, the value 15 is stored in two nibbles, using the hexadecimal characters 1 and 5.
The sign indication is dependent on your operating environment. On IBM
mainframes, the sign is indicated by the last nibble. With formats, C indicates a
positive value, and D indicates a negative value. With informats, A, C, E, and F
Formats
4
Languages Supporting Packed Decimal and Zoned Decimal Data
91
indicate positive values, and B and D indicate negative values. Any other nibble is
invalid for signed packed decimal data. In all other operating environments, the sign is
indicated in its own byte. If the high-order bit is 1, then the number is negative.
Otherwise, it is positive.
The following applies to packed decimal data representation:
3 You can use the S370FPD format on all platforms to obtain the IBM mainframe
configuration.
3 You can have unsigned packed data with no sign indicator. The packed decimal
format and informat handles the representation. It is consistent between ASCII
and EBCDIC platforms.
3 Note that the S370FPDU format and informat expects to have an F in the last
nibble, while packed decimal expects no sign nibble.
Zoned Decimal Data
The following applies to zoned decimal data representation:
3 A zoned decimal representation stores a decimal digit in the low order nibble of
each byte. For all but the byte containing the sign, the high-order nibble is the
numeric zone nibble (F on EBCDIC and 3 on ASCII).
3 The sign can be merged into a byte with a digit, or it can be separate, depending
on the representation. But the standard zoned decimal format and informat
expects the sign to be merged into the last byte.
3 The EBCDIC and ASCII zoned decimal formats produce the same printable
representation of numbers. There are two nibbles per byte, each indicated by a
hexadecimal character. For example, the value 15 is stored in two bytes. The first
byte contains the hexadecimal value F1 and the second byte contains the
hexadecimal value C5.
Packed Julian Dates
The following applies to packed Julian dates:
3 The two formats and informats that handle Julian dates in packed decimal
representation are PDJULI and PDJULG. PDJULI uses the IBM mainframe year
computation, while PDJULG uses the Gregorian computation.
3 The IBM mainframe computation considers 1900 to be the base year, and the year
values in the data indicate the offset from 1900. For example, 98 means 1998, 100
means 2000, and 102 means 2002. 1998 would mean 3898.
3 The Gregorian computation allows for 2-digit or 4-digit years. If you use 2-digit
years, SAS uses the setting of the YEARCUTOFF= system option to determine the
true year.
Platforms Supporting Packed Decimal and Zoned Decimal Data
Some platforms have native instructions to support packed and zoned decimal data,
while others must use software to emulate the computations. For example, the IBM
mainframe has an Add Pack instruction to add packed decimal data, but the
Intel-based platforms have no such instruction and must convert the decimal data into
some other format.
Languages Supporting Packed Decimal and Zoned Decimal Data
Several languages support packed decimal and zoned decimal data. The following
table shows how COBOL picture clauses correspond to SAS formats and informats.
92
Summary of Packed Decimal and Zoned Decimal Formats and Informats
4
Chapter 3
IBM VS COBOL II clauses
Corresponding S370Fxxx
formats/informats
PIC S9(X) PACKED-DECIMAL
S370FPDw.
PIC 9(X) PACKED-DECIMAL
S370FPDUw.
PIC S9(W) DISPLAY
S370FZDw.
PIC 9(W) DISPLAY
S370FZDUw.
PIC S9(W) DISPLAY SIGN LEADING
S370FZDLw.
PIC S9(W) DISPLAY SIGN LEADING SEPARATE
S370FZDSw.
PIC S9(W) DISPLAY SIGN TRAILING SEPARATE
S370FZDTw.
For the packed decimal representation listed above, X indicates the number of digits
represented, and W is the number of bytes. For PIC S9(X) PACKED-DECIMAL, W is
ceil((x+1)/2). For PIC 9(X) PACKED-DECIMAL, W is ceil(x/2). For example, PIC
S9(5) PACKED-DECIMAL represents five digits. If a sign is included, six nibbles are
needed. ceil((5+1)/2) has a length of three bytes, and the value of W is 3.
Note that you can substitute COMP-3 for PACKED-DECIMAL.
In IBM assembly language, the P directive indicates packed decimal, and the Z
directive indicates zoned decimal. The following shows an excerpt from an assembly
language listing, showing the offset, the value, and the DC statement:
offset
value (in hex)
+000000
+000003
+000006
+000009
00001C
00001D
F0F0C1
F0F0D1
inst label
2
3
4
5
PEX1
PEX2
ZEX1
ZEX2
directive
DC
DC
DC
DC
PL3’1’
PL3’-1’
ZL3’1’
ZL3’1’
In PL/I, the FIXED DECIMAL attribute is used in conjunction with packed decimal
data. You must use the PICTURE specification to represent zoned decimal data. There
is no standardized representation of decimal data for the Fortran or the C languages.
Summary of Packed Decimal and Zoned Decimal Formats and
Informats
SAS uses a group of formats and informats to handle packed and zoned decimal data.
The following table lists the type of data representation for these formats and
informats. Note that the formats and informats that begin with S370 refer to IBM
mainframe representation.
Format
Type of data
representation
Corresponding
informat
Comments
PD
Packed decimal
PD
Local signed packed decimal
PK
Packed decimal
PK
Unsigned packed decimal; not
specific to your operating
environment
Formats
4
Summary of Packed Decimal and Zoned Decimal Formats and Informats
Format
Type of data
representation
Corresponding
informat
Comments
ZD
Zoned decimal
ZD
Local zoned decimal
none
Zoned decimal
ZDB
Translates EBCDIC blank
(hexadecimal 40) to EBCDIC
zero (hexadecimal F0);
corresponds to the informat
as zoned decimal
none
Zoned decimal
ZDV
Non-IBM zoned decimal
representation
S370FPD
Packed decimal
S370FPD
Last nibble C (positive) or D
(negative)
S370FPDU
Packed decimal
S370FPDU
Last nibble always F
(positive)
S370FZD
Zoned decimal
S370FZD
Last byte contains sign in
upper nibble: C (positive) or
D (negative)
S370FZDU
Zoned decimal
S370FZDU
Unsigned; sign nibble always
F
S370FZDL
Zoned decimal
S370FZDL
Sign nibble in first byte in
informat; separate leading
sign byte of hexadecimal C0
(positive) or D0 (negative) in
format
S370FZDS
Zoned decimal
S370FZDS
Leading sign of (hexadecimal 60) or +
(hexadecimal 4E)
S370FZDT
Zoned decimal
S370FZDT
Trailing sign of (hexadecimal 60) or +
(hexadecimal 4E)
PDJULI
Packed decimal
PDJULI
Julian date in packed
representation - IBM
computation
PDJULG
Packed decimal
PDJULG
Julian date in packed
representation - Gregorian
computation
none
Packed decimal
RMFDUR
Input layout is: mmsstttF
none
Packed decimal
SHRSTAMP
Input layout is:
yyyydddFhhmmssth, where
yyyydddF is the packed
Julian date; yyyy is a 0-based
year from 1900
none
Packed decimal
SMFSTAMP
Input layout is:
xxxxxxxxyyyydddF, where
yyyydddF is the packed
Julian date; yyyy is a 0-based
year from 1900
93
94
Working with Dates and Times Using the ISO 8601 Basic and Extended Notations
4
Chapter 3
Format
Type of data
representation
Corresponding
informat
Comments
none
Packed decimal
PDTIME
Input layout is: 0hhmmssF
none
Packed decimal
RMFSTAMP
Input layout is:
0hhmmssFyyyydddF, where
yyyydddF is the packed
Julian date; yyyy is a 0-based
year from 1900
Working with Dates and Times Using the ISO 8601 Basic and Extended
Notations
ISO 8601 Formatting Symbols
The following list explains the formatting symbols that are used to notate the ISO
8601 dates, time, datetime, durations, and interval values:
n
specifies a number that represents the number of years, months, or
days
P
indicates that the duration that follows is specified by the number of
years, months, days, hours, minutes, and seconds
T
indicates that a time value follows. Any value with a time must
begin with T.
Time values that are read by the extended notation
informats that begin with the characters E8601 must use an
uppercase T.
Requirement:
W
indicates that the duration is specified in weeks.
Z
indicates that the time value is the time in Greenwich, England, or
UTC time.
+|-
the + indicates the time zone offset to the east of Greenwich,
England. The - indicates the time zone offset to the west of
Greenwich, England.
yyyy
specifies a four-digit year
mm
as part of a date, specifies a two-digit month, 01 - 12
dd
specifies a two-digit day, 01 - 31
hh
specifies a two-digit hour, 00 - 24
mm
as part of a time, specifies a two-digit minute, 00 - 59
ss
specifies a two-digit second, 00 - 59
fff | ffffff
specifies an optional fraction of a second using the digits 0 - 9:
fff
use 1 - 3 digits for values read by the $N8601B
informat and the $N8601E informat
Formats
ffffff
4
Writing ISO 8601 Date, Time, and Datetime Values
95
use 1 - 6 digits for informat other than the
$N8601B informat and the $N8601E informat
Y
indicates that a year value proceeds this character in a duration
M
as part of a date, indicates that a month value proceeds this
character in a duration
D
indicates that a day value proceeds this character in a duration
H
indicates that an hour value proceeds this character in a duration
M
as part of a time, indicates that a minute value proceeds this
character in a duration
S
indicates that a seconds value proceeds this character in a duration
Writing ISO 8601 Date, Time, and Datetime Values
SAS uses the formats in the following table to write date, time, and datetime values
in the ISO 8601 basic and extended notations from SAS date, time, and datetime values.
Table 3.3 Formats for Writing ISO 8601 Dates, Times, and Datetimes
Date, Time, or Datetime
ISO 8601 Notation
Example
Format
Date
yyyymmdd
20080915
B8601DAw.
Time
hhmmssffffff
155300322348
B8601TMw.d
Time with time zone
hhmmss+|-hhmm
155300+0500
B8601TZw.d
hhmmssZ
155300Z
B8601TZw.d
Convert to local time with
time zone
hhmmss+|-hhmm
155300+0500
B8601LZw.d
Datetime
yyyymmddThhmmssffffff
20080915T155300
B8601DTw.d
Datetime with timezone
yyyymmddThhmmss+|hhmm
20080915T155300+0500
B8601DZw.d
yyyymmddThhmmssZ
20080915T155300Z
B8601DZw.d
yyyymmdd
20080915
B8601DNw.
Date
yyyy-mm-dd
2008-09-15
E8601DAw.
Time
hh:mm:ss.ffffff
15:53:00.322348
E8601TMw.d
Time with time zone
hh:mm:ss.ffffff+|-hh:mm
15:53:00+05:00
E8601TZw.d
Convert to local time with
time zone
hh:mm:ss.ffffff+|-hh:mm
15:53:00+05:00
E8601LZw.d
Datetime
yyyy-mmddThh:mm:ss.ffffff
2008-09-15T15:53:00
E8601TZw.d
Basic Notations
Write the date from a
datetime
Extended Notations
96
Writing ISO 8601 Duration, Datetime, and Interval Values
4
Chapter 3
Date, Time, or Datetime
ISO 8601 Notation
Example
Format
Datetime with time zone
yyyy-mmddThh:mm:ss.nnnnnn+|hh:mm
2008-0915T15:53:00+05:00
E8601DZw.d
Write the date from a
datetime
yyyy-mm-dd
2008-09-15
E8601DNw.
An asterisk ( * )used in place of a date or time formatted value that is out-of-range.
Writing ISO 8601 Duration, Datetime, and Interval Values
Duration, Datetime, and Interval Formats
SAS writes duration, datetime, and interval values from character data using these
formats:
Time Component
ISO 8601 Notation
Duration - Basic
Notation
PyyyymmddThhmmssfff P20080915T155300
$N8601BA
-PyyyymmddThhmmssfff -P20080915T155300
$N8601BA
Pyyyy-mmddThh:mm:ss.fff
P2008-09-15T15:53:00
$N8601EA
-Pyyyy-mmddThh:mm:ss.fff
-P2008-09-15T15:53:00
$N8601EA
PnYnMnDTnHnMnS
P2y10m14dT20h13m45s $N8601B
Duration - Extended
Notation
Duration - Basic and
Extended Notation
Example
Format
$N8601E
-PnYnMnDTnHnMnS
-P2y10m14dT20h13m45s $N8601B
$N8601E
PnW (weeks)
P6w
$N8601B
$N8601E
Interval - Basic
Notation
Interval- Extended
Notation
yyyymmddThhmmssfff/
yyyymmddThhmmssfff
20080915T155300/
20101113T000000
PnYnMnDTnHnMnS/
yyyymmddThhmmssfff
P2y10M14dT20h13m45s/ $N8601B
20080915T155300
yyyymmddThhmmssfff/
PnYnMnDTnHnMnS
20080915T155300/
$N8601BA
P2y10M14dT20h13m45s
yyyy-mmddThh:mm:ss.fff/
yyyy-mmddThh:mm:ss.fff
2008-09-15T15:53:00/
2010-11-13T00:00:00
PnYnMnDTnHnMnS/
yyyy-mmddThh:mm:ss.fff
P2y10M14dT20h13m45s/ $N8601E
2008-09-15T15:53:00
yyyy-mmddThh:mm:ss.fff/
PnYnMnDTnHnMnS
2008-09-15T15:53:00/
$N8601EA
P2y10M14dT20h13m45s
$N8601BA
$N8601EA
Formats
4
Writing ISO 8601 Duration, Datetime, and Interval Values
Time Component
ISO 8601 Notation
Example
Datetime-Basic
Notation
yyyymmddThhmmss.fff+|-20080915T155300
hhmm
$N8601BA
(all blank)
$N8601B
97
Format
$N8601BA
$N8601E
$N8601EA
Datetime-Extended
Notation
yyyy-mmddThh:mm:ss.fff+|hhmm
2008-09-15T15:53:00
$N8601EA
+04:30
(all blank)
$N8601B
$N8601BA
$N8601E
$N8601EA
Writing Omitted Components
An omitted component can be represented by a hyphen ( - ) or an x in the extended
datetime form yyyy-mm-ddThh:mm:ss and in the extended duration form
Pyyyy-mm-ddThh:mm:ss.
Omitted components in the durations form PnYnMnDTnHnMnS are dropped, they do
not contain a hyphen or x. For example, P2mT4H.
The following formats write omitted components that use the hyphen and the x:
Format
Datetime Form
Duration Form
Examples
$N8601H
yyyy-mmddThh:mm:ss
PnYnMnDTnHnMnS
–09-15T15:-:53
$N8601EH
yyyy-mmddThh:mm:ss
Pyyyy-mmddThh:mm:ss
P000—02T02:55:20/
2008—15T-:-:45
$N8601X
yyyy-mmddThh:mm:ss
PnYnMnDTnHnMnS
P2Y2DT4H5M6S/
x-09-15T15:x:00
$N8601EX
yyyy-mmddThh:mm:ss
Pyyyy-mmddThh:mm:ss
P0003-x-02T02:55:20/
2008-x-15Tx:x:45
P2Y2DT4H5M6S/
–09-15T15:-:00
Datetime values with omitted components that are formatted with either the $N8601B
format or the $N8601BA format are formatted in the extended notation using the
hyphen for omitted components to ensure accurate data. For example, when the month
is an omitted component, the value 2008—15 is written and not 2008-15.
The extended notation with hyphens is also used in place of the basic notation if a
duration is formatted by using the $N8601BA format. Using the same date, P2008—15
is written and not P2008-15.
98
Writing ISO 8601 Duration, Datetime, and Interval Values
4
Chapter 3
Writing Truncated Duration, Datetime, and Interval Values
Duration, datetime, or interval values can be truncated when one or more lower
order values is 0 or is not significant. When SAS writes a truncated value using the
formats $N8601B, $N8601BA, $N8601E, and $N8601EA, the display of the value stops
at the last non-missing component.
When you format a truncated value by using either the $N8601H format or the
$N8601EH format, the lower order components are written with a hyphen. When you
format a truncated value by using the $N8601X format or the $N8601EX format, the
lower order components are written with an x.
The following examples show truncated values:
p00030202T1031
2008-09-15T15/2010-09-15T15:53
-p0003-03-03T-:-:P2y3m4dT5h6m
2008-09-xTx:x:x
2008
Normalizing Duration Components
When a value for a duration component is greater than the largest standard value
for a component, SAS normalizes the component except when the duration component
is a single component. The following table shows examples of normalized duration
components:
Duration
Extended Normalized Duration
p3y13m
p0004-01
pt24h24m65s
P----01T-:25:05
p3y13mT24h61m
P0004-01-01T01:01
p0004-13
p0005-01
p0003-02-61T15:61:61
P0003-04-01T16:02:01
p13m
P13M
If a component contains the largest value, such as 60 for minutes or seconds, SAS
normalizes the value and replaces the value with a hyphen. For example, pT12:60:13
becomes PT13:-:13.
Thirty days is used to normalize a month.
Dates and times in a datetime value that are greater than the standard value for the
component are not normalized. They produce an error.
Fractions in Durations, Datetime, and Interval Values
Ending components can contain a fraction that consists of a period or a comma,
followed by one to three digits. The following examples show the use of fractions in
duration, datetime, and interval values:
200809.5
P2008-09-15T10.33
2008-09-15/P0003-03-03,333
Formats
4
Formats by Category
99
Formats by Category
There are four categories of formats in this list:
Category
Description
Character
instructs SAS to write character data values from character variables.
Date and Time
instructs SAS to write data values from variables that represent dates,
times, and datetimes.
ISO 8601
instructs SAS to write date, time, and datetime values using the ISO
8601 standard.
Numeric
instructs SAS to write numeric data values from numeric variables.
Formats that support national languages can be found in SAS National Language
Support (NLS): Reference Guide. A listing of national language formats is provided in .
Storing user-defined formats is an important consideration if you associate these
formats with variables in permanent SAS data sets, especially those data sets shared
with other users. For information about creating and storing user-defined formats, see
“The FORMAT Procedure” in Base SAS Procedures Guide.
The following table provides brief descriptions of the SAS formats. For more detailed
descriptions, see the dictionary entry for each format.
Table 3.4 Categories and Descriptions of Formats
Category
Formats
Description
Character
“$ASCIIw. Format” on
page 108
Converts native format character data to ASCII
representation.
“$BASE64Xw. Format” on
page 109
Converts character data into ASCII text by using Base
64 encoding.
“$BINARYw. Format” on
page 110
Converts character data to binary representation.
“$CHARw. Format” on
page 111
Writes standard character data.
“$EBCDICw. Format” on
page 112
Converts native format character data to EBCDIC
representation.
“$HEXw. Format” on page
113
Converts character data to hexadecimal representation.
“$MSGCASEw. Format”
on page 114
Writes character data in uppercase when the MSGCASE
system option is in effect.
“$OCTALw. Format” on
page 125
Converts character data to octal representation.
“$QUOTEw. Format” on
page 126
Writes data values that are enclosed in double quotation
marks.
“$REVERJw. Format” on
page 127
Writes character data in reverse order and preserves
blanks.
100
Formats by Category
Category
Date and Time
4
Chapter 3
Formats
Description
“$REVERSw. Format” on
page 128
Writes character data in reverse order and left aligns
“$UPCASEw. Format” on
page 129
Converts character data to uppercase.
“$VARYINGw. Format” on
page 130
Writes character data of varying length.
“$w. Format” on page 131
Writes standard character data.
“$N8601Bw.d Format” on
page 115
Writes ISO 8601 duration, datetime, and interval forms
using the basic notations PnYnMnDTnH nMnS and
yyyymmddThhmmss.
“$N8601BAw.d Format” on
page 116
Writes ISO 8601 duration, datetime, and interval forms
using the basic notations PyyyymmddThhmmss and
yyyymmdd Thhmmss.
“$N8601Ew.d Format” on
page 117
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations PnYnMnDTn HnMnS and
yyyy-mm-ddT hh:mm:ss.
“$N8601EAw.d Format” on
page 119
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations Pyyyy-mm-ddThh:mm:ss
and yyyy-mm-ddThh:mm:ss.
“$N8601EHw.d Format”
on page 120
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations Pyyyy-mm-ddThh:mm:ss
and yyyy-mm-ddThh:mm:ss, using a hyphen ( - )for
omitted components.
“$N8601EXw.d Format” on
page 121
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations Pyyyy-mm-ddThh:mm:ss
and yyyy-mm-ddThh:mm:ss, using an x for digit of an
omitted component.
“$N8601Hw.d Format” on
page 122
Writes ISO 8601 duration, datetime, and interval forms
P nYnMnDTnHnM nS and yyyy-mm-ddThh:mm:ss,
dropping omitted components in duration values and
using a hyphen ( - )for omitted components in datetime
values.
“$N8601Xw.d Format” on
page 124
Writes ISO 8601 duration, datetime, and interval forms
P nYnMnDTnHnM nS and yyyy-mm-ddThh:mm:ss,
dropping omitted components in duration values and
using an x for each digit of an omitted component in
datetime values.
“B8601DAw. Format” on
page 136
Writes date values using the IOS 8601 base notation
yyyymmdd .
“B8601DNw. Format” on
page 137
Writes the date from a datetime value using the ISO
8601 basic notation yyyymmdd.
“B8601DTw.d Format” on
page 138
Writes datetime values in the ISO 8601 basic notation
yyyymmdd Thhmmssffffff.
“B8601DZw. Format” on
page 139
Writes datetime values in the Coordinated Universal
Time (UTC) time scale using ISO 8601 datetime and
time zone basic notation yyyymmdd Thhmmss+|-hhmm.
Formats
Category
4
Formats by Category
Formats
Description
“B8601LZw. Format” on
page 141
Writes time values as local time by appending a time zone
offset difference between the local time and UTC, using
the ISO 8601 basic time notation hhmmss+|-hhmm.
“B8601TMw.d Format” on
page 142
Writes time values using the ISO 8601 basic notation
hhmmssffff .
“B8601TZw. Format” on
page 143
Adjusts time values to the Coordinated Universal Time
(UTC) and writes them using the ISO 8601 basic time
notation hhmmss+|- hhmm.
“DATEw. Format” on page
148
Writes date values in the form ddmmmyy, ddmmmyyyy ,
or dd-mmm-yyyy.
“DATEAMPMw.d Format”
on page 150
Writes datetime values in the form
ddmmmyy:hh:mm:ss.ss with AM or PM.
“DATETIMEw.d Format”
on page 151
Writes datetime values in the form
ddmmmyy:hh:mm:ss.ss.
“DAYw. Format” on page
153
Writes date values as the day of the month.
“DDMMYYw. Format” on
page 154
Writes date values in the form ddmm<yy> yy or dd/mm/
<yy>yy , where a forward slash is the separator and the
year appears as either 2 or 4 digits.
“DDMMYYxw. Format” on
page 155
Writes date values in the form ddmm<yy> yy or
dd-mm-yy<yy>, where the x in the format name is a
character that represents the special character that
separates the day, month, and year, which can be a
hyphen (-), period (.), blank character, slash (/), colon (:),
or no separator; the year can be either 2 or 4 digits.
“DOWNAMEw. Format”
on page 160
Writes date values as the name of the day of the week.
“DTDATEw. Format” on
page 161
Expects a datetime value as input and writes date values
in the form ddmmmyy or ddmmmyyyy.
“DTMONYYw. Format” on
page 162
Writes the date part of a datetime value as the month
and year in the form mmmyy or mmmyyyy.
“DTWKDATXw. Format”
on page 163
Writes the date part of a datetime value as the day of the
week and the date in the form day-of-week, dd
month-name yy (or yyyy).
“DTYEARw. Format” on
page 164
Writes the date part of a datetime value as the year in
the form yy or yyyy.
“DTYYQCw. Format” on
page 165
Writes the date part of a datetime value as the year and
the quarter and separates them with a colon (:).
“E8601DAw. Format” on
page 167
Writes date values using the ISO 8601 extended notation
yyyy-mm-dd.
“E8601DNw. Format” on
page 168
Writes the date from a SAS datetime value using the
ISO 8601 extended notation yyyy-mm-dd.
“E8601DTw.d Format” on
page 169
Writes datetime values in the ISO 8601 extended
notation yyyy-mm-ddThh:mm:ss.ffffff.
101
102
Formats by Category
Category
4
Chapter 3
Formats
Description
“E8601DZw. Format” on
page 170
Writes datetime values in the Coordinated Universal
Time (UTC) time scale using ISO 8601 datetime and
time zone extended notations
yyyy-mm-ddThh:mm:ss+|-hh:mm.
“E8601LZw. Format” on
page 172
Writes time values as local time, appending the
Coordinated Universal Time (UTC) offset for the local
SAS session, using the ISO 8601 extended time notation
hh:mm:ss+|-hh:mm.
“E8601TMw.d Format” on
page 174
Writes time values using the ISO 8601 extended notation
hh:mm:ss.ffffff.
“E8601TZw.d Format” on
page 175
Adjusts time values to the Coordinated Universal Time
(UTC) and writes them using the ISO 8601 extended
notation hh:mm :ss+|-hh:mm.
“HHMMw.d Format” on
page 180
Writes time values as hours and minutes in the form
hh:mm .
“HOURw.d Format” on
page 182
Writes time values as hours and decimal fractions of
hours.
“JULDAYw. Format” on
page 187
Writes date values as the Julian day of the year.
“JULIANw. Format” on
page 188
Writes date values as Julian dates in the form yyddd or
yyyyddd.
“MMDDYYw. Format” on
page 190
Writes date values in the form mmdd<yy> yy or mm/dd/
<yy>yy , where a forward slash is the separator and the
year appears as either 2 or 4 digits.
“MMDDYYxw. Format” on
page 192
Writes date values in the form mmdd<yy> yy or
mm-dd-<yy>yy , where the x in the format name is a
character that represents the special character which
separates the month, day, and year. The special
character can be a hyphen (-), period (.), blank character,
slash (/), colon (:), or no separator; the year can be either
2 or 4 digits.
“MMSSw.d Format” on
page 194
Writes time values as the number of minutes and
seconds since midnight.
“MMYYw. Format” on
page 195
Writes date values in the form mmM<yy> yy, where M is
the separator and the year appears as either 2 or 4 digits.
“MMYYxw. Format” on
page 196
Writes date values in the form mm<yy> yy or
mm-<yy>yy, where the x in the format name is a
character that represents the special character that
separates the month and the year, which can be a
hyphen (-), period (.), blank character, slash (/), colon (:),
or no separator; the year can be either 2 or 4 digits.
“MONNAMEw. Format”
on page 198
Writes date values as the name of the month.
“MONTHw. Format” on
page 199
Writes date values as the month of the year.
Formats
Category
4
Formats by Category
Formats
Description
“MONYYw. Format” on
page 200
Writes date values as the month and the year in the
form mmmyy or mmmyyyy.
“PDJULGw. Format” on
page 207
Writes packed Julian date values in the hexadecimal
format yyyydddF for IBM.
“PDJULIw. Format” on
page 208
Writes packed Julian date values in the hexadecimal
format ccyydddF for IBM.
“QTRw. Format” on page
217
Writes date values as the quarter of the year.
“QTRRw. Format” on page
218
Writes date values as the quarter of the year in Roman
numerals.
“TIMEw.d Format” on
page 239
Writes time values as hours, minutes, and seconds in the
form hh:mm:ss.ss.
“TIMEAMPMw.d Format”
on page 241
Writes time values as hours, minutes, and seconds in the
form hh:mm:ss.ss with AM or PM.
“TODw.d Format” on page
242
Writes SAS time values and the time portion of SAS
datetime values in the form hh:mm:ss.ss.
“WEEKDATEw. Format”
on page 247
Writes date values as the day of the week and the date
in the form day-of-week, month-name dd, yy (or yyyy).
“WEEKDATXw. Format”
on page 249
Writes date values as the day of the week and date in
the form day-of-week, dd month-name yy (or yyyy).
“WEEKDAYw. Format” on
page 250
Writes date values as the day of the week.
“WEEKUw. Format” on
page 251
Writes a week number in decimal format by using the U
algorithm.
“WEEKVw. Format” on
page 253
Writes a week number in decimal format by using the V
algorithm.
“WEEKWw. Format” on
page 255
Writes a week number in decimal format by using the W
algorithm.
“WORDDATEw. Format”
on page 257
Writes date values as the name of the month, the day,
and the year in the form month-name dd, yyyy.
“WORDDATXw. Format”
on page 258
Writes date values as the day, the name of the month,
and the year in the form dd month-name yyyy.
“YEARw. Format” on page
261
Writes date values as the year.
“YYMMw. Format” on
page 262
Writes date values in the form <yy>yyM mm, where M is
a character separator to indicate that the month number
follows the M and the year appears as either 2 or 4 digits.
“YYMMxw. Format” on
page 263
Writes date values in the form <yy>yymm or <yy>yy-mm,
where the x in the format name is a character that
represents the special character that separates the year
and the month, which can be a hyphen (-), period (.),
blank character, slash (/), colon (:), or no separator; the
year can be either 2 or 4 digits.
103
104
Formats by Category
Category
ISO 8601
4
Chapter 3
Formats
Description
“YYMMDDw. Format” on
page 265
Writes date values in the form yymmdd or <
yy>yy-mm-dd, where a dash is the separator and the
year appears as either 2 or 4 digits.
“YYMMDDxw. Format” on
page 266
Writes date values in the form yymmdd or <
yy>yy-mm-dd, where the x in the format name is a
character that represents the special character which
separates the year, month, and day. The special
character can be a hyphen (-), period (.), blank character,
slash (/), colon (:), or no separator; the year can be either
2 or 4 digits.
“YYMONw. Format” on
page 268
Writes date values in the form yymmm or yyyymmm .
“YYQw. Format” on page
269
Writes date values in the form <yy>yyQ q, where Q is the
separator, the year appears as either 2 or 4 digits, and q
is the quarter of the year.
“YYQxw. Format” on page
270
Writes date values in the form <yy>yyq or <yy>yy-q,
where the x in the format name is a character that
represents the special character that separates the year
and the quarter or the year, which can be a hyphen (-),
period (.), blank character, slash (/), colon (:), or no
separator; the year can be either 2 or 4 digits.
“YYQRw. Format” on page
272
Writes date values in the form <yy>yyQ qr, where Q is the
separator, the year appears as either 2 or 4 digits, and qr
is the quarter of the year expressed in roman numerals.
“YYQRxw. Format” on
page 273
Writes date values in the form <yy>yy qr or <yy>yy-qr,
where the x in the format name is a character that
represents the special character that separates the year
and the quarter or the year, which can be a hyphen (-),
period (.), blank character, slash (/), colon (:), or no
separator; the year can be either 2 or 4 digits and qr is
the quarter of the year expressed in roman numerals.
“$N8601Bw.d Format” on
page 115
Writes ISO 8601 duration, datetime, and interval forms
using the basic notations PnYnMnDTnH nMnS and
yyyymmddThhmmss.
“$N8601BAw.d Format” on
page 116
Writes ISO 8601 duration, datetime, and interval forms
using the basic notations PyyyymmddThhmmss and
yyyymmdd Thhmmss.
“$N8601Ew.d Format” on
page 117
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations PnYnMnDTn HnMnS and
yyyy-mm-ddT hh:mm:ss.
“$N8601EAw.d Format” on
page 119
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations Pyyyy-mm-ddThh:mm:ss
and yyyy-mm-ddThh:mm:ss.
“$N8601EHw.d Format”
on page 120
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations Pyyyy-mm-ddThh:mm:ss
and yyyy-mm-ddThh:mm:ss, using a hyphen ( - )for
omitted components.
Formats
Category
4
Formats by Category
Formats
Description
“$N8601EXw.d Format” on
page 121
Writes ISO 8601 duration, datetime, and interval forms
using the extended notations Pyyyy-mm-ddThh:mm:ss
and yyyy-mm-ddThh:mm:ss, using an x for digit of an
omitted component.
“$N8601Hw.d Format” on
page 122
Writes ISO 8601 duration, datetime, and interval forms
P nYnMnDTnHnM nS and yyyy-mm-ddThh:mm:ss,
dropping omitted components in duration values and
using a hyphen ( - )for omitted components in datetime
values.
“$N8601Xw.d Format” on
page 124
Writes ISO 8601 duration, datetime, and interval forms
P nYnMnDTnHnM nS and yyyy-mm-ddThh:mm:ss,
dropping omitted components in duration values and
using an x for each digit of an omitted component in
datetime values.
“B8601DAw. Format” on
page 136
Writes date values using the IOS 8601 base notation
yyyymmdd .
“B8601DNw. Format” on
page 137
Writes the date from a datetime value using the ISO
8601 basic notation yyyymmdd.
“B8601DTw.d Format” on
page 138
Writes datetime values in the ISO 8601 basic notation
yyyymmdd Thhmmssffffff.
“B8601DZw. Format” on
page 139
Writes datetime values in the Coordinated Universal
Time (UTC) time scale using ISO 8601 datetime and
time zone basic notation yyyymmdd Thhmmss+|-hhmm.
“B8601LZw. Format” on
page 141
Writes time values as local time by appending a time zone
offset difference between the local time and UTC, using
the ISO 8601 basic time notation hhmmss+|-hhmm.
“B8601TMw.d Format” on
page 142
Writes time values using the ISO 8601 basic notation
hhmmssffff .
“B8601TZw. Format” on
page 143
Adjusts time values to the Coordinated Universal Time
(UTC) and writes them using the ISO 8601 basic time
notation hhmmss+|- hhmm.
“E8601DAw. Format” on
page 167
Writes date values using the ISO 8601 extended notation
yyyy-mm-dd.
“E8601DNw. Format” on
page 168
Writes the date from a SAS datetime value using the
ISO 8601 extended notation yyyy-mm-dd.
“E8601DTw.d Format” on
page 169
Writes datetime values in the ISO 8601 extended
notation yyyy-mm-ddThh:mm:ss.ffffff.
“E8601DZw. Format” on
page 170
Writes datetime values in the Coordinated Universal
Time (UTC) time scale using ISO 8601 datetime and
time zone extended notations
yyyy-mm-ddThh:mm:ss+|-hh:mm.
“E8601LZw. Format” on
page 172
Writes time values as local time, appending the
Coordinated Universal Time (UTC) offset for the local
SAS session, using the ISO 8601 extended time notation
hh:mm:ss+|-hh:mm.
105
106
Formats by Category
Category
Numeric
4
Chapter 3
Formats
Description
“E8601TMw.d Format” on
page 174
Writes time values using the ISO 8601 extended notation
hh:mm:ss.ffffff.
“E8601TZw.d Format” on
page 175
Adjusts time values to the Coordinated Universal Time
(UTC) and writes them using the ISO 8601 extended
notation hh:mm :ss+|-hh:mm.
“BESTw. Format” on page
132
SAS chooses the best notation.
“BESTDw.p Format” on
page 134
Prints numeric values, lining up decimal places for
values of similar magnitude, and prints integers without
decimals.
“BINARYw. Format” on
page 135
Converts numeric values to binary representation.
“COMMAw.d Format” on
page 145
Writes numeric values with a comma that separates
every three digits and a period that separates the
decimal fraction.
“COMMAXw.d Format” on
page 146
Writes numeric values with a period that separates every
three digits and a comma that separates the decimal
fraction.
“Dw.p Format” on page 147
Prints numeric values, possibly with a great range of
values, lining up decimal places for values of similar
magnitude.
“DOLLARw.d Format” on
page 157
Writes numeric values with a leading dollar sign, a
comma that separates every three digits, and a period
that separates the decimal fraction.
“DOLLARXw.d Format” on
page 158
Writes numeric values with a leading dollar sign, a
period that separates every three digits, and a comma
that separates the decimal fraction.
“Ew. Format” on page 166
Writes numeric values in scientific notation.
“FLOATw.d Format” on
page 177
Generates a native single-precision, floating-point value
by multiplying a number by 10 raised to the dth power.
“FRACTw. Format” on
page 178
Converts numeric values to fractions.
“HEXw. Format” on page
179
Converts real binary (floating-point) values to
hexadecimal representation.
“IBw.d Format” on page
183
Writes native integer binary (fixed-point) values,
including negative values.
“IBRw.d Format” on page
184
Writes integer binary (fixed-point) values in Intel and
DEC formats.
“IEEEw.d Format” on page
186
Generates an IEEE floating-point value by multiplying a
number by 10 raised to the dth power.
“NEGPARENw.d Format”
on page 201
Writes negative numeric values in parentheses.
“NUMXw.d Format” on
page 202
Writes numeric values with a comma in place of the
decimal point.
Formats
Category
4
Formats by Category
Formats
Description
“OCTALw. Format” on
page 204
Converts numeric values to octal representation.
“PDw.d Format” on page
205
Writes data in packed decimal format.
“PERCENTw.d Format” on
page 209
Writes numeric values as percentages.
“PERCENTNw.d Format”
on page 210
Produces percentages, using a minus sign for negative
values.
“PIBw.d Format” on page
212
Writes positive integer binary (fixed-point) values.
“PIBRw.d Format” on page
213
Writes positive integer binary (fixed-point) values in
Intel and DEC formats.
“PKw.d Format” on page
215
Writes data in unsigned packed decimal format.
“PVALUEw.d Format” on
page 216
Writes p-values.
“RBw.d Format” on page
219
Writes real binary data (floating-point) in real binary
format.
“ROMANw. Format” on
page 220
Writes numeric values as roman numerals.
“S370FFw.d Format” on
page 221
Writes native standard numeric data in IBM mainframe
format.
“S370FIBw.d Format” on
page 222
Writes integer binary (fixed-point) values, including
negative values, in IBM mainframe format.
“S370FIBUw.d Format” on
page 223
Writes unsigned integer binary (fixed-point) values in
IBM mainframe format.
“S370FPDw.d Format” on
page 225
Writes packed decimal data in IBM mainframe format.
“S370FPDUw.d Format”
on page 226
Writes unsigned packed decimal data in IBM mainframe
format.
“S370FPIBw.d Format” on
page 227
Writes positive integer binary (fixed-point) values in IBM
mainframe format.
“S370FRBw.d Format” on
page 228
Writes real binary (floating-point) data in IBM
mainframe format.
“S370FZDw.d Format” on
page 230
Writes zoned decimal data in IBM mainframe format.
“S370FZDLw.d Format” on
page 231
Writes zoned decimal leading–sign data in IBM
mainframe format.
“S370FZDSw.d Format” on
page 232
Writes zoned decimal separate leading-sign data in IBM
mainframe format.
“S370FZDTw.d Format” on
page 233
Writes zoned decimal separate trailing-sign data in IBM
mainframe format.
“S370FZDUw.d Format”
on page 234
Writes unsigned zoned decimal data in IBM mainframe
format.
107
108
Dictionary
4
Chapter 3
Category
Formats
Description
“SSNw. Format” on page
238
Writes Social Security numbers.
“VAXRBw.d Format” on
page 244
Writes real binary (floating-point) data in VMS format.
“VMSZNw.d Format” on
page 245
Generates VMS and MicroFocus COBOL zoned numeric
data.
“w.d Format” on page 246
Writes standard numeric data one digit per byte.
“WORDFw. Format” on
page 259
Writes numeric values as words with fractions that are
shown numerically.
“WORDSw. Format” on
page 260
Writes numeric values as words.
“Zw.d Format” on page 275
Writes standard numeric data with leading 0s.
“ZDw.d Format” on page
276
Writes numeric data in zoned decimal format .
Dictionary
$ASCIIw. Format
Converts native format character data to ASCII representation.
Category:
Alignment:
Character
left
Syntax
$ASCIIw.
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–32767
Details
If ASCII is the native format, no conversion occurs.
Comparisons
3 On EBCDIC systems, $ASCIIw. converts EBCDIC character data to ASCIIw.
Formats
4
$BASE64Xw. Format
109
3 On all other systems, $ASCIIw. behaves like the $CHARw. format.
Examples
put x $ascii3.;
Value of x
Results
abc
616263
ABC
414243
();
28293B
* The results are hexadecimal representations of ASCII codes for characters. Each two
hexadecimal characters correspond to one byte of binary data, and each byte corresponds to
one character.
$BASE64Xw. Format
Converts character data into ASCII text by using Base 64 encoding.
Category:
Character
Alignment:
left
Syntax
$BAS64Xw.
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1-32767
Details
Base 64 is an industry encoding method whose encoded characters are determined by
using a positional scheme that uses only ASCII characters. Several Base 64 encoding
schemes have been defined by the industry for specific uses, such as e-mail or content
masking. SAS maps positions 0 - 61 to the characters A - Z, a - z, and 0 - 9. Position 62
maps to the character +, and position 63 maps to the character /.
The following are some uses of Base 64 encoding:
3 embed binary data in an XML file
3 encode passwords
3 encode URLs
110
$BINARYw. Format
4
Chapter 3
The ’=’ character in the encoded results indicates that the results have been padded
with zero bits. In order for the encoded characters to be decoded, the ’=’ must be
included in the value to be decoded.
Examples
put x $base64x64.;
Value of x
Results
"FCA01A7993BC"
RkNBMDFBNzk5M0JD
"MyPassword"
TXlQYXNzd29yZA==
"www.mydomain.com/myhiddenURL"
d3d3Lm15ZG9tYWluLmNvbi9teWhpZGRlblVSTA==
See Also
Informat:
“$BASE64Xw. Informat” on page 1223
The XMLDOUBLE option of the LIBNAME Statement for the XML engine, in SAS
XML LIBNAME Engine: User’s Guide
$BINARYw. Format
Converts character data to binary representation.
Character
Alignment: left
Category:
Syntax
$BINARYw.
Syntax Description
w
specifies the width of the output field.
Default: The default width is calculated based on the length of the variable to be
printed.
Range: 1–32767
Comparisons
The $BINARYw. format converts character values to binary representation. The
BINARYw. format converts numeric values to binary representation.
Formats
4
$CHARw. Format
111
Examples
put @1 name $binary16.;
Value of name
AB
Results
ASCII
EBCDIC
----+----1----+----2
----+----1----+----2
0100000101000010
1100000111000010
$CHARw. Format
Writes standard character data.
Category: Character
Alignment:
left
Syntax
$CHARw.
Syntax Description
w
specifies the width of the output field.
Default: 8 if the length of variable is undefined; otherwise, the length of the variable
Range: 1–32767
Comparisons
3 The $CHARw. format is identical to the $w. format.
3 The $CHARw. and $w. formats do not trim leading blanks. To trim leading blanks,
use the LEFT function to left align character data, or use the PUT statement with
the colon (:) format modifier and the format of your choice to produce list output.
3 Use the following table to compare the SAS format $CHAR8. with notation in
other programming languages:
Language
Notation
SAS
$CHAR8.
C
char [8]
COBOL
PIC x(8)
Fortran
A8
PL/I
A(8)
112
$EBCDICw. Format
4
Chapter 3
Examples
put @7 name $char4.;
Value of name
Results
----+----1
XYZ
XYZ
$EBCDICw. Format
Converts native format character data to EBCDIC representation.
Category:
Character
Alignment:
left
Syntax
$EBCDICw.
Syntax Description
w
specifies the width of the output field.
Default: 1
Range:
1–32767
Details
If EBCDIC is the native format, no conversion occurs.
Comparisons
3 On ASCII systems, $EBCDICw. converts ASCII character data to EBCDIC.
3 On all other systems, $EBCDICw. behaves like the $CHARw. format.
Examples
put name $ebcdic3.;
Formats
Value of name
Results*
qrs
9899A2
QRS
D8D9E2
+;>
4E5E6E
4
$HEXw. Format
113
* The results are shown as hexadecimal representations of EBCDIC codes for characters. Each
two hexadecimal characters correspond to one byte of binary data, and each byte corresponds
to one character.
$HEXw. Format
Converts character data to hexadecimal representation.
Category: Character
left
See: $HEXw. Format in the documentation for your operating environment.
Alignment:
Syntax
$HEXw.
Syntax Description
w
specifies the width of the output field.
Default: The default width is calculated based on the length of the variable to be
printed.
Range: 1–32767
Tip: To ensure that SAS writes the full hexadecimal equivalent of your data, make
w twice the length of the variable or field that you want to represent.
Tip: If w is greater than twice the length of the variable that you want to represent,
$HEXw. pads it with blanks.
Details
The $HEXw. format converts each character into two hexadecimal characters. Each
blank counts as one character, including trailing blanks.
Comparisons
The HEXw. format converts real binary numbers to their hexadecimal equivalent.
Examples
put @5 name $hex4.;
114
$MSGCASEw. Format
4
Chapter 3
Value of name
AB
Results
EBCDIC
ASCII
----+----1
----+----1
C1C2
4142
$MSGCASEw. Format
Writes character data in uppercase when the MSGCASE system option is in effect.
Character
Alignment: left
Category:
Syntax
$MSGCASEw.
Syntax Description
w
specifies the width of the output field.
Default: 1 if the length of the variable is undefined. Otherwise, the default is the
length of the variable
Range: 1–32767
Details
When the MSGCASE= system option is in effect, all notes, warnings, and error
messages that SAS generates appear in uppercase. Otherwise, all notes, warnings, and
error messages appear in mixed case. You specify the MSGCASE= system option in the
configuration file or during the SAS invocation.
Operating Environment Information: For more information about the MSGCASE=
system option, see the SAS documentation for your operating environment. 4
Examples
put name $msgcase.;
Value of name
Results
sas
SAS
Formats
4
$N8601Bw.d Format
115
$N8601Bw.d Format
Writes ISO 8601 duration, datetime, and interval forms using the basic notations
PnYnMnDTnHnMnS and yyyymmddThhmmss.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.4.4 Complete representation
Syntax
$N8601Bw.d
Syntax Description
w
specifies the width of the output field.
Default: 50
Range: 1 - 200
The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
Requirement:
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range: 0 - 3
Details
The $N8601B format writes ISO 8601 duration, datetime, and interval values as
character data for the following basic notations:
PnYnMnDTnHnMnS
yyyymmddThhmmss
PnYnMnDTnHnMnS/yyyymmddThhmmss
yyyymmddThhmmssT/PnYnMnDTnHnMnS
The lowest order component can contain fractions, as in these examples:
p2y3.5m
p00020304T05.335
Examples
put nb $n8601b.;
116
$N8601BAw.d Format
4
Chapter 3
Value of nb
Results
0002405050112FFC
P2Y4M5DT5H1M12S
2008915155300FFD
20080915T155300
2008915000000FFD2010915000000FFD
20080915T000000/20100915T000000
0033104030255FFC2008915155300FFD
P33Y1M4DT3H2M55S/20080915T155300
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$N8601BAw.d Format
Writes ISO 8601 duration, datetime, and interval forms using the basic notations
PyyyymmddThhmmss and yyyymmddThhmmss.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.5.4.2 Alternative format
Syntax
$N8601BAw.d
Syntax Description
w
specifies the width of the output field.
Default: 50
Range:
1 - 200
The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
Requirement:
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range:
0-3
Formats
4
$N8601Ew.d Format
117
Details
The $N8601BA format writes ISO 8601 duration, datetime, and interval values as
character data for the following basic notations:
PyyyymmddThhmmss
yyyymmddThhmmss
PyyyymmddThhmmss/yyyymmddThhmmss
yyyymmddThhmmss/PyyyymmddThhmmss
The lowest order component can contain fractions, as in these examples:
p00023.5
00020304T05.335
Examples
put @1 nba $N8601ba.;
Value of nba
Results
00024050501127D0
P00020405T050112.5
2008915155300FFD
20080915T155300
00023040506075282008915155300FFD
P00020304T050607.33/20080915T155300
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$N8601Ew.d Format
Writes ISO 8601 duration, datetime, and interval forms using the extended notations
PnYnMnDTnHnMnS and yyyy-mm-ddThh:mm:ss.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.4.4 Complete representation
Syntax
$N8601Ew.d
118
$N8601Ew.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 50
Range:
1 - 200
The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
Requirement:
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range:
0-3
Details
The $N8601B format writes ISO 8601 duration, datetime, and interval values as
character data for the following basic notations:
PnYnMnDTnHnMnS
yyyy-mm-ddThh:mm:ss
PnYnMnDTnHnMnS/yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ssT/PnYnMnDTnHnMnS
The lowest order component can contain fractions, as in these examples:
p2y3.5m
p0002--03--04T05.335
Examples
put @1 ne $n8601e.;
Value of ne
Results
00024050501127D0
P2Y4M5DT5H1M12.5S
2008915155300FFD
2008-09-15T15:53:00
2008915000000FFD2010915000000FFD
2008-09-15T00:00:00/2010-09-15T00:00:00
0033104030255FFC2008915155300FFD
P33Y1M4DT3H2M55S/2008-09-15T15:53:00
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
Formats
4
$N8601EAw.d Format
119
$N8601EAw.d Format
Writes ISO 8601 duration, datetime, and interval forms using the extended notations
Pyyyy-mm-ddThh:mm:ss and yyyy-mm-ddThh:mm:ss.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.4.4 Complete representation
Syntax
$N8601EAw.d
Syntax Description
w
specifies the width of the output field.
Default: 50
Range: 1 - 200
The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
Requirement:
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range: 0 - 3
Details
The $N8601EA format writes ISO 8601 duration, datetime, and interval values as
character data for the following basic notations:
Pyyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss
Pyyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss/Pyyyy-mm-ddThh:mm:ss
The lowest order component can contain fractions, as in these examples:
p00023.5
0002--03--04T05.335
Examples
put @1 nea $N8601ea.;
120
$N8601EHw.d Format
4
Chapter 3
Value of nea
Results
00024050501127D0
P0002-04-05T05:01:12.500
2008915155300FFD
2008-09-15T15:53:00
00023040506075282008915155300FFD
P0002-03-04T05:06:07.330/2008-09-15T15:53:00
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$N8601EHw.d Format
Writes ISO 8601 duration, datetime, and interval forms using the extended notations
Pyyyy-mm-ddThh:mm:ss and yyyy-mm-ddThh:mm:ss, using a hyphen ( - )for omitted components.
Category:
Date and Time
ISO 8601
Time Zone Format:
No
ISO 8601 Element: 5.4.4 Complete representation
Syntax
$N8601EHw.d
Syntax Description
w
specifies the width of the output field.
Default: 50
Range:
1 - 200
The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
Requirement:
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range:
0-3
Formats
4
$N8601EXw.d Format
121
Details
The $N8601H format writes ISO 8601 duration, datetime, and interval values as
character data, using a hyphen ( - )to represent omitted components, for the following
extended notations:
Pyyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss
Pyyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss/Pyyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
Omitted datetime components are always displayed, they are never truncated.
Examples
put a $n8601eh.;
Value of a
Results
00023FFFFFFFFFFC2008FFF15FFFFFFD
P0002-03---T-:-:-/2008------T15:-:-
2008FFF15FFFFFFdFFFF3FF1553FFFFC
2008------T15:-:-/P---03---T15:53:-
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$N8601EXw.d Format
Writes ISO 8601 duration, datetime, and interval forms using the extended notations
Pyyyy-mm-ddThh:mm:ss and yyyy-mm-ddThh:mm:ss, using an x for digit of an omitted component.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.5.3, 5.5.4.1, 5.5.4.2
Syntax
$N8601Xw.d
122
$N8601Hw.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 50
Range: 1 - 200
Requirement: The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range: 0 - 3
Details
The $N8601H format writes ISO 8601 duration, datetime, and interval values as
character data, using a hyphen ( - ) to represent omitted components, for the following
extended notations:
Pyyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss
Pyyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss/Pyyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
Omitted datetime components are always displayed, they are never truncated.
Examples
put nex $n8601ex.;
Value of nex
Results
00023FFFFFFFFFFC2008FFF15FFFFFFD
P0002-03xxTxx:xx:xx/2008--xx-xxT15:xx:xx
2008FFF15FFFFFFdFFFF3FF1553FFFFC
2008-xx-xxT15:xx:xx/Pxxxx-03-xxT15:53:xx
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$N8601Hw.d Format
Writes ISO 8601 duration, datetime, and interval forms PnYnMnDTnHnMnS and
yyyy-mm-ddThh:mm:ss, dropping omitted components in duration values and using a hyphen ( )for omitted components in datetime values.
Formats
Category:
4
$N8601Hw.d Format
123
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.5.3, 5.5.4.1, 5.5.4.2
Syntax
$N8601Hw.d
Syntax Description
w
specifies the width of the output field.
Default: 50
Range: 1 - 200
The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
Requirement:
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range: 0 - 3
Details
The $N8601H format writes ISO 8601 durations, intervals, and datetimes in the
following forms, omitting components in the PnYnMnDTnHnMnS form and using a
hyphen ( - )to represent omitted components in the datetime form:
PnYnMnDTnHnMnS
yyyy-mm-ddThh:mm:ss
PnYnMnDTnHnMnS/yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ssT/PnYnMnDTnHnMnS
yyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
Omitted datetime components are always displayed, they are never truncated.
Examples
put nh $n8601h.;
Value of nh
Results
0002304FFFFFFFFC2008FFF15FFFFFFD
P2Y3M4D/2008------T15:-:-
FFFF102FFFFFFFFD2008FFF15FFFFFFD
---01-02T-:-:-0/2008------T15:-:-
124
$N8601Xw.d Format
4
Chapter 3
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$N8601Xw.d Format
Writes ISO 8601 duration, datetime, and interval forms PnYnMnDTnHnMnS and
yyyy-mm-ddThh:mm:ss, dropping omitted components in duration values and using an x for each
digit of an omitted component in datetime values.
Date and Time
ISO 8601
Alignment: left
Time Zone Format: No
ISO 8601 Element: 5.5.3, 5.5.4.1, 5.5.4.2
Category:
Syntax
$N8601Xw.d
Syntax Description
w
specifies the width of the output field.
Default: 50
Range: 1 - 200
Requirement: The minimum length for a duration value or a datetime value is 16.
The minimum length for an interval value is 16.
d
specifies the number of digits to the right of the lowest order component. This
argument is optional.
Default: 0
Range: 0 - 3
Details
The $N8601X format writes ISO 8601 durations, intervals, and datetimes in the
following forms, omitting components in the PnYnMnDTnHnMnS form and using an x
to represent omitted components in the datetime form:
PnYnMnDTnHnMnS
yyyy-mm-ddThh:mm:ss
PnYnMnDTnHnMnS/yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ssT/PnYnMnDTnHnMnS
yyyy-mm-ddThh:mm:ss/yyyy-mm-ddThh:mm:ss
Formats
4
$OCTALw. Format
125
Omitted datetime components are always displayed, they are never truncated.
Examples
put nx $n8601x.;
Value of nx
Results
0002304FFFFFFFFC2008FFF15FFFFFFD
P2Y3M4D/2008-xx-xxT15:xx:xx
FFFF102FFFFFFFFD2008FFF15FFFFFFd
xxxx-01-02Txx:xx:xx/2008-xx-xxT15:xx:xx
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
$OCTALw. Format
Converts character data to octal representation.
Category: Character
Alignment:
left
Syntax
$OCTALw.
Syntax Description
w
specifies the width of the output field.
Default: The default width is calculated based on the length of the variable to be
printed.
Range: 1–32767
Tip: Because each character value generates three octal characters, increase the
value of w by three times the length of the character value.
Comparisons
The $OCTALw. format converts character values to the octal representation of their
character codes. The OCTALw. format converts numeric values to octal representation.
Example
The following example shows ASCII output when you use the $OCTALw. format.
126
$QUOTEw. Format
4
Chapter 3
data _null_;
infile datalines truncover;
input item $5.;
put item $octal15.;
datalines;
art
rice
bank
;
run;
SAS writes the following results to the log.
141162164040040
162151143145040
142141156153040
$QUOTEw. Format
Writes data values that are enclosed in double quotation marks.
Character
Alignment: left
Category:
Syntax
$QUOTEw.
Syntax Description
w
specifies the width of the output field.
Default: 2 if the length of the variable is undefined. Otherwise, the default is the
length of the variable + 2
Range: 2–32767
Tip: Make w wide enough to include the left and right quotation marks.
Details
The following list describes the output that SAS produces when you use the $QUOTEw.
format. For examples of these items, see “Examples” on page 127.
3 If your data value is not enclosed in quotation marks, SAS encloses the output in
double quotation marks.
3 If your data value is not enclosed in quotation marks, but the value contains a
single quotation mark, SAS
3 encloses the data value in double quotation marks
Formats
4
$REVERJw. Format
127
3 does not change the single quotation mark.
3 If your data value begins and ends with single quotation marks, and the value
contains double quotation marks, SAS
3 encloses the data value in double quotation marks
3 duplicates the double quotation marks that are found in the data value
3 does not change the single quotation marks.
3 If your data value begins and ends with single quotation marks, and the value
contains two single contiguous quotation marks, SAS
3 encloses the value in double quotation marks
3 does not change the single quotation marks.
3 If your data value begins and ends with single quotation marks, and contains both
double quotation marks and single, contiguous quotation marks, SAS
3 encloses the value in double quotation marks
3 duplicates the double quotation marks that are found in the data value
3 does not change the single quotation marks.
3 If the length of the target field is not large enough to contain the string and its
quotation marks, SAS returns all blanks.
Examples
put name $quote20.;
Value of name
Results
----+----1
SAS
"SAS"
SAS’s
"SAS’s"
’ad"verb"’
"’ad""verb""’"
’ad’’verb’
"’ad’’verb’"
’"ad"’’"verb"’
"’""ad""’’""verb""’"
deoxyribonucleotide
$REVERJw. Format
Writes character data in reverse order and preserves blanks.
Category: Character
Alignment:
right
Syntax
$REVERJw.
128
$REVERSw. Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 1 if w is not specified
Range: 1–32767
Comparisons
The $REVERJw. format is similar to the $REVERSw. format except that $REVERSw.
left aligns the result by trimming all leading blanks.
Examples
put @1 name $reverj7.;
Name
Results
----+----1
ABCD###
DCBA
###ABCD
DCBA
* The character # represents a blank space.
$REVERSw. Format
Writes character data in reverse order and left aligns
Category:
Alignment:
Character
left
Syntax
$REVERSw.
Syntax Description
w
specifies the width of the output field.
Default: 1 if w is not specified
Range: 1–32767
Comparisons
The $REVERSw. format is similar to the $REVERJw. format except that $REVERJw.
does not left align the result.
Formats
4
$UPCASEw. Format
Examples
put @1 name $revers7.;
Name
Results
----+----1
ABCD###
DCBA
###ABCD
DCBA
* The character # represents a blank space.
$UPCASEw. Format
Converts character data to uppercase.
Category: Character
Alignment:
left
Syntax
$UPCASEw.
Syntax Description
w
specifies the width of the output field.
Default: 8 if the length of the variable is undefined. Otherwise, the default is the
length of the variable
Range: 1–32767
Details
Special characters, such as hyphens and other symbols, are not altered.
Examples
put @1 name $upcase9.;
Value of name
Results
----+----1
coxe-ryan
COXE-RYAN
129
130
$VARYINGw. Format
4
Chapter 3
$VARYINGw. Format
Writes character data of varying length.
in DATA step
Character
Alignment: left
Valid:
Category:
Syntax
$VARYINGw. length-variable
Syntax Description
w
specifies the maximum width of the output field for any output line or output file
record.
Default: 8 if the length of the variable is undefined. Otherwise, the default is the
length of the variable
Range: 1–32767
length-variable
specifies a numeric variable that contains the length of the current value of the
character variable. SAS obtains the value of the length-variable by reading it directly
from a field that is described in an INPUT statement, reading the value of a variable
in an existing SAS data set, or calculating its value.
Requirement: You must specify length-variable immediately after $VARYINGw. in
a SAS statement.
Restriction: Length-variable cannot be an array reference.
Tip: If the value of length-variable is 0, negative, or missing, SAS writes nothing to
the output field. If the value of length-variable is greater than 0 but less than w,
SAS writes the number of characters that are specified by length-variable. If
length-variable is greater than or equal to w, SAS writes w columns.
Details
Use $VARYINGw. when the length of a character value differs from record to record.
After writing a data value with $VARYINGw., the pointer’s position is the first column
after the value.
Examples
Example 1: Obtaining a Variable Length Directly
An existing data set variable
contains the length of a variable. The data values and the results follow the
explanation of this SAS statement:
put @10 name $varying12. varlen;
NAME is a character variable of length 12 that contains values that vary from 1 to 12
characters in length. VARLEN is a numeric variable in the same data set that contains
the actual length of NAME for the current observation.
Formats
Value of name*
4
$w. Format
131
Results
----+----1----+----2----+
New York 8
New York
Toronto 7
Toronto
Buenos Aires 12
Buenos Aires
Tokyo 5
Tokyo
* The value of NAME appears before the value of VARLEN.
Example 2: Obtaining a Variable Length Indirectly
Use the LENGTH function to
determine the length of a variable. The data values and the results follow the
explanation of these SAS statements:
varlen=length(name);
put @10 name $varying12. varlen;
The assignment statement determines the length of the varying-length variable. The
variable VARLEN contains this length and becomes the length-variable argument to the
$VARYING12. format.
Values*
Results
----+----1----+----2----+
New York
New York
Toronto
Toronto
Buenos Aires
Buenos Aires
Tokyo
Tokyo
* The value of NAME appears before the value of VARLEN.
$w. Format
Writes standard character data.
Category: Character
Alignment:
Alias:
$Fw.
Syntax
$w.
left
132
4
BESTw. Format
Chapter 3
Syntax Description
w
specifies the width of the output field. You can specify a number or a column range.
Default: 1 if the length of the variable is undefined. Otherwise, the default is the
length of the variable.
Range: 1–32767
Comparisons
The $w. format and the $CHARw. format are identical, and they do not trim leading
blanks. To trim leading blanks, use the LEFT function to left align character data, or
use list output with the colon (:) format modifier and the format of your choice.
Examples
put @10 name $5.;
put name $ 10-15;
Value of name*
Results
----+----1----+----2
#Cary
Cary
Tokyo
Tokyo
* The character # represents a blank space.
BESTw. Format
SAS chooses the best notation.
Numeric
Alignment: right
Category:
See:
BESTw. Format in the documentation for your operating environment.
Syntax
BESTw.
Formats
4
BESTw. Format
133
Syntax Description
w
specifies the width of the output field.
Default: 12
Tip: If you print numbers between 0 and .01 exclusively, then use a field width of at
least 7 to avoid excessive rounding. If you print numbers between 0 and -.01
exclusively, then use a field width of at least 8.
Range: 1–32
Details
When a format is not specified for writing a numeric value, SAS uses the BESTw.
format as the default format. The BESTw. format writes numbers as follows:
3 Values are written with the maximum precision, as determined by the width.
3 Integers are written without decimals.
3 Numbers with decimals are written with as many digits to the left and right of the
decimal point as needed or as allowed by the width.
3 Values that can be written within the given width are written without trailing
zeros.
3 Values that cannot be written within the given width are written with the
maximum allowable number of decimal places as determined by the width.
3 Extreme values might be written in scientific notation.
SAS stores the complete value regardless of the format that is used.
Comparisons
3 The BESTw. format writes as many significant digits as possible in the output
field, but if the numbers vary in magnitude, the decimal points do not line up.
Integers print without a decimal.
3 The Dw.p format writes numbers with the desired precision and more alignment
than the BESTw format.
3 The BESTDw.p format is a combination of the BESTw. format and the Dw.p
format in that it formats all numeric data, and it does a better job of aligning
decimals than the BESTw. format.
3 The w.d format aligns decimal points, if possible, but does not necessarily show
the same precision for all numbers.
Examples
The following statements produce these results.
SAS Statements
Results
----+----1----+----2
x=1257000;
put x best6.;
1.26E6
x=1257000;
put x best3.;
1E6
134
BESTDw.p Format
4
Chapter 3
See Also
Format:
“BESTDw.p Format” on page 134
BESTDw.p Format
Prints numeric values, lining up decimal places for values of similar magnitude, and prints
integers without decimals.
Category:
Alignment:
Numeric
right
Syntax
BESTDw.p
Syntax Description
w
specifies the width of the output field.
Default: 12
Range: 1–32
p
specifies the precision. This argument is optional.
Default: 3
Range: 0 to w–1
Requirement: must be less than w
Tip: If p is omitted or is specified as 0, then p is set to 3.
Details
The BESTDw.p format writes numbers so that the decimal point aligns in groups of
values with similar magnitude. Integers are printed without a decimal point. Larger
values of p print the data values with more precision and potentially more shifts in the
decimal point alignment. Smaller values of p print the data values with less precision
and a greater chance of decimal point alignment.
The format chooses the number of decimal places to print for ranges of values, even
when the underlying values can be represented with fewer decimal places.
Comparisons
3 The BESTw. format writes as many significant digits as possible in the output
field, but if the numbers vary in magnitude, the decimal points do not line up.
Integers print without a decimal.
3 The Dw.p format writes numbers with the desired precision and more alignment
than the BESTw format.
Formats
4
BINARYw. Format
135
3 The BESTDw.p format is a combination of the BESTw. format and the Dw.p
format in that it formats all numeric data, and it does a better job of aligning
decimals than the BESTw. format.
3 The w.d format aligns decimal points, if possible, but it does not necessarily show
the same precision for all numbers.
Examples
put x bestd14.;
Data Line
Results
—-+—-1—-+
12345
12345
123.45
123.4500000
1.2345
1.2345000
.12345
0.1234500
1.23456789
See Also
Formats:
“BESTw. Format” on page 132
“Dw.p Format” on page 147
BINARYw. Format
Converts numeric values to binary representation.
Category: Numeric
Alignment:
left
Syntax
BINARYw.
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 1–64
1.23456789
136
B8601DAw. Format
4
Chapter 3
Comparisons
BINARYw. converts numeric values to binary representation. The $BINARYw. format
converts character values to binary representation.
Examples
put @1 x binary8.;
Value of x
Results
----+----1
123.45
01111011
123
01111011
-123
10000101
B8601DAw. Format
Writes date values using the IOS 8601 base notation yyyymmdd.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.2.1.1 Complete representation
Syntax
B8601DAw.
Syntax Description
w
specifies the width of the output field.
Default: 10
Requirement:
The width of the output field must be 10.
Details
The B8601DA format writes the ISO 8601 basic date notation yyyymmdd:
yyyy
is a four-digit year, such as 2008
mm
is a two-digit month (zero padded) between 01 and 12
dd
is a two-digit day of the month (zero padded) between 01 and 31
Formats
4
B8601DNw. Format
137
Examples
put bda $b8601da.;
Value of bda
Results
17790
20080915
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
B8601DNw. Format
Writes the date from a datetime value using the ISO 8601 basic notation yyyymmdd.
Category: Date and Time
ISO 8601
Alignment: left
Time Zone Format: No
ISO 8601 Element: 5.2.1.1 Complete representation
Syntax
B8601DNw.
Syntax Description
w
specifies the width of the output field.
Default: 10
Requirement: The width of the input field must be 10.
Details
The B8601DN format writes the date from a datetime value using the ISO 8601 basic
date notation yyyymmdd:
yyyy
is a four-digit year, such as 2008
mm
is a two-digit month (zero padded) between 01 and 12
dd
is a two-digit day of the month (zero padded) between 01 and 31
138
B8601DTw.d Format
4
Chapter 3
Examples
put bdn b8601dn.;
Value of bdn
Results
1537113180
20080915
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
B8601DTw.d Format
Writes datetime values in the ISO 8601 basic notation yyyymmddThhmmssffffff.
Date and Time
ISO 8601
Alignment: left
Time Zone Format: No
ISO 8601 Element: 5.4.1 Complete representation
Category:
Syntax
B8601DTw.d
Syntax Description
w
specifies the width of the output field.
Default: 19
Range: 19 - 26
d
specifies the number of digits to the right of the seconds value that represents a
fraction of a second. This argument is optional.
Default: 0
Range: 0 - 6
Details
The B8601DT format writes ISO 8601 basic datetime notation yyyymmddThhmmssffffff:
yyyy
is a four-digit year, such as 2008
Formats
4
B8601DZw. Format
mm
is a two-digit month (zero padded) between 01 and 12
dd
is a two-digit day of the month (zero padded) between 01 and 31
hh
is a two-digit hour (zero padded), between 00 - 23
mm
is a two-digit minute (zero padded), between 00 - 59
ss
is a two-digit second (zero padded), between 00 - 59
.ffffff
are optional fractional seconds, with a precision of up to six digits,
where each digit is between 0 - .
139
Examples
put bdt b8601dt.;
Value of bdt
Results
——+——1
1537113180
20080915T155300
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
B8601DZw. Format
Writes datetime values in the Coordinated Universal Time (UTC) time scale using ISO 8601
datetime and time zone basic notation yyyymmddThhmmss+|-hhmm.
Category: Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
Yes
ISO 8601 Element: 5.4.1 Complete representation
Syntax
B8601DZw.
Syntax Description
w
specifies the width of the output field.
140
B8601DZw. Format
4
Chapter 3
Default: 26
Range:
20 - 35
Details
UTC values specify a time and a time zone based on the zero meridian in Greenwich,
England. The B8602DZ format writes SAS datetime values for the zero meridian date
and time using one of the following ISO 8601 basic datetime notations:
yyyymmddThhmmss+|–hhmm
is the form used whenw is large enough to support this time zone notation.
yyyymmddThhmmssZ
is the form used when w is not large enough to support the +|-hhmm time zone
notation.
where
yyyy
is a four-digit year, such as 2008
mm
is a two-digit month (zero padded) between 01 and 12
dd
is a two-digit day of the month (zero padded) between 01 and 31
hh
is a two-digit hour (zero padded), between 00 - 23
mm
is a two-digit minute (zero padded), between 00 - 59
ss
is a two-digit second (zero padded), between 00 - 59
Z
indicates that the time is for zero meridian (Greenwich, England) or
UTC time
+|-hhmm
is an hour and minute signed offset from zero meridian time. Note
that the offset must be +|-hhmm (that is, + or - and four characters).
Use + for time zones east of the zero meridian and use - for time
zones west of the zero meridian. For example, +0200 indicates a
two-hour time difference to the east of the zero meridian, and -0600
indicates a six-hour time differences to the west of the zero meridian.
Restriction: The shorter form +|-hh is not supported.
Examples
SAS Statement
Value of bdz
Results
put bdz b8601dz20.;
1537113180
20080915T155300Z
put bdz b8601dz26.;
1537113180
20080915T155300+0000
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
Formats
4
B8601LZw. Format
141
B8601LZw. Format
Writes time values as local time by appending a time zone offset difference between the local
time and UTC, using the ISO 8601 basic time notation hhmmss+|-hhmm.
Category: Date and Time
ISO 8601
Alignment: left
Yes. The format appends the UTC offset to the value as determined by
the local SAS session.
Time Zone Format:
ISO 8601 Element: 5.3.3, 5.3.4.2
Syntax
B8601LZw.
Syntax Description
w
specifies the width of the output field.
Default: 14
Range: 9 - 20
Details
The B8602LZ format writes time values without making any adjustments and appends
the UTC time zone offset for the local SAS session, using the following ISO 8601 basic
notation:
hhmmss+|–hhmm
where
hh
is a two-digit hour (zero padded), between 00 - 23
mm
is a two-digit minute (zero padded), between 00 - 59
ss
is a two-digit second (zero padded), between 00 - 59
+|-hhmm
is an hour and minute signed offset from zero meridian time. Note
that the offset must be +|-hhmm (that is, + or - and five characters).
Use + for time zones east of the zero meridian and use - for time
zones west of the zero meridian. For example, +0200 indicates a two
hour time difference to the east of the zero meridian, and -0600
indicates a six hour time differences to the west of the zero meridian.
Restriction: The shorter form +|-hh is not supported.
When SAS reads a UTC time by using the B8601TZ informat, and the adjusted time
is greater than 24 hours or less than 00 hours, SAS adjusts the value so that the time
is between 000000 and 235959. If the B8601LZ format attempts to format a time
outside of this time range, the time is formatted with stars to indicate that the value is
out of range.
142
B8601TMw.d Format
4
Chapter 3
Examples
The following PUT statement writes the time for the Eastern Standard time zone:
put blz b8601lz.;
Value of blz
Results
46380
125300-0500
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
B8601TMw.d Format
Writes time values using the ISO 8601 basic notation hhmmssffff.
Category:
Date and Time
ISO 8601
Alignment:
left
Time Zone Format:
No
ISO 8601 Element: 5.3.1.1 Complete representation
Syntax
B8601TMw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range:
8 - 15
d
specifies the number of digits to the right of the seconds value that represent a
fraction of a second. This argument is optional.
Default: 0
Range:
0-6
Formats
4
B8601TZw. Format
143
Details
The B8601TM format writes SAS time values using the following ISO 8601 basic time
notation hhmmssffffff:
hh
is a two-digit hour (zero padded), between 00 - 23.
mm
is a two-digit minute (zero padded), between 00 - 59.
ss
is a two-digit second (zero padded), between 00 - 59.
ffffff
are optional fractional seconds, with a precision of up to six digits,
where each digit is between 0 - 9.
Examples
put btm b8601tm.;.
Value of btm
Results
57180
155300
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
B8601TZw. Format
Adjusts time values to the Coordinated Universal Time (UTC) and writes them using the ISO 8601
basic time notation hhmmss+|-hhmm.
Category: Date and Time
ISO 8601
Alignment: left
Time Zone Format: Yes
ISO 8601 Element: 5.3.3, 5.3.4
Syntax
B8601TZw.
144
B8601TZw. Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 14
Range:
9–20
Details
UTC time values specify a time and a time zone based on the zero meridian in
Greenwich, England. The B8602TZ format adjusts the time value to be the time at the
zero meridian and writes it in one of the following ISO 8601 basic time notations:
hhmmss+|–
hhmm
is the form used when w is large enough to support this time
notation.
hhmmssZ
is the form used when w is not large enough to support the
+|-hhmm time zone notation.
where
hh
is a two-digit hour (zero padded), between 00 and 23.
mm
is a two-digit minute (zero padded), between 00 and 59.
ss
is a two-digit second (zero padded), between 00 and 59.
Z
indicates that the time is for zero meridian (Greenwich, England) or
UTC time.
+|–hh:mm
is an hour and minute signed offset from zero meridian time. Note
that the offset must be +|–hhmm (that is, + or – and four
characters).
Use + for time zones east of the zero meridian and use – for time
zones west of the zero meridian. For example, +0200 indicates a two
hour time difference to the east of the zero meridian, and –0600
indicates a six hour time differences to the west of the zero meridian.
Restriction: The shorter form +|–hh is not supported.
When SAS reads a UTC time by using the B8601TZ informat, and the adjusted time
is greater than 24 hours or less than 00 hours, SAS adjusts the value so that the time
is between 000000 and 240000. If the B8601TZ format attempts to format a time
outside of this time range, the time is formatted with stars to indicate that the value is
out of range.
Comparisons
For time values between 000000 and 240000, the B8601TZ format adjusts the time
value to be the time at the zero meridian and writes it in the international standard
extended time notation. The B8601LZ format makes no adjustment to the time and
writes time values in the international standard extended time notation, using a UTC
time zone offset for the local SAS session.
Examples
put btz b8601tz.;
Formats
Values for btz
Results
73441
202401+0000
4
COMMAw.d Format
145
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
COMMAw.d Format
Writes numeric values with a comma that separates every three digits and a period that separates
the decimal fraction.
Category: Numeric
Alignment:
right
Syntax
COMMAw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 1–32
Tip: Make w wide enough to write the numeric values, the commas, and the
optional decimal point.
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Range: 0–31
Requirement: must be less than w
Details
The COMMAw.d format writes numeric values with a comma that separates every
three digits and a period that separates the decimal fraction.
Comparisons
3 The COMMAw.d format is similar to the COMMAXw.d format, but the
COMMAXw.d format reverses the roles of the decimal point and the comma. This
convention is common in European countries.
146
COMMAXw.d Format
4
Chapter 3
3 The COMMAw.d format is similar to the DOLLARw.d format except that the
COMMAw.d format does not print a leading dollar sign.
Examples
put @10 sales comma10.2;
Value of sales
Results
----+----1----+----2
23451.23
23,451.23
123451.234
123,451.23
See Also
Formats:
“COMMAXw.d Format” on page 146
“DOLLARw.d Format” on page 157
COMMAXw.d Format
Writes numeric values with a period that separates every three digits and a comma that separates
the decimal fraction.
Category:
Numeric
Alignment:
right
Syntax
COMMAXw.d
Syntax Description
w
specifies the width of the output field. This argument is optional.
Default: 6
Range:
1–32
Make w wide enough to write the numeric values, the commas, and the
optional decimal point.
Tip:
d
specifies the number of digits to the right of the decimal point in the numeric value.
Range:
0–31
Requirement:
must be less than w
Formats
4
Dw.p Format
147
Details
The COMMAXw.d format writes numeric values with a period that separates every
three digits and with a comma that separates the decimal fraction.
Comparisons
The COMMAw.d format is similar to the COMMAXw.d format, but the COMMAXw.d
format reverses the roles of the decimal point and the comma. This convention is
common in European countries.
Examples
put @10 sales commax10.2;
Value of sales
Results
----+----1----+----2
23451.23
23.451,23
123451.234
123.451,23
Dw.p Format
Prints numeric values, possibly with a great range of values, lining up decimal places for values
of similar magnitude.
Category: Numeric
Alignment:
right
Syntax
Dw.p
Syntax Description
w
specifies the width of the output field. This argument is optional.
Default: 12
Range: 1–32
p
specifies the precision. This argument is optional.
Default: 3
Range: 0–9
Requirement: p must be less than w
Tip: If p is omitted or is specified as 0, then p is set to 3.
148
DATEw. Format
4
Chapter 3
Tip:
If zero is the desired precision, use the w.d format in place of the Dw.p format.
Details
The Dw.p format writes numbers so that the decimal point aligns in groups of values
with similar magnitude. Larger values of p print the data values with more precision
and potentially more shifts in the decimal point alignment. Smaller values of p print
the data values with less precision and a greater chance of decimal point alignment.
Comparisons
3 The BESTw. format writes as many significant digits as possible in the output
field, but if the numbers vary in magnitude, the decimal points do not line up.
3 Dw.p writes numbers with the desired precision and more alignment than the
BESTw format.
3 The BESTDw.p format is a combination of the BESTw. format and the Dw.p
format in that it formats all numeric data, and it does a better job of aligning
decimals than the BESTw. format.
3 The w.d format aligns decimal points, if possible, but it does not necessarily show
the same precision for all numbers.
Examples
put @1 x d10.4;
Value of x
Results
----+----1----+----2
12345
12345.0
1234.5
1234.5
123.45
123.45000
12.345
12.34500
1.2345
1.23450
.12345
0.12345
See Also
Format:
“BESTDw.p Format” on page 134
DATEw. Format
Writes date values in the form ddmmmyy, ddmmmyyyy, or dd-mmm-yyyy.
Category:
Alignment:
Date and Time
right
Formats
4
DATEw. Format
Syntax
DATEw.
Syntax Description
w
specifies the width of the output field.
Default: 7
Range: 5–11
Use a width of 9 to print a 4-digit year without a separator between the day,
month, and year. Use a width of 11 to print a 4-digit year using a hyphen as a
separator between the day, month, and year
Tip:
Details
The DATEw. format writes SAS date values in the form ddmmmyy, ddmmmyyyy, or
dd-mmm-yyyy, where
dd
is an integer that represents the day of the month.
mmm
is the first three letters of the month name.
yy or yyyy
is a two-digit or four-digit integer that represents the year.
Examples
The example table uses the input value of 17607, which is the SAS date value that
corresponds to March 16, 2008.
SAS Statement
Results
----+----1----+
put day date5.;
16MAR
put day date6.;
16MAR
put day date7.;
16MAR08
put day date8.;
16MAR08
put day date9.;
16MAR2008
put day date11.;
16-MAR-2008
See Also
Function:
“DATE Function” on page 611
149
150
4
DATEAMPMw.d Format
Chapter 3
Informat:
“DATEw. Informat” on page 1263
DATEAMPMw.d Format
Writes datetime values in the form ddmmmyy:hh:mm:ss.ss with AM or PM.
Category:
Date and Time
Alignment:
right
Syntax
DATEAMPMw.d
Syntax Description
w
specifies the width of the output field.
Default: 19
Range:
7–40
SAS requires a minimum w value of 13 to write AM or PM. For widths
between 10 and 12, SAS writes a 24-hour clock time.
Tip:
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Requirement:
Range:
Note:
must be less than w
0–39
If w–d< 17, SAS truncates the decimal values.
4
Details
The DATEAMPMw.d format writes SAS datetime values in the form
ddmmmyy:hh:mm:ss.ss, where
dd
is an integer that represents the day of the month.
mmm
is the first three letters of the month name.
yy
is a two-digit integer that represents the year.
hh
is an integer that represents the hour.
mm
is an integer that represents the minutes.
Formats
4
DATETIMEw.d Format
ss.ss
is the number of seconds to two decimal places.
Comparisons
The DATEAMPMw.d format is similar to the DATETIMEw.d format except that
DATEAMPMw.d prints AM or PM at the end of the time.
Examples
The example table uses the input value of 1347455694, which is the SAS datetime
value that corresponds to 11:01:34 a.m. on April 20, 2003.
SAS Statement
Results
----+----1----+----2----+
put event dateampm.;
20APR03:11:01:34 AM
put event dateampm7.;
20APR03
put event dateampm10.;
20APR:11
put event dateampm13.;
20APR03:11 AM
put event dateampm22.2;
20APR03:11:01:34.00 AM
See Also
Format:
“DATETIMEw.d Format” on page 151
DATETIMEw.d Format
Writes datetime values in the form ddmmmyy:hh:mm:ss.ss.
Category: Date and Time
Alignment:
right
Syntax
DATETIMEw.d
151
152
DATETIMEw.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 16
Range: 7–40
Tip: SAS requires a minimum w value of 16 to write a SAS datetime value with the
date, hour, and seconds. Add an additional two places to w and a value to d to
return values with optional decimal fractions of seconds.
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Requirement: must be less than w
Range: 0–39
Note:
If w–d< 17, SAS truncates the decimal values.
4
Details
The DATETIMEw.d format writes SAS datetime values in the form
ddmmmyy:hh:mm:ss.ss, where
dd
is an integer that represents the day of the month.
mmm
is the first three letters of the month name.
yy
is a two-digit integer that represents the year.
hh
is an integer that represents the hour in 24–hour clock time.
mm
is an integer that represents the minutes.
ss.ss
is the number of seconds to two decimal places.
Examples
The example table uses the input value of 1447213759, which is the SAS datetime
value that corresponds to 3:49:19 a.m. on November 10, 2005.
SAS Statement
Results
----+----1----+----2
put event datetime.;
10NOV05:03:49:19
put event datetime7.;
10NOV05
put event datetime12.;
10NOV05:03
put event datetime18.;
10NOV05:03:49:19
put event datetime18.1;
put event datetime19.;
10NOV05:03:49:19.0
10NOV2005:03:49:19
Formats
SAS Statement
Results
put event datetime20.1;
10NOV2005:03:49:19.0
put event datetime21.2;
10NOV2005:03:49:19.00
4
DAYw. Format
See Also
Formats:
“DATEw. Format” on page 148
“TIMEw.d Format” on page 239
Function:
“DATETIME Function” on page 613
Informats:
“DATEw. Informat” on page 1263
“DATETIMEw. Informat” on page 1264
“TIMEw. Informat” on page 1330
DAYw. Format
Writes date values as the day of the month.
Category: Date and Time
Alignment:
right
Syntax
DAYw.
Syntax Description
w
specifies the width of the output field.
Default: 2
Range: 2–32
Examples
The example table uses the input value of 16601, which is the SAS date value that
corresponds to June 14, 2005.
153
154
DDMMYYw. Format
4
Chapter 3
SAS Statement
Results
----+----1
put date day2.;
14
DDMMYYw. Format
Writes date values in the form ddmm<yy>yy or dd/mm/<yy>yy, where a forward slash is the
separator and the year appears as either 2 or 4 digits.
Category:
Date and Time
Alignment:
right
Syntax
DDMMYYw.
Syntax Description
w
specifies the width of the output field.
Default: 8
Range:
2–10
Interaction: When w has a value of from 2 to 5, the date appears with as much of
the day and the month as possible. When w is 7, the date appears as a two-digit
year without slashes.
Details
The DDMMYYw. format writes SAS date values in the form ddmm<yy>yy or dd/mm/
<yy>yy, where
dd
is an integer that represents the day of the month.
/
is the separator.
mm
is an integer that represents the month.
<yy>yy
is a two-digit or four-digit integer that represents the year.
Formats
4
DDMMYYxw. Format
155
Examples
The following examples use the input value of 16794, which is the SAS date value
that corresponds to December 24, 2005.
SAS Statement
Results
----+----1----+
put date ddmmyy5.;
24/12
put date ddmmyy6.;
241205
put date ddmmyy7.;
241205
put date ddmmyy8.;
24/12/05
put date ddmmyy10.;
24/12/2005
See Also
Formats:
“DATEw. Format” on page 148
“DDMMYYxw. Format” on page 155
“MMDDYYw. Format” on page 190
“YYMMDDw. Format” on page 265
Function:
“MDY Function” on page 885
Informats:
“DATEw. Informat” on page 1263
“DDMMYYw. Informat” on page 1266
“MMDDYYw. Informat” on page 1288
“YYMMDDw. Informat” on page 1345
DDMMYYxw. Format
Writes date values in the form ddmm<yy>yy or dd-mm-yy<yy>, where the x in the format name is
a character that represents the special character that separates the day, month, and year, which
can be a hyphen (-), period (.), blank character, slash (/), colon (:), or no separator; the year can
be either 2 or 4 digits.
Category: Date and Time
Alignment:
right
Syntax
DDMMYYxw.
156
DDMMYYxw. Format
4
Chapter 3
Syntax Description
x
identifies a separator or specifies that no separator appear between the day, the
month, and the year. Valid values for x are:
B
separates with a blank
C
separates with a colon
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a slash.
w
specifies the width of the output field.
Default: 8
Range:
2–10
Interaction: When w has a value of from 2 to 5, the date appears with as much of
the day and the month as possible. When w is 7, the date appears as a two-digit
year without separators.
Interaction: When x has a value of N, the width range changes to 2–8.
Details
The DDMMYYxw. format writes SAS date values in the form ddmm<yy>yy or
ddxmmx<yy>yy, where
dd
is an integer that represents the day of the month.
x
is a specified separator.
mm
is an integer that represents the month.
<yy>yy
is a two-digit or four-digit integer that represents the year.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to May 14, 2009.
Formats
SAS Statement
4
DOLLARw.d Format
157
Results
----+----1----+
put date ddmmyyc5.;
14:05
put date ddmmyyd8.;
14-05-09
put date ddmmyyp10.;
14.05.2009
put date ddmmyyn8.;
14052009
See Also
Formats:
“DATEw. Format” on page 148
“DDMMYYw. Format” on page 154
“MMDDYYxw. Format” on page 192
“YYMMDDxw. Format” on page 266
Functions:
“DAY Function” on page 613
“MDY Function” on page 885
“MONTH Function” on page 897
“YEAR Function” on page 1176
Informat:
“DDMMYYw. Informat” on page 1266
DOLLARw.d Format
Writes numeric values with a leading dollar sign, a comma that separates every three digits, and
a period that separates the decimal fraction.
Category: Numeric
Alignment:
right
Syntax
DOLLARw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 2–32
158
DOLLARXw.d Format
4
Chapter 3
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Range: 0–31
Requirement: must be less than w
Details
The DOLLARw.d format writes numeric values with a leading dollar sign, a comma
that separates every three digits, and a period that separates the decimal fraction.
The hexadecimal representation of the code for the dollar sign character ($) is 5B on
EBCDIC systems and 24 on ASCII systems. The monetary character that these codes
represent might be different in other countries, but DOLLARw.d always produces one
of these codes. If you need another monetary character, define your own format with
the FORMAT procedure. See “The FORMAT Procedure” in Base SAS Procedures Guide
for more details.
Comparisons
3 The DOLLARw.d format is similar to the DOLLARXw.d format, but the
DOLLARXw.d format reverses the roles of the decimal point and the comma. This
convention is common in European countries.
3 The DOLLARw.d format is the same as the COMMAw.d format except that the
COMMAw.d format does not write a leading dollar sign.
Examples
put @3 netpay dollar10.2;
Value of netpay
Results
----+----1----+
1254.71
$1,254.71
See Also
Formats:
“COMMAw.d Format” on page 145
“DOLLARXw.d Format” on page 158
DOLLARXw.d Format
Writes numeric values with a leading dollar sign, a period that separates every three digits, and a
comma that separates the decimal fraction.
Numeric
Alignment: right
Category:
Formats
4
DOLLARXw.d Format
159
Syntax
DOLLARXw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 2–32
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: 0
Range: 0–31
Requirement:
must be less than w
Details
The DOLLARXw.d format writes numeric values with a leading dollar sign, with a
period that separates every three digits, and with a comma that separates the decimal
fraction.
The hexadecimal representation of the code for the dollar sign character ($) is 5B on
EBCDIC systems and 24 on ASCII systems. The monetary character that these codes
represent might be different in other countries, but DOLLARXw.d always produces one
of these codes. If you need another monetary character, define your own format with
the FORMAT procedure. See “The FORMAT Procedure” in Base SAS Procedures Guide
for more details.
Comparisons
3 The DOLLARXw.d format is similar to the DOLLARw.d format, but the
DOLLARXw.d format reverses the roles of the decimal point and the comma. This
convention is common in European countries.
3 The DOLLARXw.d format is the same as the COMMAXw.d format except that the
COMMAw.d format does not write a leading dollar sign.
Examples
put @3 netpay dollarx10.2;
Value of netpay
Results
----+----1----+
1254.71
$1.254,71
160
4
DOWNAMEw. Format
Chapter 3
See Also
Formats:
“COMMAXw.d Format” on page 146
“DOLLARw.d Format” on page 157
DOWNAMEw. Format
Writes date values as the name of the day of the week.
Category:
Date and Time
Alignment:
right
Syntax
DOWNAMEw.
Syntax Description
w
specifies the width of the output field.
Default: 9
Range:
Tip:
1–32
If you omit w, SAS prints the entire name of the day.
Details
If necessary, SAS truncates the name of the day to fit the format width. For example,
the DOWNAME2. prints the first two letters of the day name.
Examples
The example table uses the input value of 13589, which is the SAS date value that
corresponds to March 16, 1997.
SAS Statement
Results
----+----1
put date downame.;
Sunday
Formats
4
DTDATEw. Format
161
See Also
Format:
“WEEKDAYw. Format” on page 250
DTDATEw. Format
Expects a datetime value as input and writes date values in the form ddmmmyy or ddmmmyyyy.
Category: Date and Time
Alignment:
right
Syntax
DTDATEw.
Syntax Description
w
specifies the width of the output field.
Default: 7
Range: 5–9
Tip:
Use a width of 9 to print a 4–digit year.
Details
The DTDATEw. format writes SAS date values in the form ddmmmyy or ddmmmyyyy,
where
dd
is an integer that represents the day of the month.
mmm
are the first three letters of the month name.
yy or yyyy
is a two-digit or four-digit integer that represents the year.
Comparisons
The DTDATEw. format produces the same type of output that the DATEw. format
produces. The difference is that the DTDATEw. format requires a datetime value.
Examples
The example table uses a datetime value of 16APR2000:10:00:00 as input, and prints
both a two-digit and a four-digit year for the DTDATEw. format.
162
DTMONYYw. Format
4
Chapter 3
SAS Statement
Results
----+----+
put trip_date=dtdate.;
16APR00
put trip_date=dtdate9.;
16APR2000
See Also
Formats:
“DATEw. Format” on page 148
DTMONYYw. Format
Writes the date part of a datetime value as the month and year in the form mmmyy or mmmyyyy.
Date and Time
Alignment: right
Category:
Syntax
DTMONYYw.
Syntax Description
w
specifies the width of the output field.
Default: 5
Range:
5–7
Details
The DTMONYYw. format writes SAS datetime values in the form mmmyy or
mmmyyyy, where
mmm
is the first three letters of the month name.
yy or yyyy
is a two–digit or four-digit integer that represents the year.
Comparisons
The DTMONYYw. format and the MONYYw. format are similar in that they both
write date values. The difference is that DTMONYYw. expects a datetime value as
input, and MONYYw. expects a SAS date value.
Formats
4
DTWKDATXw. Format
Examples
The example table uses as input the value 1476598132, which is the SAS datetime
value that corresponds to October 16, 2006, at 06:08:52 a.m.
SAS Statement
Results
----+----1
put date dtmonyy.;
OCT06
put date dtmonyy5.;
OCT06
put date dtmonyy6.;
OCT06
put date dtmonyy7.;
OCT2006
See Also
Formats:
“DATETIMEw.d Format” on page 151
“MONYYw. Format” on page 200
DTWKDATXw. Format
Writes the date part of a datetime value as the day of the week and the date in the form
day-of-week, dd month-name yy (or yyyy).
Category: Date and Time
Alignment:
right
Syntax
DTWKDATXw.
Syntax Description
w
specifies the width of the output field.
Default: 29
Range: 3–37
Details
The DTWKDATXw. format writes SAS date values in the form day-of-week, dd
month-name, yy or yyyy, where
163
164
DTYEARw. Format
4
Chapter 3
day-of-week
is either the first three letters of the day name or the entire day name.
dd
is an integer that represents the day of the month.
month-name
is either the first three letters of the month name or the entire month name.
yy or yyyy
is a two-digit or four-digit integer that represents the year.
Comparisons
The DTWKDATXw. format is similar to the WEEKDATXw. format in that they both
write date values. The difference is that DTWKDATXw. expects a datetime value as
input, and WEEKDATXw. expects a SAS date value.
Examples
The example table uses as input the value 1476598132, which is the SAS datetime
value that corresponds to October 16, 2002, at 06:08:52 a.m.
SAS Statement
Results
----+----1----+----2----+----3
put date dtwkdatx.;
put date dtwkdatx3.;
put date dtwkdatx8.;
put date dtwkdatx25.;
Monday, 16 October 2006
Mon
Mon
Monday, 16 Oct 2006
See Also
Formats:
“DATETIMEw.d Format” on page 151
“WEEKDATXw. Format” on page 249
DTYEARw. Format
Writes the date part of a datetime value as the year in the form yy or yyyy.
Date and Time
Alignment: right
Category:
Syntax
DTYEARw.
Formats
4
DTYYQCw. Format
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 2–4
Comparisons
The DTYEARw. format is similar to the YEARw. format in that they both write date
values. The difference is that DTYEARw. expects a datetime value as input, and
YEARw. expects a SAS date value.
Examples
The example table uses as input the value 1476598132, which is the SAS datetime
value that corresponds to October 16, 2006, at 06:08:52 a.m.
SAS Statement
Results
----+----1
put date dtyear.;
2006
put date dtyear2.;
06
put date dtyear3.;
put date year4.;
06
2006
See Also
Formats:
“DATETIMEw.d Format” on page 151
“YEARw. Format” on page 261
DTYYQCw. Format
Writes the date part of a datetime value as the year and the quarter and separates them with a
colon (:).
Category: Date and Time
Alignment:
right
Syntax
DTYYQCw.
165
166
4
Ew. Format
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 4
4–6
Range:
Details
The DTYYQCw. format writes SAS datetime values in the form yy or yyyy, followed by
a colon (:) and the numeric value for the quarter of the year.
Examples
The example table uses as input the value 1476598132, which is the SAS datetime
value that corresponds to October 16, 2006, at 06:08:52 p.m..
SAS Statement
Results
----+----1
put date dtyyqc.;
06:4
put date dtyyqc4.;
06:4
put date dtyyqc5.;
06:4
put date dtyyqc6.;
2006:4
See Also
Formats:
“DATETIMEw.d Format” on page 151
Ew. Format
Writes numeric values in scientific notation.
Category:
Alignment:
See:
right
Ew. Format in the documentation for your operating environment.
Syntax
Ew.
Numeric
Formats
4
E8601DAw. Format
167
Syntax Description
w
specifies the width of the output field. The output field can display up to 14
significant digits.
Default: 12
Range: 7–32
Details
When formatting values in scientific notation, the E format reserves the first column of
the result for a minus sign and formats up to 14 significant digits.
Examples
put @1 x e10.;
Value of x
Results
----+----1----+
1257
-1257
1.257E+03
-1.257E+03
E8601DAw. Format
Writes date values using the ISO 8601 extended notation yyyy-mm-dd.
Category: Date and Time
ISO 8601
Alignment: left
Alias: IS8601DA
Time Zone Format: No
ISO 8601 Element: 5.2.1.1 Complete representation
Syntax
E8601DAw.
Syntax Description
w
specifies the width of the output field.
Default: 10
168
E8601DNw. Format
4
Chapter 3
The width of the output field must be 10.
Requirement:
Details
The E8601DA format writes a date in the ISO 8601 extended notation yyyy-mm-dd:
yyyy
is a four-digit year, such as 2008.
mm
is a two-digit month (zero padded) between 01 and 12.
dd
is a two-digit day of the month (zero padded) between 01 and 31.
Examples
put eda e8601da.;
Value for eda
Results
17790
2008-09-15
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
E8601DNw. Format
Writes the date from a SAS datetime value using the ISO 8601 extended notation yyyy-mm-dd.
Category:
Date and Time
ISO 8601
Alignment: left
Alias:
IS8601DN
Time Zone Format:
No
ISO 8601 Element: 5.2.1.1 Complete representation
Syntax
E8601DNw.
Syntax Description
w
specifies the width of the input field.
Formats
4
E8601DTw.d Format
169
Default: 10
Requirement:
The width of the input field must be 10.
Details
The E8601DN formats writes the date in the ISO 8601 extended date notation
yyyy-mm-dd:
yyyy
is a four-digit year, such as 2008.
mm
is a two-digit month (zero padded) between 01 and 12.
dd
is a two-digit day of the month (zero padded) between 01 and 31.
Examples
put edn e8601dn.;
Value for edn
Results
1537113180
2008-09-15
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
E8601DTw.d Format
Writes datetime values in the ISO 8601 extended notation yyyy-mm-ddThh:mm:ss.ffffff.
Category: Date and Time
ISO 8601
Alignment: left
Alias: IS8601DT
Time Zone Format: No
ISO 8601 Element: 5.4.1 Complete representation
Syntax
E8601DTw.d
Syntax Description
w
specifies the width of the input field.
170
E8601DZw. Format
4
Chapter 3
Default: 19
Range:
19 - 26
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Default: 0
Range: 0 - 6
Details
The E8602DT format writes datetime values using the ISO 8601 extended datetime
notation yyyy-mm-ddThh:mm:ss.ffffff:
yyyy
is a four-digit year, such as 2008.
mm
is a two-digit month (zero padded) between 01 and 12.
dd
is a two-digit day of the month (zero padded) between 01 and 31.
hh
is a two-digit hour (zero padded), between 00 - 23.
mm
is a two-digit minute (zero padded), between 00 - 59.
ss
is a two-digit second (zero padded), between 00 - 59.
.ffffff
are optional fractional seconds, with a precision of up to six digits,
where each digit is between 0 - 9.
Examples
put edt e8601dt.;
Value of edt
Results
1537113180
2008-09-15T15:53:00
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
E8601DZw. Format
Writes datetime values in the Coordinated Universal Time (UTC) time scale using ISO 8601
datetime and time zone extended notations yyyy-mm-ddThh:mm:ss+|-hh:mm.
Date and Time
ISO 8601
Alignment: left
Alias: IS8601DZ
Category:
Formats
Time Zone Format:
4
E8601DZw. Format
171
Yes
ISO 8601 Element: 5.4.1 Complete representation
Syntax
E8601DZw.
Syntax Description
w
specifies the width of the output field.
Default: 26
Range: 20 - 35
Details
UTC values specify a time and a time zone based on the zero meridian in Greenwich,
England. The E8602DZ format writes SAS datetime values using one of the following
ISO 8601 extended datetime notations:
yyyy-mmis the form used when w is large enough to support this time zone
ddThh:mm:ss+|– notation.
hh:mm
yyyy-mmddThh:mm:ssZ
is the form used when w is not large enough to support the +|hhmm time zone notation.
where
yyyy
is a four-digit year, such as 2008
mm
is a two-digit month (zero padded) between 01 and 12
dd
is a two-digit day of the month (zero padded) between 01 and 31
hh
is a two-digit hour (zero padded), between 00 - 24
mm
is a two-digit minute (zero padded), between 00 - 59
ss
is a two-digit second (zero padded), between 00 - 59
Z
indicates that the time is for zero meridian (Greenwich, England) or
UTC time.
+|-hh:mm
is an hour and minute signed offset from zero meridian time. Note
that the offset must be +|-hh:mm (that is, + or - and five characters).
Use + for time zones east of the zero meridian and use - for time
zones west of the zero meridian. For example, +02:00 indicates a
two hour time difference to the east of the zero meridian, and -06:00
indicates a six hour time differences to the west of the zero meridian.
Restriction: The shorter form +|-hh is not supported.
Examples
put edz e8601dz.;
172
E8601LZw. Format
4
Chapter 3
Value of edz
Results
1537113180
2008-09-15T15:53:00+00:00
1537102380
2008-09-15T12:53:00+00:00
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
E8601LZw. Format
Writes time values as local time, appending the Coordinated Universal Time (UTC) offset for the
local SAS session, using the ISO 8601 extended time notation hh:mm:ss+|-hh:mm.
Date and Time
ISO 8601
Alignment: left
Alias: IS8601LZ
Time Zone Format: Yes. The format appends the UTC offset to the value as determined by
the local SAS session.
ISO 8601 Element: 5.3.1.1 Complete representation
Category:
Syntax
E8601LZw.
Syntax Description
w
specifies the width of the output field.
Default: 14
Range: 9 - 20
Details
The E8602LZ format writes time values without making any adjustments and appends
the UTC time zone offset for the local SAS session, using one of the following ISO 8601
extended time notations:
hh:mm:ss+|–
hh:mm
is the form used when w is large enough to support this time
notation.
hh:mm:ssZ
is the form used when w is not large enough to support the +|hh:mm time zone notation.
Formats
4
E8601LZw. Format
173
where
hh
is a two-digit hour (zero padded), between 00 - 23.
mm
is a two-digit minute (zero padded), between 00 - 59.
ss
is a two-digit second (zero padded), between 00 - 59.
Z
indicate zero meridian (Greenwich, England) or UTC time.
+|-hh:mm
is an hour and minute signed offset from zero meridian time. Note
that the offset must be +|-hh:mm (that is, + or - and five characters).
Use + for time zones east of the zero meridian and use - for time
zones west of the zero meridian. For example, +02:00 indicates a
two hour time difference to the east of the zero meridian, and -06:00
indicates a six hour time differences to the west of the zero meridian.
Restriction: The shorter form +|-hh is not supported.
SAS writes the time value using the form hh:mm.ffffff and appends the time zone
indicator +|-hh:mm based on the time zone offset from the zero meridian for the local
SAS session, or Z. The Z time zone indicator is used for format lengths that are less
than 14.
If the same time is written using both zone indicators, they indicate two different
times based on the UTC. For example, if the local SAS session uses Eastern Standard
Time in the US, and the time value is 45824, SAS would write 12:43:44-04:00 or
12:43:44Z. The time 12:43:44–04:00 is the time 16:43:44+00:00 at the zero meridian.
The Z indicates that the time is the time at the zero meridian, or 12:43:44+00:00.
When SAS reads a UTC time by using the E8601TZ informat, and the adjusted time
is greater than 24 hours or less than 00 hours, SAS adjusts the value so that the time
is between 00:00:00 and 24:00:00. If the E8601TZ format attempts to format a time
outside of this time range, the time is formatted with stars to indicate that the value is
out of range.
Examples
The following PUT statement write the time for the Eastern Standard time zone.
put elz e8601lz.;
Value of elz
Results
46380
12:53:00-5:00
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
174
4
E8601TMw.d Format
Chapter 3
E8601TMw.d Format
Writes time values using the ISO 8601 extended notation hh:mm:ss.ffffff.
Category:
Date and Time
ISO 8601
Alignment:
Alias:
left
IS8601TM
Time Zone Format:
No
ISO 8601 Element: 5.3.1.1 Complete representation and 5.3.1.3 Representation of decimal
fractions
Syntax
E8601TMw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range:
8 - 15
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Default: 0
Range:
0-6
Details
The E8601TM format writes SAS time values using the following ISO 8601 extended
time notation:
hh:mm:ss.ffffff
hh
is a two-digit hour (zero padded), between 00 - 23.
mm
is a two-digit minute (zero padded), between 00 - 59.
ss
is a two-digit second (zero padded), between 00 - 59.
.ffffff
are optional fractional seconds, with a precision of up to six digits,
where each digit is between 0 - 9.
Examples
put etm e8601tm.;
Formats
Value of etm
Results
57180
15:53:00
4
E8601TZw.d Format
175
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
E8601TZw.d Format
Adjusts time values to the Coordinated Universal Time (UTC) and writes them using the ISO 8601
extended notation hh:mm:ss+|-hh:mm.
Category: Date and Time
ISO 8601
left
IS8601TZ
Alignment:
Alias:
Yes
ISO 8601 Element: 5.3.1.1 Complete representation
Time Zone Format:
Syntax
E8601TZw.d
Syntax Description
w
specifies the width of the output field.
Default: 14
Range: 9 - 20
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Default: 0
Range: 0 - 6
176
E8601TZw.d Format
4
Chapter 3
Details
UTC time values specify a time and a time zone based on the zero meridian in
Greenwich, England. The E8602TZ format writes time values in one of the following
ISO 8601 extended time notations:
hh:mm:ss+|–
hh:mm
is the form used when w is large enough to support this time zone
notation.
hh:mm:ssZ
is the form used when w is not large enough to support the +|hh:mm time zone notation.
where
hh
is a two-digit hour (zero padded), between 00 - 23
mm
is a two-digit minute (zero padded), between 00 - 59
ss
is a two-digit second (zero padded), between 00 - 59
Z
indicate zero meridian (Greenwich, England) or UTC time
+|-hh:mm
is an hour and minute signed offset from zero meridian time. Note
that the offset must be +|-hh:mm (that is, + or - and five
characters). The shorter form +|-hh is not supported.
Use + for time zones east of the zero meridian and use - for time
zones west of the zero meridian. For example, +02:00 indicates a
two hour time difference to the east of the zero meridian, and -06:00
indicates a six hour time differences to the west of the zero meridian.
When SAS reads a UTC time by using the B8601TZ informat, and the adjusted time
is greater than 24 hours or less than 00 hours, SAS adjusts the value so that the time
is between 00:00:00 and 24:00:00. If the E8601TZ format attempts to format a time
outside of this time range, the time is formatted with stars to indicate that the value is
out of range.
Comparisons
For time values between 00:00:00 and 24:00:00, the E8601TZ format adjusts the time
value to be the time at the zero meridian and writes it in the international standard
extended time notation. The E8601LZ format makes no adjustment to the time and
writes time values in the international standard extended time notation, using a UTC
time zone offset for the local SAS session.
Examples
put etz e8601tz.;
Value of etz
Results
73441
20:24:01+00:00
62641
17:24:01+00:00
Formats
4
FLOATw.d Format
177
See Also
“Working with Dates and Times Using the ISO 8601 Basic and Extended Notations”
on page 94
FLOATw.d Format
Generates a native single-precision, floating-point value by multiplying a number by 10 raised to
the dth power.
Category: Numeric
Alignment:
left
Syntax
FLOATw.d
Syntax Description
w
specifies the width of the output field.
Requirement:
width must be 4
d
specifies the power of 10 by which to multiply the value. This argument is optional.
Default: 0
Range: 0-31
Details
This format is useful in operating environments where a float value is not the same as
a truncated double. Values that are written by FLOAT4. typically are values that are
meant to be read by some other external program that runs in your operating
environment and that expects these single-precision values.
Note: If the value that is to be formatted is a missing value, or if it is out-of-range
for a native single-precision, floating-point value, a single-precision value of zero is
generated. 4
On IBM mainframe systems, a four-byte floating-point number is the same as a
truncated eight-byte floating-point number. However, in operating environments using
the IEEE floating-point standard, such as IBM PC-based operating environments and
most UNIX operating environments, a four-byte floating-point number is not the same
as a truncated double. Hence, the RB4. format does not produce the same results as
the FLOAT4. format. Floating-point representations other than IEEE might have this
same characteristic.
178
FRACTw. Format
4
Chapter 3
Comparisons
The following table compares the names of float notation in several programming
languages:
Language
Float Notation
SAS
FLOAT4
Fortran
REAL+4
C
float
IBM 370 ASM
E
PL/I
FLOAT BIN(21)
Examples
put x float4.;
Value of x
Results*
1
3F800000
* The result is a hexadecimal representation of a binary number that is stored in IEEE form.
FRACTw. Format
Converts numeric values to fractions.
Category:
Alignment:
Numeric
right
Syntax
FRACTw.
Syntax Description
w
specifies the width of the output field.
Default: 10
Range: 4–32
Details
Dividing the number 1 by 3 produces the value 0.33333333. To write this value as 1/3,
use the FRACTw. format. FRACTw. writes fractions in reduced form, that is, 1/2
instead of 50/100.
Formats
4
HEXw. Format
179
Examples
put x fract8.;
Value of x
Results
----+----1
0.6666666667
0.2784
2/3
174/625
HEXw. Format
Converts real binary (floating-point) values to hexadecimal representation.
Category: Numeric
Alignment:
See:
left
HEXw. Format in the documentation for your operating environment.
Syntax
HEXw.
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 1–16
If w< 16, the HEXw. format converts real binary numbers to fixed-point
integers before writing them as hexadecimal characters. It also writes negative
numbers in two’s complement notation, and right aligns digits. If w is 16, HEXw.
displays floating-point values in their hexadecimal form.
Tip:
Details
In any operating environment, the least significant byte written by HEXw. is the
rightmost byte. Some operating environments store integers with the least significant
digit as the first byte. The HEXw. format produces consistent results in any operating
environment regardless of the order of significance by byte.
Note: Different operating environments store floating-point values in different ways.
However, the HEX16. format writes hexadecimal representations of floating-point
values with consistent results in the same way that your operating environment stores
them. 4
180
HHMMw.d Format
4
Chapter 3
Comparisons
The HEXw. numeric format and the $HEXw. character format both generate the
hexadecimal equivalent of values.
Examples
put @8 x hex8.;
Value of x
Results
----+----1----+----2
35.4
00000023
88
00000058
2.33
00000002
-150
FFFFFF6A
HHMMw.d Format
Writes time values as hours and minutes in the form hh:mm.
Date and Time
Alignment: right
Category:
Syntax
HHMMw.d
Syntax Description
w
specifies the width of the output field.
Default: 5
Range: 2–20
d
specifies the number of digits to the right of the decimal point in the minutes value.
The digits to the right of the decimal point specify a fraction of a minute. This
argument is optional.
Default: 0
Range: 0–19
Requirement: must be less than w
Details
The HHMMw.d format writes SAS time values in the form hh:mm, where
Formats
4
HHMMw.d Format
181
hh
Note: If hh is a single digit, HHMMw.d places a leading blank before the digit.
For example, the HHMMw.d. format writes 9:00 instead of 09:00. 4
is an integer.
mm
is the number of minutes that range from 00 through 59.
SAS rounds hours and minutes that are based on the value of seconds in a SAS time
value.
The HHMM format uses asterisks to format values that are outside the time range
0–24 hours, such as datetime values.
Comparisons
The HHMMw.d format is similar to the TIMEw.d format except that the HHMMw.d
format does not print seconds.
The HHMMw.d format writes a leading blank for a single-hour digit. The TODw.d
format writes a leading zero for a single-hour digit.
Examples
The example table uses the input value of 46796, which is the SAS time value that
corresponds to 12:59:56 p. m.
SAS Statement
Results
----+----1
put time hhmm.;
13:00
put time hhmm8.2;
12:59.93
In the first example, SAS rounds up the time value four seconds based on the value of
seconds in the SAS time value. In the second example, by adding a decimal
specification of 2 to the format shows that fifty-six seconds is 93% of a minute.
See Also
Formats:
“HOURw.d Format” on page 182
“MMSSw.d Format” on page 194
“TIMEw.d Format” on page 239
“TODw.d Format” on page 242
Functions:
“HMS Function” on page 771
“HOUR Function” on page 774
“MINUTE Function” on page 889
“SECOND Function” on page 1071
“TIME Function” on page 1108
182
HOURw.d Format
4
Chapter 3
Informat:
“TIMEw. Informat” on page 1330
HOURw.d Format
Writes time values as hours and decimal fractions of hours.
Category:
Date and Time
Alignment:
right
Syntax
HOURw.d
Syntax Description
w
specifies the width of the output field.
Default: 2
Range:
2–20
d
specifies the number of digits to the right of the decimal point in the hour value.
Therefore, SAS prints decimal fractions of the hour. This argument is optional.
Requirement:
Range:
must be less than w
0-19
Details
SAS rounds hours based on the value of minutes in the SAS time value.
The HOUR format uses asterisks to format values that are outside the time range
0–24 hours, such as datetime values.
Examples
The example table uses the input value of 41400, which is the SAS time value that
corresponds to 11:30 a.m.
SAS Statement
Results
----+----1
put time hour4.1;
11.5
Formats
4
IBw.d Format
183
See Also
Formats:
“HHMMw.d Format” on page 180
“MMSSw.d Format” on page 194
“TIMEw.d Format” on page 239
“TODw.d Format” on page 242
Functions:
“HMS Function” on page 771
“HOUR Function” on page 774
“MINUTE Function” on page 889
“SECOND Function” on page 1071
“TIME Function” on page 1108
Informat:
“TIMEw. Informat” on page 1330
IBw.d Format
Writes native integer binary (fixed-point) values, including negative values.
Category: Numeric
Alignment:
See:
left
IBw.d Format in the documentation for your operating environment.
Syntax
IBw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default 0
Range: 0–10
Details
The IBw.d format writes integer binary (fixed-point) values, including negative values
that are represented in two’s complement notation. IBw.d writes integer binary values
184
4
IBRw.d Format
Chapter 3
with consistent results if the values are created in the same type of operating
environment that you use to run SAS.
Note: Different operating environments store integer binary values in different
ways. This concept is called byte ordering. For a detailed discussion about byte
ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms” on page 88. 4
Comparisons
The IBw.d and PIBw.d formats are used to write native format integers. (Native format
allows you to read and write values created in the same operating environment.) The
IBRw.d and PIBRw.d formats are used to write little endian integers in any operating
environment.
To view a table that shows the type of format to use with big endian and little endian
integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,ib4.);
put y $hex8.;
Value of x
128
Results on Big Endian Platforms*
Results on Little Endian Platforms*
----+----1
----+----1
00000080
80000000
* The result is a hexadecimal representation of a four-byte integer binary number. Each byte
occupies one column of the output field.
See Also
Format:
“IBRw.d Format” on page 184
IBRw.d Format
Writes integer binary (fixed-point) values in Intel and DEC formats.
Category:
Alignment:
Syntax
IBRw.d
Numeric
left
Formats
4
IBRw.d Format
185
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Details
The IBRw.d format writes integer binary (fixed-point) values, including negative values
that are represented in two’s complement notation. IBRw.d writes integer binary
values that are generated by and for Intel and DEC operating environments. Use
IBRw.d to write integer binary data from Intel or DEC environments on other operating
environments. The IBRw.d format in SAS code allows for a portable implementation for
writing the data in any operating environment.
Note: Different operating environments store integer binary values in different
ways. This concept is called byte ordering. For a detailed discussion about byte
ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms” on page 88. 4
Comparisons
3 The IBw.d and PIBw.d formats are used to write native format integers. (Native
format allows you to read and write values that are created in the same operating
environment.)
3 The IBRw.d and PIBRw.d formats are used to write little endian integers,
regardless of the operating environment you are writing on.
3 In Intel and DEC operating environments, the IBw.d and IBRw.d formats are
equivalent.
To view a table that shows the type of format to use with big endian and little endian
integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,ibr4.);
put y $hex8.;
Value of x
Results
----+----1
128
80000000
* The result is a hexadecimal representation of a 4-byte integer binary number. Each byte occupies
one column of the output field.
186
IEEEw.d Format
4
Chapter 3
See Also
Format:
“IBw.d Format” on page 183
IEEEw.d Format
Generates an IEEE floating-point value by multiplying a number by 10 raised to the dth power.
Numeric
Alignment: left
Caution: Large floating-point values and floating-point values that require precision
might not be identical to the original SAS value when they are written to an IBM
mainframe by using the IEEE format and read back into SAS using the IEE informat.
Category:
Syntax
IEEEw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 3–8
Tip: If w is 8, an IEEE double-precision, floating-point number is written. If w is 5,
6, or 7, an IEEE double-precision, floating-point number is written, which assumes
truncation of the appropriate number of bytes. If w is 4, an IEEE single-precision
floating-point number is written. If w is 3, an IEEE single-precision, floating-point
number is written, which assumes truncation of one byte.
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Details
This format is useful in operating environments where IEEEw.d is the floating-point
representation that is used. In addition, you can use the IEEEw.d format to create files
that are used by programs in operating environments that use the IEEE floating-point
representation.
Typically, programs generate IEEE values in single-precision (4 bytes) or
double-precision (8 bytes). Programs perform truncation solely to save space on output
files. Machine instructions require that the floating-point number be one of the two
lengths. The IEEEw.d format allows other lengths, which enables you to write data to
files that contain space-saving truncated data.
Formats
4
JULDAYw. Format
187
Examples
test1=put(x,ieee4.);
put test1 $hex8.;
test2=put(x,ieee5.);
put test2 $hex10.;
Value of x
Results
1
3F800000
3FF0000000
* The result contains hexadecimal representations of binary numbers stored in IEEE form.
JULDAYw. Format
Writes date values as the Julian day of the year.
Category: Date and Time
Alignment:
right
Syntax
JULDAYw.
Syntax Description
w
specifies the width of the output field.
Default: 3
Range: 3–32
Details
The JULDAYw. format writes SAS date values in the form ddd, where
ddd
is the number of the day, 1–365 (or 1–366 for leap years).
Examples
The example table uses the input values of 13515, which is the SAS date value that
corresponds to January 1, 1997, and 13589, which is the SAS date value that
corresponds to March 16, 1997.
188
JULIANw. Format
4
Chapter 3
SAS Statement
Results
----+----1
put date julday3.;
1
put date julday3.;
75
JULIANw. Format
Writes date values as Julian dates in the form yyddd or yyyyddd.
Category: Date and Time
Alignment: left
Syntax
JULIANw.
Syntax Description
w
specifies the width of the output field.
Default: 5
Range: 5–7
Tip: If w is 5, the JULIANw. format writes the date with a two-digit year. If w is 7,
the JULIANw. format writes the date with a four-digit year.
Details
The JULIANw. format writes SAS date values in the form yyddd or yyyyddd, where
yy or yyyy
is a two-digit or four-digit integer that represents the year.
ddd
is the number of the day, 1–365 (or 1–366 for leap years), in that year.
Examples
The example table uses the input value of 16794, which is the SAS date value that
corresponds to December 24, 2005 (the 358th day of the year).
SAS Statement
Results
----+----1
put date julian5.;
05358
put date julian7.;
2005358
Formats
4
MDYAMPMw.d Format
189
See Also
Functions:
“DATEJUL Function” on page 611
“JULDATE Function” on page 832
Informat:
“JULIANw. Informat” on page 1285
MDYAMPMw.d Format
Writes datetime values in the form mm/dd/yy<yy> hh:mm AM|PM. The year can be either two or
four digits.
Category: Date and Time
Alignment:
right
Default Time Period:
AM
Syntax
MDYAMPMw.
Syntax Description
w
specifies the width of the output field.
Default: 19
Range: 8−40
Details
The MDYAMPMw.d format writes SAS datetime values in the following form:
mm/dd/yy<yy> hh:mm< AM | PM>
The following list explains the datetime variables:
mm
is an integer from 1 through 12 that represents the month.
dd
is an integer from 1 through 31 that represents the day of the month.
yy or yyyy
specifies a two-digit or four-digit integer that represents the year.
hh
is the number of hours that range from 0 through 23.
mm
is the number of minutes that range from 00 through 59.
190
MMDDYYw. Format
4
Chapter 3
AM | PM
specifies either the time period 00:01−12:00 noon (AM) or the time period
12:01−12:00 midnight (PM). The default is AM.
date and time separator characters
is one of several special characters, such as the slash (/), colon (:), or a blank
character that SAS uses to separate date and time components.
Comparison
The MDYAMPMw. format writes datetime values with separators in the form mm/dd/
yy<yy> hh:mm AM | PM, and requires a space between the date and the time.
The DATETIMEw.d format writes datetime values with separators in the form
ddmmmyy<yy>: hh:mm:ss.ss.
Examples
This example uses the input value of 1537113180, which is the SAS datetime value
that corresponds to 3:53:00 PM on September 15, 2008.
SAS Statement
Results
put dt mdyampm25.
9/15/2008 3:53 PM
See Also
Format:
“DATETIMEw.d Format” on page 151
Informat:
“MDYAMPMw.d Informat” on page 1286
MMDDYYw. Format
Writes date values in the form mmdd<yy>yy or mm/dd/<yy>yy, where a forward slash is the
separator and the year appears as either 2 or 4 digits.
Category:
Alignment:
Date and Time
right
Syntax
MMDDYYw.
Formats
4
MMDDYYw. Format
191
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–10
Interaction: When w has a value of from 2 to 5, the date appears with as much of
the month and the day as possible. When w is 7, the date appears as a two-digit
year without slashes.
Details
The MMDDYYw. format writes SAS date values in the form mmdd<yy>yy or mm/dd/
<yy>yy, where
mm
is an integer that represents the month.
/
is the separator.
dd
is an integer that represents the day of the month.
<yy>yy
is a two-digit or four-digit integer that represents the year.
Examples
The following examples use the input value of 16734, which is the SAS date value
that corresponds to October 25, 2005.
SAS Statement
Results
----+----1----+
put day mmddyy2.;
10
put day mmddyy3.;
10
put day mmddyy4.;
1025
put day mmddyy5.;
10/25
put day mmddyy6.;
102505
put day mmddyy7.;
102505
put day mmddyy8.;
10/25/05
put day mmddyy10.;
10/25/2005
192
MMDDYYxw. Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 148
“DDMMYYw. Format” on page 154
“MMDDYYxw. Format” on page 192
“YYMMDDw. Format” on page 265
Functions:
“DAY Function” on page 613
“MDY Function” on page 885
“MONTH Function” on page 897
“YEAR Function” on page 1176
Informats:
“DATEw. Informat” on page 1263
“DDMMYYw. Informat” on page 1266
“YYMMDDw. Informat” on page 1345
MMDDYYxw. Format
Writes date values in the form mmdd<yy>yy or mm-dd-<yy>yy, where the x in the format name is
a character that represents the special character which separates the month, day, and year. The
special character can be a hyphen (-), period (.), blank character, slash (/), colon (:), or no
separator; the year can be either 2 or 4 digits.
Category:
Alignment:
Date and Time
right
Syntax
MMDDYYxw.
Syntax Description
x
identifies a separator or specifies that no separator appear between the month, the
day, and the year. Valid values for x are:
B
separates with a blank
C
separates with a colon
D
separates with a dash
N
indicates no separator
Formats
4
MMDDYYxw. Format
193
P
separates with a period
S
separates with a slash.
w
specifies the width of the output field.
Default: 8
Range: 2–10
Interaction: When w has a value of from 2 to 5, the date appears with as much of
the month and the day as possible. When w is 7, the date appears as a two-digit
year without separators.
Interaction: When x has a value of N, the width range changes to 2–8.
Details
The MMDDYYxw. format writes SAS date values in the form mmdd<yy>yy or
mmxddx<yy>yy, where
mm
is an integer that represents the month.
x
is a specified separator.
dd
is an integer that represents the day of the month.
<yy>yy
is a two-digit or four-digit integer that represents the year.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to May 14, 2009.
SAS Statement
Results
----+----1----+
put day mmddyyc5.;
05:14
put day mmddyyd8.;
05-14-09
put day mmddyyp10.;
05.14.2009
put day mmddyyn8.;
05142009
See Also
Formats:
“DATEw. Format” on page 148
194
MMSSw.d Format
4
Chapter 3
“DDMMYYxw. Format” on page 155
“MMDDYYw. Format” on page 190
“YYMMDDxw. Format” on page 266
Functions:
“DAY Function” on page 613
“MDY Function” on page 885
“MONTH Function” on page 897
“YEAR Function” on page 1176
Informat:
“MMDDYYw. Informat” on page 1288
MMSSw.d Format
Writes time values as the number of minutes and seconds since midnight.
Category:
Date and Time
right
Alignment:
Syntax
MMSSw.d
Syntax Description
w
specifies the width of the output field.
Default: 5
Range:
Tip:
2–20
Set w to a minimum of 5 to write a value that represents minutes and seconds.
d
specifies the number of digits to the right of the decimal point in the seconds value.
Therefore, the SAS time value includes fractional seconds. This argument is optional.
Range:
0–19
Restriction:
must be less than w
Details
The MMSS format uses asterisks to format values that are outside the time range 0–24
hours, such as datetime values.
Examples
The example table uses the input value of 4530.
Formats
SAS Statement
4
MMYYw. Format
195
Results
----+----1
put time mmss.;
75:30
See Also
Formats:
“HHMMw.d Format” on page 180
“TIMEw.d Format” on page 239
Functions:
“HMS Function” on page 771
“MINUTE Function” on page 889
“SECOND Function” on page 1071
Informat:
“TIMEw. Informat” on page 1330
MMYYw. Format
Writes date values in the form mmM<yy>yy, where M is the separator and the year appears as
either 2 or 4 digits.
Category: Date and Time
Alignment:
right
Syntax
MMYYw.
Syntax Description
w
specifies the width of the output field.
Default: 7
Range: 5–32
Interaction: When w has a value of 5 or 6, the date appears with only the last two
digits of the year. When w is 7 or more, the date appears with a four-digit year.
Details
The MMYYw. format writes SAS date values in the form mmM<yy>yy, where
196
MMYYxw. Format
4
Chapter 3
mm
is an integer that represents the month.
M
is the character separator.
<yy>yy
is a two-digit or four-digit integer that represents the year.
Examples
The following examples use the input value of 16734, which is the SAS date value
that corresponds to October 25, 2005.
SAS Statement
Results
----+----1----+
put date mmyy5.;
put date mmyy6.;
10M05
10M05
put date mmyy.;
10M2005
put date mmyy7.;
10M2005
put date mmyy10.;
10M2005
See Also
Format:
“MMYYxw. Format” on page 196
“YYMMw. Format” on page 262
MMYYxw. Format
Writes date values in the form mm<yy>yy or mm-<yy>yy, where the x in the format name is a
character that represents the special character that separates the month and the year, which can
be a hyphen (-), period (.), blank character, slash (/), colon (:), or no separator; the year can be
either 2 or 4 digits.
Category:
Date and Time
Alignment:
Syntax
MMYYxw.
right
Formats
4
MMYYxw. Format
197
Syntax Description
x
identifies a separator or specifies that no separator appear between the month and
the year. Valid values for x are
C
separates with a colon
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a forward slash.
w
specifies the width of the output field.
Default: 7
Range: 5–32
Interaction: When x is set to N, no separator is specified. The width range is then
4–32, and the default changes to 6.
Interaction: When x has a value of C, D, P, or S and w has a value of 5 or 6, the
date appears with only the last two digits of the year. When w is 7 or more, the
date appears with a four-digit year.
Interaction: When x has a value of N and w has a value of 4 or 5, the date appears
with only the last two digits of the year. When x has a value of N and w is 6 or
more, the date appears with a four-digit year.
Details
The MMYYxw. format writes SAS date values in the form mm<yy>yy or mmx<yy>yy,
where
mm
is an integer that represents the month.
x
is a specified separator.
<yy>yy
is a two-digit or four-digit integer that represents the year.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to May 14, 2009.
SAS Statement
Results
----+----1----+
put date mmyyc5.;
05:09
put date mmyyd.;
05-2009
198
4
MONNAMEw. Format
Chapter 3
SAS Statement
Results
put date mmyyn4.;
0509
put date mmyyp8.;
put date mmyys10.;
05.2009
05/2009
See Also
Format:
“MMYYw. Format” on page 195
“YYMMxw. Format” on page 263
MONNAMEw. Format
Writes date values as the name of the month.
Category:
Date and Time
right
Alignment:
Syntax
MONNAMEw.
Syntax Description
w
specifies the width of the output field.
Default: 9
Range:
Tip:
1–32
Use MONNAME3. to print the first three letters of the month name.
Details
If necessary, SAS truncates the name of the month to fit the format width.
Examples
The example table uses the input value of 16500, which is the SAS date value that
corresponds to March 5, 2005.
Formats
SAS Statement
4
MONTHw. Format
Results
----+----1
put date monname1.;
M
put date monname3.;
Mar
put date monname5.;
March
See Also
Format:
“MONTHw. Format” on page 199
MONTHw. Format
Writes date values as the month of the year.
Category: Date and Time
Alignment:
right
Syntax
MONTHw.
Syntax Description
w
specifies the width of the output field.
Default: 2
Range: 1–32
Tip:
Use MONTH1. to obtain a hexadecimal value.
Details
The MONTHw. format writes the month (1 through 12) of the year from a SAS date
value. If the month is a single digit, the MONTHw. format places a leading blank
before the digit. For example, the MONTHw. format writes 4 instead of 04.
Examples
The example table uses the input value of 18031, which is the SAS date value that
corresponds to May 14, 2009.
199
200
MONYYw. Format
4
Chapter 3
SAS Statement
Results
----+----1
put date month.;
5
See Also
Format:
“MONNAMEw. Format” on page 198
MONYYw. Format
Writes date values as the month and the year in the form mmmyy or mmmyyyy.
Category:
Date and Time
Alignment:
right
Syntax
MONYYw.
Syntax Description
w
specifies the width of the output field.
Default: 5
Range:
5–7
Details
The MONYYw. format writes SAS date values in the form mmmyy or mmmyyyy, where
mmm
is the first three letters of the month name.
yy or yyyy
is a two-digit or four-digit integer that represents the year.
Comparisons
The MONYYw. format and the DTMONYYw. format are similar in that they both
write date values. The difference is that MONYYw. expects a SAS date value as input,
and DTMONYYw. expects a datetime value.
Formats
4
NEGPARENw.d Format
Examples
The example table uses the input value of 16794, which is the SAS date value that
corresponds to December 24, 2005.
SAS Statement
Results
----+----1
put date monyy5.;
DEC05
put date monyy7.;
DEC2005
See Also
Formats:
“DTMONYYw. Format” on page 162
“DDMMYYw. Format” on page 154
“MMDDYYw. Format” on page 190
“YYMMDDw. Format” on page 265
Functions:
“MONTH Function” on page 897
“YEAR Function” on page 1176
Informat:
“MONYYw. Informat” on page 1290
NEGPARENw.d Format
Writes negative numeric values in parentheses.
Category: Numeric
Alignment:
right
Syntax
NEGPARENw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 1–32
201
202
NUMXw.d Format
4
Chapter 3
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: 0
Range:
0–31
Details
The NEGPARENw.d format attempts to right-align output values. If the input value is
negative, NEGPARENw.d displays the output by enclosing the value in parentheses, if
the field that you specify is wide enough. Otherwise, it uses a minus sign to represent
the negative value. If the input value is non-negative, NEGPARENw.d displays the
value with a leading and trailing blank to ensure proper column alignment. It reserves
the last column for a close parenthesis even when the value is positive.
Comparisons
The NEGPARENw.d format is similar to the COMMAw.d format in that it separates
every three digits of the value with a comma.
Examples
put @1 sales negparen8.;
Value of sales
Results
----+----1----+
100
100
1000
1,000
-200
(200)
-2000
(2,000)
NUMXw.d Format
Writes numeric values with a comma in place of the decimal point.
Numeric
Alignment: right
Category:
Syntax
NUMXw.d
Formats
4
NUMXw.d Format
Syntax Description
w
specifies the width of the output field.
Default: 12
Range: 1–32
d
specifies the number of digits to the right of the decimal point (comma) in the
numeric value. This argument is optional.
Default: 0
Range: 0–31
Details
The NUMXw.d format writes numeric values with a comma in place of the decimal
point.
Comparisons
The NUMXw.d format is similar to the w.d format except that NUMXw.d writes
numeric values with a comma in place of the decimal point.
Examples
put x numx10.2;
Value of x
Results
----+----1----+
896.48
896,48
64.89
64,89
3064.10
3064,10
See Also
Format:
“w.d Format” on page 246
Informat:
“NUMXw.d Informat” on page 1292
203
204
OCTALw. Format
4
Chapter 3
OCTALw. Format
Converts numeric values to octal representation.
Numeric
Alignment: left
Category:
Syntax
OCTALw.
Syntax Description
w
specifies the width of the output field.
Default: 3
Range: 1–24
Details
If necessary, the OCTALw. format converts numeric values to integers before displaying
them in octal representation.
Comparisons
OCTALw. converts numeric values to octal representation. The $OCTALw. format
converts character values to octal representation.
Examples
put x octal6.;
Value of x
Results
----+----1
3592
007010
Formats
4
PDw.d Format
205
PDw.d Format
Writes data in packed decimal format.
Category: Numeric
Alignment:
See:
left
PDw.d Format in the documentation for your operating environment.
Syntax
PDw.d
Syntax Description
w
specifies the width of the output field. The w value specifies the number of bytes, not
the number of digits. (In packed decimal data, each byte contains two digits.)
Default: 1
Range: 1–16
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
Different operating environments store packed decimal values in different ways.
However, the PDw.d format writes packed decimal values with consistent results if the
values are created in the same type of operating environment that you use to run SAS.
The PDw.d format writes missing numerical data as –0. When the PDw.d informat
reads a –0, it stores it as 0.
206
PDw.d Format
4
Chapter 3
Comparisons
The following table compares packed decimal notation in several programming
languages:
Language
Notation
SAS
PD4.
COBOL
COMP-3 PIC S9(7)
IBM 370 assembler
PL4
PL/I
FIXED DEC
Examples
y=put(x,pd4.);
put y $hex8.;
Value of x
Results*
----+----1
128
00000128
* The result is a hexadecimal representation of a binary number written in packed decimal format.
Each byte occupies one column of the output field.
Formats
4
PDJULGw. Format
PDJULGw. Format
Writes packed Julian date values in the hexadecimal format yyyydddF for IBM.
Category: Date and Time
Syntax
PDJULGw.
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 3-16
Details
The PDJULGw. format writes SAS date values in the form yyyydddF, where
yyyy
is the two-byte representation of the four-digit Gregorian year.
ddd
is the one-and-a-half byte representation of the three-digit integer that
corresponds to the Julian day of the year, 1–365 (or 1–366 for leap years).
F
is the half byte that contains all binary 1s, which assigns the value as positive.
Note: SAS interprets a two-digit year as belonging to the 100-year span that is
defined by the YEARCUTOFF= system option. 4
Examples
SAS Statement
Results
----+----1
date = ’17mar2005’d;
juldate = put(date,pdjulg4.);
put juldate $hex8.;
See Also
Formats:
“PDJULIw. Format” on page 208
“JULIANw. Format” on page 188
2005076F
207
208
PDJULIw. Format
4
Chapter 3
“JULDAYw. Format” on page 187
Functions:
“JULDATE Function” on page 832
“DATEJUL Function” on page 611
Informats:
“PDJULIw. Informat” on page 1297
“PDJULGw. Informat” on page 1296
“JULIANw. Informat” on page 1285
System Option:
“YEARCUTOFF= System Option” on page 1988
PDJULIw. Format
Writes packed Julian date values in the hexadecimal format ccyydddF for IBM.
Category:
Date and Time
Syntax
PDJULIw.
Syntax Description
w
specifies the width of the output field.
Default: 4
Range:
3-16
Details
The PDJULIw. format writes SAS date values in the form ccyydddF, where
cc
is the one-byte representation of a two-digit integer that represents the century.
yy
is the one-byte representation of a two-digit integer that represents the year. The
PDJULIw. format makes an adjustment for the century byte by subtracting 1900
from the 4–digit Gregorian year to produce the correct packed decimal ccyy
representation. A year value of 1998 is stored in ccyy as 0098, and a year value of
2011 is stored as 0111.
ddd
is the one-and-a-half byte representation of the three-digit integer that
corresponds to the Julian day of the year, 1–365 (or 1–366 for leap years).
F
is the half byte that contains all binary 1s, which assigns the value as positive.
Formats
4
PERCENTw.d Format
Note: SAS interprets a two-digit year as belonging to the 100-year span that is
defined by the YEARCUTOFF= system option. 4
Examples
SAS Statement
Results
----+----1
date = ’17mar2005’d;
juldate = put(date,pdjuli4.);
put juldate $hex8.;
0105076F
date = ’31dec2003’d;
juldate = put(date,pdjuli4.);
put juldate $hex8.;
0103365F
See Also
Formats:
“PDJULGw. Format” on page 207
“JULIANw. Format” on page 188
“JULDAYw. Format” on page 187
Functions:
“DATEJUL Function” on page 611
“JULDATE Function” on page 832
Informats:
“PDJULGw. Informat” on page 1296
“PDJULIw. Informat” on page 1297
“JULIANw. Informat” on page 1285
System Option:
“YEARCUTOFF= System Option” on page 1988
PERCENTw.d Format
Writes numeric values as percentages.
Category: Numeric
Alignment:
right
Syntax
PERCENTw.d
209
210
PERCENTNw.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 4–32
Tip: The width of the output field must account for the percent sign (% )and
parentheses for negative numbers, whether the number is negative or positive.
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Range: 0–31
Requirement: must be less than w
Details
The PERCENTw.d format multiplies values by 100, formats them the same as the
BESTw.d format, and adds a percent sign (%) to the end of the formatted value, while it
encloses negative values in parentheses.
Examples
put @10 gain percent10.;
Value of x
Results
----+----1----+----2
0.1
10%
1.2
120%
-0.05
(
See Also
Format:
“PERCENTNw.d Format” on page 210
PERCENTNw.d Format
Produces percentages, using a minus sign for negative values.
Numeric
Alignment: right
Category:
5%)
Formats
4
PERCENTNw.d Format
211
Syntax
PERCENTNw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 4–32
The width of the output field must account for the minus sign ( – ), the percent
sign ( % ), and a trailing blank, whether the number is negative or positive.
Tip:
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Range: 0–31
Requirement:
must be less than w
Details
The PERCENTNw.d format multiplies negative values by 100, formats them the same
as the BESTw.d format, adds a minus sign to the beginning of the value, and adds a
percent sign (%) to the end of the formatted value.
Comparisons
The PERCENTNw.d format produces percents by using a minus sign instead of
parentheses for negative values. The PERCENTw.d format produces percents by using
parentheses for negative values.
Examples
put x percentn10.;
Value of x
Results
--0.1
-10%
.2
20%
.8
80%
--0.05
-5%
--6.3
--630%
See Also
Format:
“PERCENTw.d Format” on page 209
212
4
PIBw.d Format
Chapter 3
PIBw.d Format
Writes positive integer binary (fixed-point) values.
Category:
Numeric
Alignment:
See:
left
PIBw.d Format in the documentation for your operating environment.
Syntax
PIBw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range:
1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range:
0–31
Details
All values are treated as positive. PIBw.d writes positive integer binary values with
consistent results if the values are created in the same type of operating environment
that you use to run SAS.
Note: Different operating environments store integer binary values in different
ways. This concept is called byte ordering. For a detailed discussion about byte
ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms” on page 88. 4
Comparisons
3 Positive integer binary values are the same as integer binary values except that
the sign bit is part of the value, which is always a positive integer. The PIBw.d
format treats all values as positive and includes the sign bit as part of the value.
3 The PIBw.d format with a width of 1 results in a value that corresponds to the
binary equivalent of the contents of a byte. A value that corresponds to the binary
equivalent of the contents of a byte is useful if your data contain values between
hexadecimal 80 and hexadecimal FF, where the high-order bit can be
misinterpreted as a negative sign.
3 The PIBw.d format is the same as the IBw.d format except that PIBw.d treats all
values as positive values.
3 The IBw.d and PIBw.d formats are used to write native format integers. (Native
format allows you to read and write values that are created in the same operating
Formats
4
PIBRw.d Format
213
environment.) The IBRw.d and PIBRw.d formats are used to write little endian
integers in any operating environment.
To view a table that shows the type of format to use with big endian and little
endian integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,pib1.);
put y $hex2.;
Value of x
Results
----+----1
12
0C
* The result is a hexadecimal representation of a one-byte binary number written in positive
integer binary format, which occupies one column of the output field.
See Also
Format:
“PIBRw.d Format” on page 213
PIBRw.d Format
Writes positive integer binary (fixed-point) values in Intel and DEC formats.
Category:
Numeric
Syntax
PIBRw.d
Syntax Description
w
specifies the width of the input field.
Default: 1
Range: 1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
214
PIBRw.d Format
4
Chapter 3
Details
All values are treated as positive. PIBRw.d writes positive integer binary values that
have been generated by and for Intel and DEC operating environments. Use PIBRw.d
to write positive integer binary data from Intel or DEC environments on other
operating environments. The PIBRw.d format in SAS code allows for a portable
implementation for writing the data in any operating environment.
Note: Different operating environments store positive integer binary values in
different ways. This concept is called byte ordering. For a detailed discussion about
byte ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little
Endian Platforms” on page 88. 4
Comparisons
3 Positive integer binary values are the same as integer binary values except that
the sign bit is part of the value, which is always a positive integer. The PIBRw.d
format treats all values as positive and includes the sign bit as part of the value.
3 The PIBRw.d format with a width of 1 results in a value that corresponds to the
binary equivalent of the contents of a byte. A value that corresponds to the binary
equivalent of the contents of a byte is useful if your data contain values between
hexadecimal 80 and hexadecimal FF, where the high-order bit can be
misinterpreted as a negative sign.
3 On Intel and DEC operating environments, the PIBw.d and PIBRw.d formats are
equivalent.
3 The IBw.d and PIBw.d formats are used to write native format integers. (Native
format allows you to read and write values that are created in the same operating
environment.) The IBRw.d and PIBRw.d formats are used to write little endian
integers in any operating environment.
To view a table that shows the type of format to use with big endian and little
endian integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,pibr2.);
put y $hex4.;
Value of x
Results
----+----1
128
8000
* The result is a hexadecimal representation of a two-byte binary number written in positive
integer binary format, which occupies one column of the output field.
See Also
Informat:
“PIBw.d Informat” on page 1300
Formats
4
PKw.d Format
215
PKw.d Format
Writes data in unsigned packed decimal format.
Category: Numeric
Alignment:
left
Syntax
PKw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–16
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Requirement:
must be less than w
Details
Each byte of unsigned packed decimal data contains two digits.
Comparisons
The PKw.d format is similar to the PDw.d format except that PKw.d does not write the
sign in the low-order byte.
Examples
y=put(x,pk4.);
put y $hex8.;
Value of x
Results*
----+----1
128
00000128
* The result is a hexadecimal representation of a four-byte number written in packed decimal
format. Each byte occupies one column of the output field.
216
PVALUEw.d Format
4
Chapter 3
PVALUEw.d Format
Writes p-values.
Numeric
Alignment: right
Category:
Syntax
PVALUEw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 3–32
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: the minimum of 4 and w–2
Range: 1–30
Restriction: must be less than w
Comparisons
The PVALUEw.d format follows the rules for the w.d format, except that
3 if the value x is such that 0 <= x < 10-d, x prints as “<.0...01” with d-1 zeros
3 missing values print as “.” unless you specify a different character by using the
MISSING= system option
Examples
put x pvalue6.4;
Value of x
Results
----+----1
.05
0.0500
0.000001
<.0001
Formats
Value of x
Results
0
<.0001
.0123456
0.0123
4
QTRw. Format
QTRw. Format
Writes date values as the quarter of the year.
Category: Date and Time
Alignment:
right
Syntax
QTRw.
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–32
Examples
The example table uses the input value of 16500, which is the SAS date value that
corresponds to March 5, 2005.
SAS Statement
Results
----+----1
put date qtr.;
1
217
218
QTRRw. Format
4
Chapter 3
See Also
Format:
“QTRRw. Format” on page 218
QTRRw. Format
Writes date values as the quarter of the year in Roman numerals.
Date and Time
Category:
Alignment:
right
Syntax
QTRRw.
Syntax Description
w
specifies the width of the output field.
Default: 3
Range:
3–32
Examples
The example table uses the input value of 16694, which is the SAS date value that
corresponds to September 15, 2005.
SAS Statement
Results
----+----1
put date qtrr.;
See Also
Format:
“QTRw. Format” on page 217
III
Formats
4
RBw.d Format
219
RBw.d Format
Writes real binary data (floating-point) in real binary format.
Category: Numeric
Alignment:
See:
left
RBw.d Format in the documentation for your operating environment.
Syntax
RBw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 2–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Details
The RBw.d format writes numeric data in the same way that SAS stores them. Because
it requires no data conversion, RBw.d is the most efficient method for writing data with
SAS.
Note: Different operating environments store real binary values in different ways.
However, RBw.d writes real binary values with consistent results in the same type of
operating environment that you use to run SAS. 4
CAUTION:
Using RB4. to write real binary data on equipment that conforms to the IEEE standard for
floating-point numbers results in a truncated eight-byte (double-precision) number rather
than a true four-byte (single-precision) floating-point number. 4
Comparisons
The following table compares the names of real binary notation in several programming
languages:
Language
4 Bytes
8 Bytes
SAS
RB4.
RB8.
Fortran
REAL*4
REAL*8
C
float
double
220
ROMANw. Format
4
Chapter 3
Language
4 Bytes
8 Bytes
COBOL
COMP-1
COMP-2
IBM 370 assembler
E
D
Examples
y=put(x,rb8.);
put y $hex16.;
Value of x
Results
----+---1----+----2
128
4280000000000000
* The result is a hexadecimal representation of an eight-byte real binary number as it looks on
an IBM mainframe. Each byte occupies one column of the output field.
ROMANw. Format
Writes numeric values as roman numerals.
Category:
Numeric
Alignment:
left
Syntax
ROMANw.
Syntax Description
w
specifies the width of the output field.
Default: 6
Range:
2–32
Details
The ROMANw. format truncates a floating-point value to its integer component before
the value is written.
Examples
put @5 year roman10.;
Formats
Value of year
Results
1998
MCMXCVIII
4
S370FFw.d Format
221
S370FFw.d Format
Writes native standard numeric data in IBM mainframe format.
Category:
Numeric
Syntax
S370FFw.d
Syntax Description
w
specifies the width of the output field.
Default: 12
Range: 1–32
d
specifies the power of 10 by which to divide the value. This argument is optional.
Range: 0–31
Details
The S370FFw.d format writes numeric data in IBM mainframe format (EBCDIC). The
EBCDIC numeric values are represented with one byte per digit. If EBCDIC is the
native format, S370FFw.d performs no conversion.
If a value is negative, an EBCDIC minus sign precedes the value. A missing value is
represented as a single EBCDIC period.
Comparisons
On an EBCDIC system, S370FFw.d behaves like the w.d format.
On all other systems, S370FFw.d performs the same role for numeric data that the
$EBCDICw. format does for character data.
Examples
y=put(x,s370ff5.);
put y $hex10.;
Value of x
Results*
----+----1
12345
F1F2F3F4F5
* The result is the hexadecimal representation for the integer.
222
S370FIBw.d Format
4
Chapter 3
See Also
Formats:
“$EBCDICw. Format” on page 112
“w.d Format” on page 246
S370FIBw.d Format
Writes integer binary (fixed-point) values, including negative values, in IBM mainframe format.
Category:
Alignment:
Numeric
left
Syntax
S370FIBw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Details
The S370FIBw.d format writes integer binary (fixed-point) values that are stored in IBM
mainframe format, including negative values that are represented in two’s complement
notation. S370FIBw.d writes integer binary values with consistent results if the values
are created in the same type of operating environment that you use to run SAS.
Use S370FIBw.d to write integer binary data in IBM mainframe format from data
that are created in other operating environments.
Note: Different operating environments store integer binary values in different
ways. This concept is called byte ordering. For a detailed discussion about byte
ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms” on page 88. 4
Comparisons
3 If you use SAS on an IBM mainframe, S370FIBw.d and IBw.d are identical.
Formats
4
S370FIBUw.d Format
223
3 S370FPIBw.d, S370FIBUw.d, and S370FIBw.d are used to write big endian
integers in any operating environment.
To view a table that shows the type of format to use with big endian and little
endian integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,s370fib4.);
put y $hex8.;
Value of x
Results
----+----1
128
00000080
* The result is a hexadecimal representation of a 4-byte integer binary number. Each byte occupies
one column of the output field.
See Also
Formats:
“S370FIBUw.d Format” on page 223
“S370FPIBw.d Format” on page 227
S370FIBUw.d Format
Writes unsigned integer binary (fixed-point) values in IBM mainframe format.
Category: Numeric
Alignment:
left
Syntax
S370FIBUw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
224
S370FIBUw.d Format
4
Chapter 3
Default: 0
Range:
0–10
Details
The S370FIBUw.d format writes unsigned integer binary (fixed-point) values that are
stored in IBM mainframe format, including negative values that are represented in
two’s complement notation. Unsigned integer binary values are the same as integer
binary values, except that all values are treated as positive. S370FIBUw.d writes
integer binary values with consistent results if the values are created in the same type
of operating environment that you use to run SAS.
Use S370FIBUw.d to write unsigned integer binary data in IBM mainframe format
from data that are created in other operating environments.
Note: Different operating environments store integer binary values in different
ways. This concept is called byte ordering. For a detailed discussion about byte
ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms” on page 88. 4
Comparisons
3 The S370FIBUw.d format is equivalent to the COBOL notation PIC 9(n) BINARY,
where n is the number of digits.
3 The S370FIBUw.d format is the same as the S370FIBw.d format except that the
S370FIBUw.d format always uses the absolute value instead of the signed value.
3 The S370FPIBw.d format writes all negative numbers as FFs, while the
S370FIBUw.d format writes the absolute value.
3 S370FPIBw.d, S370FIBUw.d, and S370FIBw.d are used to write big endian
integers in any operating environment.
To view a table that shows the type of format to use with big endian and little
endian integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,s370fibu1.);
put y $hex2.;
Value of x
Results*
245
F5
-245
F5
* The result is a hexadecimal representation of a one-byte integer binary number. Each byte
occupies one column of the output field.
See Also
Formats:
“S370FIBw.d Format” on page 222
“S370FPIBw.d Format” on page 227
Formats
4
S370FPDw.d Format
225
S370FPDw.d Format
Writes packed decimal data in IBM mainframe format.
Category: Numeric
Alignment:
left
Syntax
S370FPDw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–16
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
Use S370FPDw.d in other operating environments to write packed decimal data in the
same format as on an IBM mainframe computer.
Comparisons
The following table shows the notation for equivalent packed decimal formats in several
programming languages:
Language
Packed Decimal Notation
SAS
S370FPD4.
PL/I
FIXED DEC(7,0)
COBOL
COMP-3 PIC S9(7)
IBM 370 assembler
PL4
Examples
y=put(x,s370fpd4.);
put y $hex8.;
226
S370FPDUw.d Format
4
Chapter 3
Value of x
Results
----+----1
128
0000128C
* The result is a hexadecimal representation of a binary number written in packed decimal format.
Each byte occupies one column of the output field.
S370FPDUw.d Format
Writes unsigned packed decimal data in IBM mainframe format.
Category:
Numeric
Alignment:
left
Syntax
S370FPDUw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range:
1–16
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range:
0–31
Details
Use S370FPDUw.d in other operating environments to write unsigned packed decimal
data in the same format as on an IBM mainframe computer.
Comparisons
3 The S370FPDUw.d format is similar to the S370FPDw.d format except that the
S370FPDw.d format always uses the absolute value instead of the signed value.
3 The S370FPDUw.d format is equivalent to the COBOL notation PIC 9(n)
PACKED-DECIMAL, where the n value is the number of digits.
Formats
4
S370FPIBw.d Format
227
Examples
y=put(x,s370fpdu2.);
put y $hex4.;
Value of x
Results
123
123F
-123
123F
* The result is a hexadecimal representation of a binary number written in packed decimal
format. Each two hexadecimal characters correspond to one byte of binary data, and each
byte corresponds to one column of the output field.
S370FPIBw.d Format
Writes positive integer binary (fixed-point) values in IBM mainframe format.
Category: Numeric
Alignment:
left
Syntax
S370FPIBw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 1–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Details
Positive integer binary values are the same as integer binary values, except that all
values are treated as positive. S370FPIBw.d writes integer binary values with
consistent results if the values are created in the same type of operating environment
that you use to run SAS.
Use S370FPIBw.d to write positive integer binary data in IBM mainframe format
from data that are created in other operating environments.
228
S370FRBw.d Format
4
Chapter 3
Note: Different operating environments store integer binary values in different
ways. This concept is called byte ordering. For a detailed discussion about byte
ordering, see “Byte Ordering for Integer Binary Data on Big Endian and Little Endian
Platforms” on page 88. 4
Comparisons
3 If you use SAS on an IBM mainframe, S370FPIBw.d and PIBw.d are identical.
3 The S370FPIBw.d format is the same as the S370FIBw.d format except that the
S370FPIBw.d format treats all values as positive values.
3 S370FPIBw.d, S370FIBUw.d, and S370FIBw.d are used to write big endian
integers in any operating environment.
To view a table that shows the type of format to use with big endian and little
endian integers, see Table 3.1 on page 88.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 89.
Examples
y=put(x,s370fpib1.);
put y $hex2.;
Value of x
Results*
----+----1
12
0C
*The result is a hexadecimal representation of a one-byte binary number written in
positive integer binary format, which occupies one column of the output field.
See Also
Formats:
“S370FIBw.d Format” on page 222
“S370FIBUw.d Format” on page 223
S370FRBw.d Format
Writes real binary (floating-point) data in IBM mainframe format.
Category:
Alignment:
Numeric
left
Syntax
S370FRBw.d
Formats
4
S370FRBw.d Format
229
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 2–8
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–10
Details
A floating-point value consists of two parts: a mantissa that gives the value and an
exponent that gives the value’s magnitude.
Use S370FRBw.d in other operating environments to write floating-point binary data
in the same format as on an IBM mainframe computer.
Comparisons
The following table shows the notation for equivalent floating-point formats in several
programming languages:
Language
4 Bytes
8 Bytes
SAS
S370FRB4.
S370FRB8.
PL/I
FLOAT BIN(21)
FLOAT BIN(53)
Fortran
REAL*4
REAL*8
COBOL
COMP-1
COMP-2
IBM 370 assembler
E
D
C
float
double
Examples
y=put(x,s370frb6.);
put y $hex8.;
Value of x
Results*
128
42800000
-123
C2800000
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each two hexadecimal digits correspond to one byte of binary data,
and each byte corresponds to one column of the output field.
230
S370FZDw.d Format
4
Chapter 3
S370FZDw.d Format
Writes zoned decimal data in IBM mainframe format.
Category:
Numeric
Alignment:
left
Syntax
S370FZDw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range:
1–32
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range:
0–31
Details
Use S370FZDw.d in other operating environments to write zoned decimal data in the
same format as on an IBM mainframe computer.
Comparisons
The following table shows the notation for equivalent zoned decimal formats in several
programming languages:
Language
Zoned Decimal Notation
SAS
S370FZD3.
PL/I
PICTURE ’99T’
COBOL
PIC S9(3) DISPLAY
assembler
ZL3
Examples
y=put(x,s370fzd3.);
put y $hex6.;
Formats
Value of x
Results*
123
F1F2C3
-123
F1F2D3
4
S370FZDLw.d Format
231
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each two hexadecimal digits correspond to one byte of binary data,
and each byte corresponds to one column of the output field.
S370FZDLw.d Format
Writes zoned decimal leading–sign data in IBM mainframe format.
Category: Numeric
Alignment:
left
Syntax
S370FZDLw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 1–32
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
Use S370FZDLw.d in other operating environments to write zoned decimal leading-sign
data in the same format as on an IBM mainframe computer.
Comparisons
3 The S370FZDLw.d format is similar to the S370FZDw.d format except that the
S370FZDLw.d format displays the sign of the number in the first byte of the
formatted output.
3 The S370FZDLw.d format is equivalent to the COBOL notation PIC S9(n)
DISPLAY SIGN LEADING, where the n value is the number of digits.
Examples
y=put(x,s370fzdl3.);
put y $hex6.;
232
S370FZDSw.d Format
4
Chapter 3
Value of x
Results*
123
C1F2F3
-123
D1F2F3
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each two hexadecimal digits correspond to one byte of binary data,
and each byte corresponds to one column of the output field.
S370FZDSw.d Format
Writes zoned decimal separate leading-sign data in IBM mainframe format.
Numeric
Alignment: left
Category:
Syntax
S370FZDSw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–32
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
Use S370FZDSw.d in other operating environments to write zoned decimal separate
leading-sign data in the same format as on an IBM mainframe computer.
Comparisons
3 The S370FZDSw.d format is similar to the S370FZDLw.d format except that the
S370FZDSw.d format does not embed the sign of the number in the zoned output.
3 The S370FZDSw.d format is equivalent to the COBOL notation PIC S9(n)
DISPLAY SIGN LEADING SEPARATE, where the n value is the number of digits.
Examples
y=put (x,s370fzds4.);
put y $hex8.;
Formats
Value of x
Results*
123
4EF1F2F3
-123
60F1F2F3
4
S370FZDTw.d Format
233
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each two hexadecimal digits correspond to one byte of binary data,
and each byte corresponds to one column of the output field.
S370FZDTw.d Format
Writes zoned decimal separate trailing-sign data in IBM mainframe format.
Category: Numeric
Alignment:
left
Syntax
S370FZDTw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–32
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
Use S370FZDTw.d in other operating environments to write zoned decimal separate
trailing-sign data in the same format as on an IBM mainframe computer.
Comparisons
3 The S370FZDTw.d format is similar to the S370FZDSw.d format except that the
S370FZDTw.d format displays the sign of the number at the end of the formatted
output.
3 The S370FZDTw.d format is equivalent to the COBOL notation PIC S9(n)
DISPLAY SIGN TRAILING SEPARATE, where the n value is the number of digits.
234
S370FZDUw.d Format
4
Chapter 3
Examples
y=put (x,s370fzdt4.); ;
put y $hex8.;
Value of x
Results*
123
F1F2F34E
-123
F1F2F360
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each two hexadecimal digits correspond to one byte of binary data,
and each byte corresponds to one column of the output field.
S370FZDUw.d Format
Writes unsigned zoned decimal data in IBM mainframe format.
Numeric
Alignment: left
Category:
Syntax
S370FZDUw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 1–32
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
Use S370FZDUw.d in other operating environments to write unsigned zoned decimal
data in the same format as on an IBM mainframe computer.
Comparisons
3 The S370FZDUw.d format is similar to the S370FZDw.d format except that the
S370FZDUw.d format always uses the absolute value of the number.
3 The S370FZDUw.d format is equivalent to the COBOL notation PIC 9(n)
DISPLAY, where the n value is the number of digits.
Formats
4
SIZEKw.d Format
235
Examples
y=put (x,s370fzdu3.);
put y $hex6.;
Value of x
Results*
123
F1F2F3
-123
F1F2F3
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each pair of hexadecimal characters (such as F1) corresponds to one
byte of binary data, and each byte corresponds to one column of the output field.
SIZEKw.d Format
Writes a numeric value in the form nK for kilobytes.
Category: Numeric
Alignment:
right
Syntax
SIZEKw.d
Syntax Description
w
specifies the width of the output field.
Default: 9
Range: 2–33
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: 0
Range: 0–31
Details
To write a numeric value in the form nK by using the SIZEKw.d format, the value of n
is calculated by dividing the numeric value by 1,024. The symbol K indicates that the
value is a multiple of 1,024.
Example
put x sizek.;
236
SIZEKBw.d Format
4
Chapter 3
Value of x
Results
—-+—-1
1024
1K
200943
197K
See Also
Formats:
“SIZEKBw.d Format” on page 236
“SIZEKMGw.d Format” on page 237
Informat:
“SIZEKMGw.d Informat” on page 1327
SIZEKBw.d Format
Writes a numeric value in the form nKB for kilobytes.
Category:
Numeric
Alignment:
right
Syntax
SIZEKBw.d
Syntax Description
w
specifies the width of the output field.
Default: 9
Range:
2–33
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: 0
Range:
0–31
Details
To write a numeric value in the form nKB by using the SIZEKBw.d format, the value of
n is calculated by dividing the numeric value by 1,024. The symbol KB indicates that
the value is a multiple of 1,024.
Formats
4
SIZEKMGw.d Format
237
Examples
put x sizekb.;
Value of x
Results
—-+—-1
1024
1KB
200943
197KB
See Also
Formats:
“SIZEKw.d Format” on page 235
“SIZEKMGw.d Format” on page 237
Informat:
“SIZEKMGw.d Informat” on page 1327
SIZEKMGw.d Format
Writes a numeric value in the form nKB for kilobytes, nMB for megabytes, or nGB for gigabytes.
Category: Numeric
Alignment:
right
Syntax
SIZEKMGw.d
Syntax Description
w
specifies the width of the output field.
Default: 9
Range: 2–33
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: 0
Range: 0–31
238
4
SSNw. Format
Chapter 3
Details
When you specify the SIZEKMGw.d format, SAS determines the best suffix: KB for
kilobytes; MB for megabytes; or GB for gigabytes; and divides the SAS numeric value
by one of the following values:
KB
1024
MB
1048576
GB
1073741824
Examples
put x sizekmg.;
Value of x
Results
——+——1
3688
4KB
1048576
1MB
83409922345
8GB
See Also
Formats:
“SIZEKw.d Format” on page 235
“SIZEKBw.d Format” on page 236
Informat:
“SIZEKMGw.d Informat” on page 1327
SSNw. Format
Writes Social Security numbers.
Numeric
Alignment: none
Category:
Syntax
SSNw.
Formats
4
TIMEw.d Format
239
Syntax Description
w
specifies the width of the output field.
Default: 11
Restriction: w must be 11
Details
If the value is missing, SAS writes nine single periods with dashes between the third
and fourth periods and between the fifth and sixth periods. If the value contains fewer
than nine digits, SAS right aligns the value and pads it with zeros on the left. If the
value has more than nine digits, SAS writes it as a missing value.
Examples
put id ssn11.;
Value of id
Results
----+----1----+
263878439
263-87-8439
TIMEw.d Format
Writes time values as hours, minutes, and seconds in the form hh:mm:ss.ss.
Category: Date and Time
Alignment:
right
Syntax
TIMEw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–20
Make w large enough to produce the desired results. To obtain a complete time
value with three decimal places, you must allow at least 12 spaces: eight spaces to
Tip:
240
TIMEw.d Format
4
Chapter 3
the left of the decimal point, one space for the decimal point itself, and three
spaces for the decimal fraction of seconds.
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Default: 0
Range:
0–19
Requirement:
must be less than w
Details
The TIMEw.d format writes SAS time values in the form hh:mm:ss.ss, where
hh
is an integer.
Note: If hh is a single digit, TIMEw.d places a leading blank before the digit.
For example, the TIMEw.d. format writes 9:00 instead of 09:00. 4
mm
is the number of minutes, ranging from 00 through 59.
ss.ss
is the number of seconds, ranging from 00 through 59, with the fraction of a
second following the decimal point.
Comparisons
The TIMEw.d format is similar to the HHMMw.d format except that TIMEw.d includes
seconds.
The TIMEw.d format writes a leading blank for a single-hour digit. The TODw.d
format writes a leading zero for a single-hour digit.
Examples
The example table uses the input value of 59083, which is the SAS time value that
corresponds to 4:24:43 p.m.
SAS Statement
Results
----+----1
put begin time.;
See Also
Formats:
“HHMMw.d Format” on page 180
“HOURw.d Format” on page 182
“MMSSw.d Format” on page 194
“TODw.d Format” on page 242
16:24:43
Formats
4
TIMEAMPMw.d Format
241
Functions:
“HOUR Function” on page 774
“MINUTE Function” on page 889
“SECOND Function” on page 1071
“TIME Function” on page 1108
Informat:
“TIMEw. Informat” on page 1330
TIMEAMPMw.d Format
Writes time and datetime values as hours, minutes, and seconds in the form hh:mm:ss.ss with
AM or PM.
Category: Date and Time
Alignment:
right
Syntax
TIMEAMPMw.d
Syntax Description
w
specifies the width of the output field.
Default: 11
Range: 2–20
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Default: 0
Range: 0–19
Requirement:
must be less than w
Details
The TIMEAMPMw.d format writes SAS time values and SAS datetime values in the
form hh:mm:ss.ss with AM or PM, where
hh
is an integer that represents the hour.
mm
is an integer that represents the minutes.
242
TODw.d Format
4
Chapter 3
ss.ss
is the number of seconds to two decimal places.
Times greater than 23:59:59 PM appear as the next day.
Make w large enough to produce the desired results. To obtain a complete time value
with three decimal places and AM or PM, you must allow at least 11 spaces (hh:mm:ss
PM). If w is less than 5, SAS writes AM or PM only.
Comparisons
3 The TIMEAMPMMw.d format is similar to the TIMEMw.d format except, that
TIMEAMPMMw.d prints AM or PM at the end of the time.
3 TIMEw.d writes hours greater than 23:59:59 PM, and TIMEAMPMw.d does not.
Examples
The example table uses the input value of 59083, which is the SAS time value that
corresponds to 4:24:43 p.m.
SAS Statement
Results
----+----1----+
put begin timeampm3.;
PM
put begin timeampm5.;
4 PM
put begin timeampm7.;
4:24 PM
put begin timeampm11.;
4:24:43 PM
See Also
Format:
“TIMEw.d Format” on page 239
TODw.d Format
Writes SAS time values and the time portion of SAS datetime values in the form hh:mm:ss.ss.
Category:
Alignment:
Syntax
TODw.d
Date and Time
right
Formats
4
TODw.d Format
243
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–20
SAS writes a zero for a zero hour if the specified width is sufficient. For
example, 02:30 or 00:30.
Tip:
d
specifies the number of digits to the right of the decimal point in the seconds value.
This argument is optional.
Default: 0
Range: 0–19
Requirement:
must be less than w
Details
The TODw.d format writes SAS time and datetime values in the form hh:mm:ss.ss,
where
hh
is an integer that represents the hour.
mm
is an integer that represents the minutes.
ss.ss
is the number of seconds to two decimal places.
Comparisons
The TODw.d format writes a leading zero for a single-hour digit. The TIMEw.d format
and the HHMMw.d format write a leading blank for a single-hour digit.
Examples
In the following example, the SAS datetime value 1566742823 corresponds to August
24, 2009 at 2:20:23 p.m.
SAS Statement
Results
----+----1
begin = ’1:30’t;
put begin tod5.;
01:30
begin = 1566742823;
14:20:23
put begin tod9.;
244
VAXRBw.d Format
4
Chapter 3
See Also
Formats:
“HHMMw.d Format” on page 180
“TIMEw.d Format” on page 239
“TIMEAMPMw.d Format” on page 241
Function:
“TIMEPART Function” on page 1109
Informat:
“TIMEw. Informat” on page 1330
VAXRBw.d Format
Writes real binary (floating-point) data in VMS format.
Numeric
Alignment: right
Category:
Syntax
VAXRBw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2-8
d
specifies the power of 10 by which to divide the value. This argument is optional.
Default: 0
Range: 0–31
Details
Use the VAXRBw.d format to write data in native VAX/VMS floating-point notation.
Comparisons
If you use SAS that is running under VAX/VMS, then the VAXRBw.d and the RBw.d
formats are identical.
Example
x=1;
y=put(x,vaxrb8.);
put y=$hex16.;
Formats
Value of x
4
VMSZNw.d Format
245
Results*
----+----1
1
8040000000000000
* The result is the hexadecimal representation for the integer.
VMSZNw.d Format
Generates VMS and MicroFocus COBOL zoned numeric data.
Category: Numeric
left
Alignment:
Syntax
VMSZNw.d
w
specifies the width of the output field
Default: 1
Range: 1–32
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Details
The VMSZNw.d format is similar to the ZDw.d format. Both generate a string of ASCII
digits, and the last digit is a special character that denotes the magnitude of the last
digit and the sign of the entire number. The difference between these formats is in the
special character that is used for the last digit. The following table shows the special
characters that are used by the VMSZNw.d format.
Desired
Special
Desired
Special
Digit
Character
Digit
Character
0
0
–0
p
1
1
–1
q
2
2
–2
r
3
3
–3
s
4
4
–4
t
5
5
–5
u
6
6
–6
v
246
4
w.d Format
Chapter 3
Desired
Special
Desired
Special
Digit
Character
Digit
Character
7
7
–7
w
8
8
–8
x
9
9
–9
y
Data formatted using the VMSZNw.d format are ASCII strings.
If the value to be formatted is too large to fit in a field of the specified width, then
the VMSZNw.d format does the following:
3 For positive values, it sets the output to the largest positive number that fits in
the given width.
3 For negative values, it sets the output to the negative number of greatest
magnitude that fits in the given width.
Example
SAS Statements
Results
------+------1
x=1234;
put x vmszn4.;
1234
x=1234;
put x vmszn5.1;
12340
x=1234;
put x vmszn6.2;
123400
-1234;
put x vmszn5.;
0123t
See Also
Format:
“ZDw.d Format” on page 276
Informat:
“VMSZNw.d Informat” on page 1335
w.d Format
Writes standard numeric data one digit per byte.
Category:
Numeric
Alignment:
right
Alias:
Fw.d
Formats
See:
4
WEEKDATEw. Format
247
w.d Format in the documentation for your operating environment.
Syntax
w.d
Syntax Description
w
specifies the width of the output field.
Range: 1–32
Tip: Allow enough space to write the value, the decimal point, and a minus sign, if
necessary.
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Range: 0–31
Requirement: must be less than w
Tip: If d is 0 or you omit d, w.d writes the value without a decimal point.
Details
The w.d format rounds to the nearest number that fits in the output field. If w.d is too
small, SAS might shift the decimal to the BESTw. format. The w.d format writes
negative numbers with leading minus signs. In addition, w.d right aligns before writing
and pads the output with leading blanks.
Comparisons
The Zw.d format is similar to the w.d format except that Zw.d pads right-aligned
output with 0s instead of blanks.
Examples
put @7 x 6.3;
Value of x
Results
----+----1----+
23.45
23.450
WEEKDATEw. Format
Writes date values as the day of the week and the date in the form day-of-week, month-name dd,
yy (or yyyy).
248
WEEKDATEw. Format
4
Category:
Chapter 3
Date and Time
Alignment:
right
Syntax
WEEKDATEw.
Syntax Description
w
specifies the width of the output field.
Default: 29
Range:
3–37
Details
The WEEKDATEw. format writes SAS date values in the form day-of-week,
month-name dd, yy (or yyyy), where
dd
is an integer that represents the day of the month.
yy or yyyy
is a two-digit or four-digit integer that represents the year.
If w is too small to write the complete day of the week and month, SAS abbreviates as
needed.
Comparisons
The WEEKDATEw. format is the same as the WEEKDATXw. format except that
WEEKDATXw. prints dd before the month’s name.
Examples
The example table uses the input value of 16601 which is the SAS date value that
corresponds to June 14, 2005.
SAS Statement
Results
----+----1----+----2
put date weekdate3.;
put date weekdate9.;
Tue
Tuesday
put date weekdate15.;
Tue, Jun 14, 05
put date weekdate17.;
Tue, Jun 14, 2005
Formats
4
WEEKDATXw. Format
See Also
Formats:
“DATEw. Format” on page 148
“DDMMYYw. Format” on page 154
“MMDDYYw. Format” on page 190
“TODw.d Format” on page 242
“WEEKDATXw. Format” on page 249
“YYMMDDw. Format” on page 265
Functions:
“JULDATE Function” on page 832
“MDY Function” on page 885
“WEEKDAY Function” on page 1173
Informats:
“DATEw. Informat” on page 1263
“DDMMYYw. Informat” on page 1266
“MMDDYYw. Informat” on page 1288
“YYMMDDw. Informat” on page 1345
WEEKDATXw. Format
Writes date values as the day of the week and date in the form day-of-week, dd month-name yy
(or yyyy).
Category: Date and Time
Alignment:
right
Syntax
WEEKDATXw.
Syntax Description
w
specifies the width of the output field.
Default: 29
Range: 3–37
Details
The WEEKDATXw. format writes SAS date values in the form day-of-week, dd
month-name, yy (or yyyy), where
dd
is an integer that represents the day of the month.
249
250
WEEKDAYw. Format
4
Chapter 3
yy or yyyy
is a two-digit or a four-digit integer that represents the year.
If w is too small to write the complete day of the week and month, then SAS
abbreviates as needed.
Comparisons
The WEEKDATEw. format is the same as the WEEKDATXw. format, except that
WEEKDATEw. prints dd after the month’s name.
The WEEKDATXw. format is the same as the DTWKDATXw. format, except that
DTWKDATXw. expects a datetime value as input.
Examples
The example table uses the input value of 16490, which is the SAS date value that
corresponds to February 23, 2005.
SAS Statement
Results
----+----1----+----2----+----3
put date weekdatx.;
Wednesday, 23 February 2005
See Also
Formats:
“DTWKDATXw. Format” on page 163
“DATEw. Format” on page 148
“DDMMYYw. Format” on page 154
“MMDDYYw. Format” on page 190
“TODw.d Format” on page 242
“WEEKDATEw. Format” on page 247
“YYMMDDw. Format” on page 265
Functions:
“JULDATE Function” on page 832
“MDY Function” on page 885
“WEEKDAY Function” on page 1173
Informats:
“DATEw. Informat” on page 1263
“DDMMYYw. Informat” on page 1266
“MMDDYYw. Informat” on page 1288
“YYMMDDw. Informat” on page 1345
WEEKDAYw. Format
Writes date values as the day of the week.
Formats
4
WEEKUw. Format
Category: Date and Time
Alignment:
right
Syntax
WEEKDAYw.
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–32
Details
The WEEKDAYw. format writes a SAS date value as the day of the week (where
1=Sunday, 2=Monday, and so on).
Examples
The example table uses the input value of 16469, which is the SAS date value that
corresponds to February 2, 2005.
SAS Statement
Result
----+----1
put date weekday.;
4
See Also
Format:
“DOWNAMEw. Format” on page 160
WEEKUw. Format
Writes a week number in decimal format by using the U algorithm.
Category:
Alignment:
Date and Time
left
Syntax
WEEKUw.
251
252
WEEKUw. Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 11
Range: 3–200
Details
The WEEKUw. format writes a week-number format. The WEEKUw. format writes
the various formats depending on the specified width. Algorithm U calculates the SAS
date value by using the number of the week within the year (Sunday is considered the
first day of the week). The number-of-the-week value is represented as a decimal
number in the range 0–53, with a leading zero and maximum value of 53. For example,
the fifth week of the year would be represented as 05.
Refer to the following table for widths, formats, and examples:
Widths
Formats
Examples
3-4
Www
w01
5-6
yyWww
03W01
7-8
yyWwwdd
03W0101
9-10
yyyyWwwdd
2003W0101
11-200
yyyy-Www-dd
2003-W01-01
Comparisons
The WEEKVw. format writes the week number as a decimal number in the range
01–53, with weeks beginning on a Monday and week 1 of the year including both
January 4th and the first Thursday of the year. If the first Monday of January is the
2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year. The
WEEKWw. format writes the week number of the year as a decimal number in the
range 00–53, with Monday as the first day of week 1. The WEEKUw. format writes the
week number of the year (Sunday as the first day of the week) as a decimal number in
the range 0–53, with a leading zero.
Examples
sasdate = ’01JAN2003’d;
Formats
Statements
Results
----+----1----+
v=put(sasdate,weeku3.);
w=put(sasdate,weeku5.);
x=put(sasdate,weeku7.);
y=put(sasdate,weeku9.);
z=put(sasdate,weeku11.);
put v;
put w;
put x;
put y;
put z;
W00
03W00
03W0004
2003W0004
2003-W00-04
See Also
Formats:
“WEEKVw. Format” on page 253
“WEEKWw. Format” on page 255
Functions:
“WEEK Function” on page 1170
Informats:
“WEEKUw. Informat” on page 1337
“WEEKVw. Informat” on page 1339
“WEEKWw. Informat” on page 1341
WEEKVw. Format
Writes a week number in decimal format by using the V algorithm.
Category:
Date and Time
Alignment:
left
Syntax
WEEKVw.
Syntax Description
w
specifies the width of the output field.
Default: 11
Range: 3–200
4
WEEKVw. Format
253
254
WEEKVw. Format
4
Chapter 3
Details
The WEEKVw. format writes the various formats depending on the specified width.
Algorithm V calculates the SAS date value, with the number-of-the-week value
represented as a decimal number in the range 01–53, with a leading zero and
maximum value of 53. Weeks begin on a Monday and week 1 of the year is the week
that includes both January 4th and the first Thursday of the year. If the first Monday
of January is the 2nd, 3rd, or 4th, the preceding days are part of the last week of the
preceding year. For example, the fifth week of the year would be represented as 06.
Refer to the following table for widths, formats, and examples:
Widths
Formats
Examples
3-4
Www
w01
5-6
yyWww
03W01
7-8
yyWwwdd
03W0101
9-10
yyyyWwwdd
2003W0101
11-200
yyyy-Www-dd
2003-W01-01
Comparisons
The WEEKVw. format writes the week number as a decimal number in the range
01–53, with weeks beginning on a Monday and week 1 of the year including both
January 4th and the first Thursday of the year. If the first Monday of January is the
2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year. The
WEEKWw. format writes the week number of the year as a decimal number in the
range 00–53, with Monday as the first day of week 1. The WEEKUw. format writes the
week number of the year (Sunday as the first day of the week) as a decimal number in
the range 0–53, with a leading zero.
Examples
sasdate=’01JAN2003’d;
Statements
Results
----+----1----+
v=put(sasdate,weekv3.);
w=put(sasdate,weekv5.);
x=put(sasdate,weekv7.);
y=put(sasdate,weekv9.);
z=put(sasdate,weekv11.);
put v;
put w;
put x;
put y;
put z;
W01
03W01
03W0103
2003W0103
2003-W01-03
Formats
4
WEEKWw. Format
255
See Also
Formats:
“WEEKUw. Format” on page 251
“WEEKWw. Format” on page 255
Functions:
“WEEK Function” on page 1170
Informats:
“WEEKUw. Informat” on page 1337
“WEEKVw. Informat” on page 1339
“WEEKWw. Informat” on page 1341
WEEKWw. Format
Writes a week number in decimal format by using the W algorithm.
Date and Time
Alignment: left
Category:
Syntax
WEEKWw.
Syntax Description
w
specifies the width of the output field.
Default: 11
Range: 3–200
Details
The WEEKWw. format writes the various formats depending on the specified width.
Algorithm W calculates the SAS date value using the number of the week within the
year (Monday is considered the first day of the week). The number-of-the-week value is
represented as a decimal number in the range 0–53, with a leading zero and maximum
value of 53. For example, the fifth week of the year would be represented as 05.
Refer to the following table for widths, formats, and examples:
Widths
Formats
Examples
3-4
Www
w01
5-6
yyWww
03W01
7-8
yyWwwdd
03W0101
256
WEEKWw. Format
4
Chapter 3
Widths
Formats
Examples
9-10
yyyyWwwdd
2003W0101
11-200
yyyy-Www-dd
2003-W01-01
Comparisons
The WEEKVw. format writes the week number as a decimal number in the range
01–53. Weeks beginning on a Monday and on week 1 of the year include both January
4th and the first Thursday of the year. If the first Monday of January is the 2nd, 3rd, or
4th, the preceding days are part of the last week of the preceding year. The WEEKWw.
format writes the week number of the year as a decimal number in the range 00–53,
with Monday as the first day of week 1. The WEEKUw. format writes the week
number of the year (Sunday as the first day of the week) as a decimal number in the
range 0–53, with a leading zero.
Examples
sasdate = ’01JAN2003’d;
Statements
Results
----+----1----+
v=put(sasdate,weekw3.);
w=put(sasdate,weekw5.);
x=put(sasdate,weekw7.);
y=put(sasdate,weekw9.);
z=put(sasdate,weekw11.);
put v;
put w;
put x;
put y;
put z;
W03
03W03
03W0003
2003W0003
2003-W00-03
See Also
Formats:
“WEEKUw. Format” on page 251
“WEEKVw. Format” on page 253
Functions:
“WEEK Function” on page 1170
Informats:
“WEEKUw. Informat” on page 1337
“WEEKVw. Informat” on page 1339
“WEEKWw. Informat” on page 1341
Formats
4
WORDDATEw. Format
257
WORDDATEw. Format
Writes date values as the name of the month, the day, and the year in the form month-name dd,
yyyy.
Category: Date and Time
Alignment:
right
Syntax
WORDDATEw.
Syntax Description
w
specifies the width of the output field.
Default: 18
Range: 3–32
Details
The WORDDATEw. format writes SAS date values in the form month-name dd, yyyy,
where
dd
is an integer that represents the day of the month.
yyyy
is a four-digit integer that represents the year.
If the width is too small to write the complete month, SAS abbreviates as necessary.
Comparisons
The WORDDATEw. format is the same as the WORDDATXw. format except that
WORDDATXw. prints dd before the month’s name.
Examples
The example table uses the input value of 16601, which is the SAS date value that
corresponds to June 14, 2005.
SAS Statement
Result
----+----1----+----2
put term worddate3.;
put term worddate9.;
put term worddate12.;
put term worddate20.;
Jun
June
Jun 14, 2005
June 14, 2005
258
4
WORDDATXw. Format
Chapter 3
See Also
Format:
“WORDDATXw. Format” on page 258
WORDDATXw. Format
Writes date values as the day, the name of the month, and the year in the form dd month-name
yyyy.
Category:
Date and Time
Alignment:
right
Syntax
WORDDATXw.
Syntax Description
w
specifies the width of the output field.
Default: 18
Range:
3–32
Details
The WORDDATXw. format writes SAS date values in the form dd month-name, yyyy,
where
dd
is an integer that represents the day of the month.
yyyy
is a four-digit integer that represents the year.
If the width is too small to write the complete month, SAS abbreviates as necessary.
Comparisons
The WORDDATXw. format is the same as the WORDDATEw. format except that
WORDDATEw. prints dd after the month’s name.
Examples
The example table uses the input value of 16500, which is the SAS date value that
corresponds to March 5, 2005.
Formats
SAS Statement
4
WORDFw. Format
259
Results
----+----1----+----2
put term worddatx.;
05 March 2005
See Also
Format:
“WORDDATEw. Format” on page 257
WORDFw. Format
Writes numeric values as words with fractions that are shown numerically.
Category: Numeric
Alignment:
left
Syntax
WORDFw.
Syntax Description
w
specifies the width of the output field.
Default: 10
Range: 5–32767
Details
The WORDFw. format converts numeric values to their equivalent in English words,
with fractions that are represented numerically in hundredths. For example, 8.2 prints
as eight and 20/100.
Negative numbers are preceded by the word minus. When the value’s equivalent in
words does not fit into the specified field, it is truncated on the right and the last
character prints as an asterisk.
Comparisons
The WORDFw. format is similar to the WORDSw. format except that WORDFw.
prints fractions as numbers instead of words.
Examples
put price wordf15.;
260
WORDSw. Format
4
Chapter 3
Value of price
Results
----+----1----+
2.5
two and 50/100
See Also
Format:
“WORDSw. Format” on page 260
WORDSw. Format
Writes numeric values as words.
Numeric
Alignment: left
Category:
Syntax
WORDSw.
Syntax Description
w
specifies the width of the output field.
Default: 10
Range: 5–32767
Details
You can use the WORDSw. format to print checks with the amount written out below
the payee line.
Negative numbers are preceded by the word minus. If the number is not an integer,
the fractional portion is represented as hundredths. For example, 5.3 prints as five and
thirty hundredths. When the value’s equivalent in words does not fit into the specified
field, it is truncated on the right and the last character prints as an asterisk.
Comparisons
The WORDSw. format is similar to the WORDFw. format except that WORDSw. prints
fractions as words instead of numbers.
Examples
put price words23.;
Formats
Value of price
4
YEARw. Format
Results
----+----1----+----2----+
2.1
two and ten hundredths
See Also
Format:
“WORDFw. Format” on page 259
YEARw. Format
Writes date values as the year.
Category: Date and Time
Alignment:
right
Syntax
YEARw.
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 2–32
If w is less than 4, the last two digits of the year print. Otherwise, the year
value prints as four digits.
Tip:
Comparisons
The YEARw. format is similar to the DTYEARw. format in that they both write date
values. The difference is that YEARw. expects a SAS date value as input, and
DTYEARw. expects a datetime value.
Examples
The example table uses the input value of 16601, which is the SAS date value that
corresponds to June 14, 2005.
261
262
YYMMw. Format
4
Chapter 3
SAS Statement
Results
----+----1
put date year2.;
05
put date year4.;
2005
See Also
Format:
“DTYEARw. Format” on page 164
YYMMw. Format
Writes date values in the form <yy>yyMmm, where M is a character separator to indicate that the
month number follows the M and the year appears as either 2 or 4 digits.
Date and Time
Alignment: right
Category:
Syntax
YYMMw.
Syntax Description
w
specifies the width of the output field.
Default: 7
Range:
5–32
Interaction: When w has a value of 5 or 6, the date appears with only the last two
digits of the year. When w is 7 or more, the date appears with a four-digit year.
Details
The YYMMw. format writes SAS date values in the form <yy>yyMmm, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
M
is the character separator to indicate that the number of the month follows..
mm
is an integer that represents the month.
Formats
4
YYMMxw. Format
263
Examples
The following examples use the input value of 16734, which is the SAS date value
that corresponds to October 25, 2005.
SAS Statement
Result
----+----1----+
put date yymm5.;
put date yymm6.;
05M10
05M10
put date yymm.;
2005M10
put date yymm7.;
2005M10
put date yymm10.;
2005M10
See Also
Format:
“MMYYw. Format” on page 195
“YYMMxw. Format” on page 263
YYMMxw. Format
Writes date values in the form <yy>yymm or <yy>yy-mm, where the x in the format name is a
character that represents the special character that separates the year and the month, which can
be a hyphen (-), period (.), blank character, slash (/), colon (:), or no separator; the year can be
either 2 or 4 digits.
Category: Date and Time
Alignment:
right
Syntax
YYMMxw.
Syntax Description
x
identifies a separator or specifies that no separator appear between the year and the
month. Valid values for x are:
C
separates with a colon
264
YYMMxw. Format
4
Chapter 3
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a forward slash.
w
specifies the width of the output field.
Default: 7
Range: 5–32
Interaction: When x is set to N, no separator is specified. The width range is then
4–32, and the default changes to 6.
Interaction: When x has a value of C, D, P, or S and w has a value of 5 or 6, the
date appears with only the last two digits of the year. When w is 7 or more, the
date appears with a four-digit year.
Interaction: When x has a value of N and w has a value of 4 or 5, the date appears
with only the last two digits of the year. When x has a value of N and w is 6 or
more, the date appears with a four-digit year.
Details
The YYMMxw. format writes SAS date values in the form <yy>yymm or <yy>yyXmm,
where
<yy>yy
is a two-digit or four-digit integer that represents the year.
x
is a specified separator.
mm
is an integer that represents the month.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to May 14, 2009.
SAS Statement
Results
----+----1----+
put date yymmc5.;
09:05
put date yymmd.;
2009-05
put date yymmn4.;
0905
put date yymmp8.;
put date yymms10.;
2009.05
2009/05
Formats
4
YYMMDDw. Format
265
See Also
Format:
“MMYYxw. Format” on page 196
“YYMMw. Format” on page 262
YYMMDDw. Format
Writes date values in the form yymmdd or <yy>yy-mm-dd, where a dash is the separator and the
year appears as either 2 or 4 digits.
Category: Date and Time
Alignment:
right
Syntax
YYMMDDw.
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–10
Interaction: When w has a value of from 2 to 5, the date appears with as much of
the year and the month as possible. When w is 7, the date appears as a two-digit
year without dashes.
Details
The YYMMDDw. format writes SAS date values in the form yymmdd or
<yy>yy–mm–dd, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
–
is the separator.
mm
is an integer that represents the month.
dd
is an integer that represents the day of the month.
To format a date that has a four-digit year and no separators, use the YYMMDDx.
format.
Examples
The following examples use the input value of 16529, which is the SAS date value
that corresponds to April 3, 2005.
266
YYMMDDxw. Format
4
Chapter 3
SAS Statement
Results
----+----1----+
put day yymmdd2.;
05
put day yymmdd3.;
05
put day yymmdd4.;
0504
put day yymmdd5.;
05-04
put day yymmdd6.;
050403
put day yymmdd7.;
050403
put day yymmdd8.;
05-04-03
put day yymmdd10.;
2005-04-03
See Also
Formats:
“DATEw. Format” on page 148
“DDMMYYw. Format” on page 154
“MMDDYYw. Format” on page 190
“YYMMDDxw. Format” on page 266
Functions:
“DAY Function” on page 613
“MDY Function” on page 885
“MONTH Function” on page 897
“YEAR Function” on page 1176
Informats:
“DATEw. Informat” on page 1263
“DDMMYYw. Informat” on page 1266
“MMDDYYw. Informat” on page 1288
YYMMDDxw. Format
Writes date values in the form yymmdd or <yy>yy-mm-dd, where the x in the format name is a
character that represents the special character which separates the year, month, and day. The
special character can be a hyphen (-), period (.), blank character, slash (/), colon (:), or no
separator; the year can be either 2 or 4 digits.
Category:
Alignment:
Date and Time
right
Syntax
YYMMDDxw.
Formats
4
YYMMDDxw. Format
267
Syntax Description
x
identifies a separator or specifies that no separator appear between the year, the
month, and the day. Valid values for x are:
B
separates with a blank
C
separates with a colon
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a slash.
w
specifies the width of the output field.
Default: 8
Range: 2–10
Interaction: When w has a value of from 2 to 5, the date appears with as much of
the year and the month. When w is 7, the date appears as a two-digit year
without separators.
Interaction: When x has a value of N, the width range is 2–8.
Details
The YYMMDDxw. format writes SAS date values in the form yymmdd or
<yy>yyxmmxdd, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
x
is a specified separator.
mm
is an integer that represents the month.
dd
is an integer that represents the day of the month.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to May 14, 2009.
268
YYMONw. Format
4
Chapter 3
SAS Statement
Results
----+----1----+
put day yymmddc5.;
09:05
put day yymmddd8.;
09-05-14
put day yymmddp10.;
2009.05.14
put day yymmddn8.;
20090514
See Also
Formats:
“DATEw. Format” on page 148
“DDMMYYxw. Format” on page 155
“MMDDYYxw. Format” on page 192
“YYMMDDw. Format” on page 265
Functions:
“DAY Function” on page 613
“MDY Function” on page 885
“MONTH Function” on page 897
“YEAR Function” on page 1176
Informat:
“YYMMDDw. Informat” on page 1345
YYMONw. Format
Writes date values in the form yymmm or yyyymmm.
Date and Time
Alignment: right
Category:
Syntax
YYMONw.
Syntax Description
w
specifies the width of the output field. If the format width is too small to print a
four-digit year, only the last two digits of the year are printed.
Default: 7
Range: 5–32
Formats
4
YYQw. Format
269
Details
The YYMONw. format abbreviates the month’s name to three characters.
Examples
The example table uses the input value of 16601, which is the SAS date value that
corresponds to June 14, 2005.
SAS Statement
Results
----+----1
put date yymon6.;
05JUN
put date yymon7.;
2005JUN
See Also
Format:
“MMYYw. Format” on page 195
YYQw. Format
Writes date values in the form <yy>yyQq, where Q is the separator, the year appears as either 2 or
4 digits, and q is the quarter of the year.
Category: Date and Time
Alignment:
right
Syntax
YYQw.
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 4–32
Interaction: When w has a value of 4 or 5, the date appears with only the last two
digits of the year. When w is 6 or more, the date appears with a four-digit year.
270
4
YYQxw. Format
Chapter 3
Details
The YYQw. format writes SAS date values in the form <yy>yyQq, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
Q
is the character separator.
q
is an integer (1,2,3, or 4) that represents the quarter of the year.
Examples
The following examples use the input value of 16601, which is the SAS date value
that corresponds to June 14, 2005.
SAS Statements
Results
----+----1----+
put date yyq4.;
put date yyq5.;
05Q2
05Q2
put date yyq.;
2005Q2
put date yyq6.;
2005Q2
put date yyq10.;
2005Q2
See Also
Formats:
“YYQxw. Format” on page 270
“YYQRw. Format” on page 272
YYQxw. Format
Writes date values in the form <yy>yyq or <yy>yy-q, where the x in the format name is a character
that represents the special character that separates the year and the quarter or the year, which
can be a hyphen (-), period (.), blank character, slash (/), colon (:), or no separator; the year can
be either 2 or 4 digits.
Category:
Alignment:
Syntax
YYQxw.
Date and Time
right
Formats
4
YYQxw. Format
271
Syntax Description
x
identifies a separator or specifies that no separator appear between the year and the
quarter. Valid values for x are:
C
separates with a colon
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a forward slash.
w
specifies the width of the output field.
Default: 6
Range: 4–32
Interaction: When x is set to N, no separator is specified. The width range is then
3–32, and the default changes to 5.
Interaction: When w has a value of 4 or 5, the date appears with only the last two
digits of the year. When w is 6 or more, the date appears with a four-digit year.
Interaction: When x has a value of N and w has a value of 3 or 4, the date appears
with only the last two digits of the year. When x has a value of N and w is 5 or
more, the date appears with a four-digit year.
Details
The YYQxw. format writes SAS date values in the form <yy>yyq or <yy>yyxq, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
x
is a specified separator.
q
is an integer (1,2,3, or 4) that represents the quarter of the year.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to July 14, 2005.
SAS Statement
Results
----+----1----+
put date yyqc4.;
09:2
put date yyqd.;
2009-2
272
YYQRw. Format
4
Chapter 3
SAS Statement
Results
put date yyqn3.;
092
put date yyqp6.;
2009.2
put date yyqs8.;
2009/2
See Also
Formats:
“YYQw. Format” on page 269
“YYQRxw. Format” on page 273
YYQRw. Format
Writes date values in the form <yy>yyQqr, where Q is the separator, the year appears as either 2
or 4 digits, and qr is the quarter of the year expressed in roman numerals.
Date and Time
Alignment: right
Category:
Syntax
YYQRw.
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 6–32
Interaction: When the value of w is too small to write a four-digit year, the date
appears with only the last two digits of the year.
Details
The YYQRw. format writes SAS date values in the form <yy>yyQqr, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
Q
is the character separator.
qr
is a roman numeral (I, II, III, or IV) that represents the quarter of the year.
Formats
4
YYQRxw. Format
273
Examples
The following examples use the input value of 16601, which is the SAS date value
that corresponds to June 14, 2005.
SAS Statement
Result
----+----1----+
put date yyqr6.;
05QII
put date yyqr7.;
2005QII
put date yyqr.;
2005QII
put date yyqr8.;
2005QII
put date yyqr10.;
2005QII
See Also
Format:
“YYQw. Format” on page 269
“YYQRxw. Format” on page 273
YYQRxw. Format
Writes date values in the form <yy>yyqr or <yy>yy-qr, where the x in the format name is a
character that represents the special character that separates the year and the quarter or the year,
which can be a hyphen (-), period (.), blank character, slash (/), colon (:), or no separator; the
year can be either 2 or 4 digits and qr is the quarter of the year expressed in roman numerals.
Category: Date and Time
Alignment:
right
Syntax
YYQRxw.
Syntax Description
x
identifies a separator or specifies that no separator appear between the year and the
quarter. Valid values for x are:
C
separates with a colon
274
YYQRxw. Format
4
Chapter 3
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a forward slash.
w
specifies the width of the output field.
Default: 8
Range: 6–32
Interaction: When x is set to N, no separator is specified. The width range is then
5–32, and the default changes to 7.
Interaction: When the value of w is too small to write a four-digit year, the date
appears with only the last two digits of the year.
Details
The YYQRxw. format writes SAS date values in the form <yy>yyqr or <yy>yyxqr, where
<yy>yy
is a two-digit or four-digit integer that represents the year.
x
is a specified separator.
qr
is a roman numeral (I, II, III, or IV) that represents the quarter of the year.
Examples
The following examples use the input value of 18031, which is the SAS date value
that corresponds to May 14, 2009.
SAS Statement
Result
----+----1----+
put date yyqrc6.;
09:II
put date yyqrd.;
2009-II
put date yyqrn5.;
09II
put date yyqrp8.;
2009.II
put date yyqrs10.;
2009/II
Formats
4
Zw.d Format
275
See Also
Format:
“YYQxw. Format” on page 270
“YYQRw. Format” on page 272
Zw.d Format
Writes standard numeric data with leading 0s.
Category: Numeric
Alignment:
right
Syntax
Zw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–32
Allow enough space to write the value, the decimal point, and a minus sign, if
necessary.
Tip:
d
specifies the number of digits to the right of the decimal point in the numeric value.
This argument is optional.
Default: 0
Range: 0–31
Tip:
If d is 0 or you omit d, Zw.d writes the value without a decimal point.
Details
The Zw.d format writes standard numeric values one digit per byte and fills in 0s to the
left of the data value.
The Zw.d format rounds to the nearest number that will fit in the output field. If w.d
is too large to fit, SAS might shift the decimal to the BESTw. format. The Zw.d format
writes negative numbers with leading minus signs. In addition, it right aligns before
writing and pads the output with leading zeros.
276
ZDw.d Format
4
Chapter 3
Comparisons
The Zw.d format is similar to the w.d format except that Zw.d pads right-aligned
output with 0s instead of blanks.
Examples
put @5 seqnum z8.;
Value of seqnum
Results
----+----1
1350
00001350
ZDw.d Format
Writes numeric data in zoned decimal format .
Numeric
left
See: ZDw.d Format in the documentation for your operating environment.
Category:
Alignment:
Syntax
ZDw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–32
d
d
specifies to multiply the number by 10 . This argument is optional.
Default: 0
Range: 0–31
Details
The zoned decimal format is similar to standard numeric format in that every digit
requires one byte. However, the value’s sign is in the last byte, along with the last digit.
Note: Different operating environments store zoned decimal values in different
ways. However, the ZDw.d format writes zoned decimal values with consistent results
if the values are created in the same type of operating environment that you use to run
SAS. 4
Formats
4
SAS National Language Support (NLS): Reference Guide
277
Comparisons
The following table compares the zoned decimal format with notation in several
programming languages:
Language
Zoned Decimal Notation
SAS
ZD3.
PL/I
PICTURE ’99T’
COBOL
DISPLAY PIC S 999
IBM 370 assembler
ZL3
Examples
y=put(x,zd4.);
put y $hex8.;
Value of x
Results
120
F0F1F2C0
* The result is a hexadecimal representation of a binary number in zoned decimal format on an
IBM mainframe computer. Each byte occupies one column of the output field.
Formats Documented in Other SAS Publications
The main references for SAS formats are SAS Language Reference: Dictionary and
the SAS National Language Support (NLS): Reference Guide. See the documentation
for your operating environment for host-specific information about formats.
SAS National Language Support (NLS): Reference Guide
Table 3.5
Category
Formats for NLS
Description
BIDI text handling
$BIDIw. Format
Converts between a logically ordered string and a
visually ordered string, by reversing the order of Hebrew
and Arabic characters while preserving the order of
Latin words and numbers.
$LOGVSw.Format
Processes a character string that is in left-to-right-logical
order, and then writes the character string in visual
order.
$LOGVSRw. Format
Processes a character string that is in right-to-left-logical
order, and then writes the character string in visual
order.
278
SAS National Language Support (NLS): Reference Guide
Character
4
Chapter 3
$VSLOGw. Format
Processes a character string that is in visual order, and
then writes the character string in left-to-right logical
order.
$VSLOGRw. Format
Processes a character string that is in visual order, and
then writes the character string in right-to-left logical
order.
$UCS2Bw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character
string in big-endian, 16-bit, UCS2, Unicode encoding.
$UCS2BEw. Format
Processes a character string that is in big-endian, 16-bit,
UCS2, Unicode encoding, and then writes the character
string in the encoding of the current SAS session.
$UCS2Lw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character
string in little-endian, 16-bit, UCS2, Unicode encoding.
$UCS2LEw. Format
Processes a character string that is in little-endian,
16-bit, UCS2, Unicode encoding, and then writes the
character string in the encoding of the current SAS
session.
$UCS2Xw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character
string in native-endian, 16-bit, UCS2, Unicode encoding.
$UCS2XEw. Format
Processes a character string that is in native-endian,
16-bit, UCS2, Unicode encoding, and then writes the
character string in the encoding of the current SAS
session.
$UCS4Bw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character
string in big-endian, 32-bit, UCS4, Unicode encoding.
$UCS4BEw. Format
Processes a character string that is in big-endian, 32-bit,
UCS4, Unicode encoding, and then writes the character
string in the encoding of the current SAS session.
$UCS4Lw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character
string in little-endian, 32-bit, UCS4, Unicode encoding.
%UCS4LEw. Format
Processes a character string that is in little-endian,
32-bit, UCS4, Unicode encoding, and then writes the
character string in the encoding of the current SAS
session.
$UCS4Xw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character
string in native-endian, 32-bit, UCS4, Unicode encoding.
$UCS4XEw. Format
Processes a character string that is in native-endian,
32-bit, UCS4, Unicode encoding, and then writes the
character string in the encoding of the current SAS
session.
Formats
DBCS
Date and Time
4
SAS National Language Support (NLS): Reference Guide
$UESCw. Format
Processes a character string that is encoded in the
current SAS session, and then writes the character
string in Unicode escape (UESC) representation.
$UESCEw. Format
Processes a character string that is in Unicode escape
(UESC) representation, and then writes the character
string in the encoding of the current SAS session.
$UNCRw. Format
Processes a character string that is encoded in the
current SAS session, and then writes the character
string in numeric character representation (NCR).
$UNCREw. Format
Processes a character string that is in numeric character
representation (NCR), and then writes the character
string in the encoding of the current SAS session.
$UPARENw. Format
Processes a character string that is encoded in the
current SAS session, and then writes the character
string in Unicode parenthesis (UPAREN) representation.
$UPARENEw. Format
Processes a character string that is in Unicode
parenthesis (UPAREN), and then writes the character
string in the encoding of the current SAS session.
$UTF8Xw. Format
Processes a character string that is in the encoding of the
current SAS session, and then writes the character string
in universal transformation format (UTF-8) encoding.
$KANJIw. Format
Adds shift-code data to DBCS data.
$KANJIXw. Format
Removes shift-code data from DBCS data.
HDATEw. Format
Writes date values in the form yyyy mmmmm dd where
dd is the day-of-the-month, mmmmm represents the
month’s name in Hebrew, and yyyy is the year.
HEBDATEw. Format
Writes date values according to the Jewish calendar.
MINGUOw. Format
Writes date values as Taiwanese dates in the form
yyyymmdd .
NENGOw. Format
Writes date values as Japanese dates in the form
e.yymmdd .
NLDATEw. Format
Converts a SAS date value to the date value of the
specified locale, and then writes the date value as a date.
NLDATEMDw. Format
Converts the SAS date value to the date value of the
specified locale, and then writes the value as the name of
the month and the day of the month.
NLDATEMNw. Format
Converts a SAS date value to the date value of the
specified locale, and then writes the value as the name of
the month.
NLDATEWw. Format
Converts a SAS date value to the date value of the
specified locale, and then writes the value as the date
and the day of the week.
NLDATEWNw. Format
Converts the SAS date value to the date value of the
specified locale, and then writes the date value as the
day of the week.
279
280
SAS National Language Support (NLS): Reference Guide
4
Chapter 3
NLDATEYMw. Format
Converts the SAS date value to the date value of the
specified locale, and then writes the date value as the
year and the name of the month.
NLDATEYQw. Format
Converts the SAS date value to the date value of the
specified locale, and then writes the date value as the
year and the quarter.
NLDATEYRw. Format
Converts the SAS date value to the date value of the
specified locale, and then writes the date value as the
year.
NLDATEYWw. Format
Converts the SAS date value to the date value of the
specified locale, and then writes the date value as the
year and the week.
NLDATMw. Format
Converts a SAS datetime value to the datetime value of
the specified locale, and then writes the value as a
datetime.
NLDATMAPw. Format
Converts a SAS datetime value to the datetime value of
the specified locale, and then writes the value as a
datetime with a.m. or p.m.
NLDATMDTw. Format
Converts the SAS datetime value to the datetime value
of the specified locale, and then writes the value as the
name of the month, day of the month and year.
NLDATMMDw. Format
Converts the SAS datetime value to the datetime value
of the specified locale, and then writes the value as the
name of the month and the day of the month.
NLDATMMNw. Format
Converts the SAS datetime value to the datetime value
of the specified locale, and then writes the value as the
name of the month.
NLDATMTMw. Format
Converts the time portion of a SAS datetime value to the
time-of-day value of the specified locale, and then writes
the value as a time of day.
NLDATMWNw. Format
Converts a SAS datetime value to the datetime value of
the specified locale, and then writes the value as the day
of the week.
NLDATMWw. Format
Converts SAS datetime values to the locale sensitive
datetime string as the day of the week and the datetime.
NLDATMYMw. Format
Converts the SAS datetime value to the datetime value
of the specified locale, and then writes the value as the
year and the name of the month.
NLDATMYQw. Format
Converts the SAS datetime value to the datetime value
of the specified locale, and then writes the value as the
year and the quarter of the year.
NLDATMYRw. Format
Converts the SAS datetime value to the datetime value of
the specified locale, and then writes the value as the year.
NLDATMYWw. Format
Converts the SAS datetime value to the datetime value
of the specified locale, and then writes the value as the
year and the name of the week.
Formats
4
SAS National Language Support (NLS): Reference Guide
NLTIMEw. Format
Converts a SAS time value to the time value of the
specified locale, and then writes the value as a time
value.
NLTIMAPw. Format
Converts a SAS time value to the time value of a
specified locale, and then writes the value as a time
value with a.m. or p.m.
WEEKUw.
Format“WEEKUw.
Format” on page 251
Writes a week number in decimal format by using the U
algorithm.
WEEKVw.
Format“WEEKVw.
Format” on page 253
Writes a week number in decimal format by using the V
algorithm.
WEEKWw.Format“WEEKWw.Writes a week number in decimal format by using the W
Format” on page 255
algorithm.
Hebrew text handling
Numeric
YYWEEKUw. Format
Writes a week number in decimal format by using the U
algorithm, excluding day–of–the–week information.
YYWEEKVw. Format
Writes a week number in decimal format by using the V
algorithm, excluding day-of-the-week information.
YYWEEKWw. Format
Writes a week number in decimal format by using the W
algorithm, excluding the day-of-week information.
$CPTDWw. Format
Processes a character string that is in Hebrew text,
encoded in IBM-PC (cp862), and then writes the
character string in Windows Hebrew encoding (cp 1255).
$CPTWDw. Format
Processes a character string that is encoded in Windows
(cp1255), and then writes the character string in Hebrew
DOS (cp862) encoding.
EUROw.d Format
Writes numeric values with a leading euro symbol (E), a
comma that separates every three digits, and a period
that separates the decimal fraction.
EUROXw.d Format
Writes numeric values with a leading euro symbol (E), a
period that separates every three digits, and a comma
that separates the decimal fraction.
NLBESTw. Format
Writes the best numerical notation based on the locale.
NLMNIAEDw.d Format
Writes the monetary format of the international
expression for the United Arab Emirates.
NLMNIAUDw.d Format
Writes the monetary format of the international
expression for Australia.
NLMNIBGNw.d Format
Writes the monetary format of the international
expression for Bulgaria.
NLMNIBRLw.d Format
Writes the monetary format of the international
expression for Brazil.
NLMNICADw.d Format
Writes the monetary format of the international
expression for Canada.
NLMNICHFw.d Format
Writes the monetary format of the international
expression for Liechtenstein and Switzerland.
281
282
SAS National Language Support (NLS): Reference Guide
4
Chapter 3
NLMNICNYw.d Format
Writes the monetary format of the international
expression for China.
NLMNICZKw.d Format
Writes the monetary format of the international
expression for the Czech Republic.
NLMNIDKKw.d Format
Writes the monetary format of the local expression for
Denmark, Faroe Island, and Greenland.
NLMNIEEKw.d Format
Writes the monetary format of the international
expression for Estonia.
NLMNIEGPw.d Format
Writes the monetary format of the international
expression for Egypt.
NLMNIEURw.d Format
Writes the monetary format of the international
expression for Belgium, Finland, France, Germany,
Greece, Ireland, Italy, Luxembourg, Malta, the
Netherlands, Portugal, Slovenia, and Spain.
NLMNIGBPw.d Format
Writes the monetary format of the international
expression for the United Kingdom.
NLMNIHKDw.d Format
Writes the monetary format of the international
expression for Hong Kong.
NLMNIHRKw.d Format
Writes the monetary format of the international
expression for Croatia.
NLMNIHUFw.d Format
Writes the monetary format of the international
expression for Hungary.
NLMNIIDRw.d Format
Writes the monetary format of the international
expression for Indonesia.
NLMNIILSw.d Format
Writes the monetary format of the international
expression for Israel.
NLMNIINRw.d Format
Writes the monetary format of the international
expression for India.
NLMNIJPYw.d Format
Writes the monetary format of the international
expression for Japan.
NLMNIKRWw.d Format
Writes the monetary format of the international
expression for South Korea.
NLMNILTLw.d Format
Writes the monetary format of the international
expression for Lithuania.
NLMNILVLw.d Format
Writes the monetary format of the international
expression for Latvia.
NLMNIMOPw.d Format
Writes the monetary format of the international
expression for Macau.
NLMNIMXNw.d Format
Writes the monetary format of the international
expression for Mexico.
NLMNIMYRw.d Format
Writes the monetary format of the international
expression for Malaysia.
NLMNINOKw.d Format
Writes the monetary format of the international
expression for Norway.
Formats
4
SAS National Language Support (NLS): Reference Guide
NLMNINZDw.d Format
Writes the monetary format of the international
expression for New Zealand.
NLMNIPLNw.d Format
Writes the monetary format of the international
expression for Poland.
NLMNIROLw.d Format
Writes the monetary format of the international
expression for Romania.
NLMNIRUBw.d Format
Writes the monetary format of the international
expression for Russia.
NLMNISEKw.d Format
Writes the monetary format of the international
expression for Sweden.
NLMNISGDw.d Format
Writes the monetary format of the international
expression for Singapore.
NLMNISITw.d Format
Writes the monetary format of the international
expression for Slovenia.
NLMNISKKw.d Format
Writes the monetary format of the international
expression for Slovakia.
NLMNITHBw.d Format
Writes the monetary format of the international
expression for Thailand.
NLMNITRYw.d Format
Writes the monetary format of the international
expression for Turkey.
NLMNITWDw.d Format
Writes the monetary format of the international
expression for Taiwan.
NLMNIUSDw.d Format
Writes the monetary format of the international
expression for Puerto Rico and the United States.
NLMNIZARw.d Format
Writes the monetary format of the international
expression for South Africa.
NLMNLAEDw.d Format
Writes the monetary format of the local expression for
the United Arab Emirates.
NLMNLAUDw.d Format
Writes the monetary format of the local expression for
Australia.
NLMNLBGNw.d Format
Writes the monetary format of the local expression for
Bulgaria.
NLMNLBRLw.d Format
Writes the monetary format of the local expression for
Brazil.
NLMNLCADw.d Format
Writes the monetary format of the local expression for
Canada.
NLMNLCHFw.d Format
Writes the monetary format of the local expression for
Liechtenstein and Switzerland.
NLMNLCNYw.d Format
Writes the monetary format of the local expression for
China.
NLMNLCZKw.d Format
Writes the monetary format of the local expression for
the Czech Republic.
NLMNLDKKw.d Format
Writes the monetary format of the local expression for
Denmark, Faroe Island, and Greenland.
283
284
SAS National Language Support (NLS): Reference Guide
4
Chapter 3
NLMNLEEKw.d Format
Writes the monetary format of the local expression for
Estonia.
NLMNLEGPw.d Format
Writes the monetary format of the local expression for
Egypt.
NLMNLEURw.d Format
Writes the monetary format of the local expression for
Austria, Belgium, Finland, France, Germany, Greece,
Ireland, Italy, Luxembourg, Malta, the Netherlands,
Portugal, Slovenia, and Spain.
NLMNLGBPw.d Format
Writes the monetary format of the local expression for
the United Kingdom.
NLMNLHKDw.d Format
Writes the monetary format of the local expression for
Hong Kong.
NLMNLHRKw.d Format
Writes the monetary format of the local expression for
Croatia.
NLMNLHUFw.d Format
Writes the monetary format of the local expression for
Hungary.
NLMNLIDRw.d Format
Writes the monetary format of the local expression for
Indonesia.
NLMNLILSw.d Format
Writes the monetary format of the local expression for
Israel.
NLMNLINRw.d Format
Writes the monetary format of the local expression for
India.
NLMNLJPYw.d Format
Writes the monetary format of the local expression for
Japan.
NLMNLKRWw.d Format
Writes the monetary format of the local expression for
South Korea.
NLMNLLTLw.d Format
Writes the monetary format of the local expression for
Lithuania.
NLMNLLVLw.d Format
Writes the monetary format of the local expression for
Latvia.
NLMNLMOPw.d Format
Writes the monetary format of the local expression for
Macau.
NLMNLMXNw.d Format
Writes the monetary format of the local expression for
Mexico.
NLMNLMYRw.d Format
Writes the monetary format of the local expression for
Malaysia.
NLMNLNOKw.d Format
Writes the monetary format of the local expression for
Norway.
NLMNLNZDw.d Format
Writes the monetary format of the local expression for
New Zealand.
NLMNLPLNw.d Format
Writes the monetary format of the local expression for
Poland.
NLMNLROLw.d Format
Writes the monetary format of the local expression for
Romania.
Formats
4
SAS National Language Support (NLS): Reference Guide
NLMNLRUBw.d Format
Writes the monetary format of the local expression for
Russia.
NLMNSEKw.d Format
Writes the monetary format of the local expression for
Sweden.
NLMNLSGDw.d Format
Writes the monetary format of the local expression for
Singapore.
NLMNLSITw.d Format
Writes the monetary format of the local expression for
Slovenia.
NLMNLSKKw.d Format
Writes the monetary format of the local expression for
Slovakia.
NLMNLTHBw.d Format
Writes the monetary format of the local expression for
Thailand.
NLMNLTRYw.d Format
Writes the monetary format of the local expression for
Turkey.
NLMNLTWDw.d Format
Writes the monetary format of the local expression for
Taiwan.
NLMNLUSDw.d Format
Writes the monetary format of the local expression for
Puerto Rico, and the United States.
NLMNLZARw.d Format
Writes the monetary format of the local expression for
South Africa.
NLMNYw.d Format
Writes the monetary format of the local expression in the
specified locale using local currency.
NLMNYIw.d Format
Writes the monetary format of the international
expression in the specified locale.
NLNUMw.d Format
Writes the numeric format of the local expression in the
specified locale.
NLNUMIw.d Format
Writes the numeric format of the international
expression in the specified locale.
NLPCTw.d Format
Writes percentage data of the local expression in the
specified locale.
NLPCTIw.d Format
Writes percentage data of the international expression in
the specified locale.
NLPCTNw.d Format
Produces percentages, using a minus sign for negative
values.
NLPCTPw.d Format
Writes locale-specific numeric values as percentages.
NLPVALUEw.d Format
Writes p-values of the local expression in the specified
locale.
NLSTRMONw.d Format
Writes a numeric value as a day-of-the-month in the
specified locale.
NLSTRQTRw.d Format
Writes a numeric value as the quarter-of-the-year in the
specified locale.
NLSTRWKw.d Format
Writes a numeric value as the day-of-the-week in the
specified locale.
YENw.d
Writes numeric values with yen signs, commas, and
decimal points.
285
286
287
CHAPTER
4
Functions and CALL Routines
Definitions of Functions and CALL Routines 297
Definition of Functions 297
Definition of CALL Routines 297
Syntax 297
Syntax of Functions 297
Syntax of CALL Routines 298
Using Functions and CALL Routines 299
Restrictions Affecting Function Arguments 299
Using the OF Operator with Temporary Arrays 299
Characteristics of Target Variables 300
Notes about Descriptive Statistic Functions 301
Notes about Financial Functions 301
Using Pricing Functions 302
Using DATA Step Functions within Macro Functions 302
Using CALL Routines and the %SYSCALL Macro Statement 303
Using Functions to Manipulate Files 303
Function Compatibility with SBCS, DBCS, and MBCS Character Sets 304
Overview 304
I18N Level 0 304
I18N Level 1 304
I18N Level 2 305
Using Random-Number Functions and CALL Routines 305
Types of Random-Number Functions 305
Seed Values 305
Understanding How Functions Generate a Random-Number Stream 305
Using the DATA Step to Generate a Single Stream of Random Numbers 305
Using the %SYSFUNC Macro to Generate a Single Stream of Random Numbers 308
Comparison of Seed Values in Random-Number Functions and CALL Routines 309
Generating Multiple Streams from Multiple Seeds in Random-Number CALL Routines 309
Overview of Random-Number CALL Routines and Streams 309
Example 1: Using Multiple Seeds to Generate Multiple Streams 309
Example 2: Using Different Seeds with the CALL RANUNI Routine 312
Generating Multiple Variables from One Seed in Random-Number Functions 314
Overview of Functions and Streams 314
Example: Generating Random Uniform Variables with Overlapping Streams 314
Using the RAND Function as an Alternative 316
Effectively Using the Random-Number CALL Routines 316
Starting, Stopping, and Restarting a Stream 316
Example: Starting, Stopping, and Restarting a Stream 316
Comparison of Changing the Seed in a CALL Routine and in a Function 317
Example: Changing Seeds in a CALL Routine and in a Function 317
288
Contents
4
Chapter 4
Date and Time Intervals 318
Definition of a Date and Time Interval 318
Interval Names and SAS Dates 318
Incrementing Dates and Times by Using Multipliers and by Shifting Intervals 319
Commonly Used Time Intervals 319
Retail Calendar Intervals: ISO 8601 Compliant 320
Best Practices for Custom Interval Names 321
Pattern Matching Using Perl Regular Expressions (PRX) 323
Definition of Pattern Matching 323
Definition of Perl Regular Expression (PRX) Functions and CALL Routines 323
Benefits of Using Perl Regular Expressions in the DATA Step 323
Using Perl Regular Expressions in the DATA Step 324
Syntax of Perl Regular Expressions 324
The Components of a Perl Regular Expression 324
Basic Syntax for Finding a Match in a String 324
Basic Syntax for Searching and Replacing Text: Example 1 324
Basic Syntax for Searching and Replacing Text: Example 2 325
Replacing Text: Example 3 325
Example 1: Validating Data 326
Example 2: Replacing Text 328
Example 3: Extracting a Substring from a String 329
Example 4: Another Example of Extracting a Substring from a String 331
Writing Perl Debug Output to the SAS Log 333
Perl Artistic License Compliance 334
Base SAS Functions for Web Applications 334
Functions and CALL Routines by Category 335
Dictionary 360
ABS Function 360
ADDR Function 361
ADDRLONG Function 362
AIRY Function 363
ALLCOMB Function 364
ALLPERM Function 366
ANYALNUM Function 368
ANYALPHA Function 370
ANYCNTRL Function 372
ANYDIGIT Function 373
ANYFIRST Function 375
ANYGRAPH Function 377
ANYLOWER Function 379
ANYNAME Function 380
ANYPRINT Function 382
ANYPUNCT Function 384
ANYSPACE Function 386
ANYUPPER Function 388
ANYXDIGIT Function 389
ARCOS Function 391
ARCOSH Function 392
ARSIN Function 393
ARSINH Function 394
ARTANH Function 395
ATAN Function 396
ATAN2 Function 397
ATTRC Function 398
Functions and CALL Routines
ATTRN Function 400
BAND Function 404
BETA Function 405
BETAINV Function 406
BLACKCLPRC Function 407
BLACKPTPRC Function 409
BLKSHCLPRC Function 410
BLKSHPTPRC Function 412
BLSHIFT Function 414
BNOT Function 415
BOR Function 416
BRSHIFT Function 416
BXOR Function 417
BYTE Function 418
CAT Function 526
CATQ Function 528
CATS Function 532
CATT Function 534
CATX Function 537
CDF Function 540
CEIL Function 553
CEILZ Function 555
CEXIST Function 556
CHAR Function 557
CHOOSEC Function 558
CHOOSEN Function 559
CINV Function 560
CLOSE Function 562
CMISS Function 562
CNONCT Function 563
COALESCE Function 565
COALESCEC Function 566
COLLATE Function 567
COMB Function 568
COMPARE Function 569
COMPBL Function 572
COMPGED Function 573
COMPLEV Function 578
COMPOUND Function 581
COMPRESS Function 582
CONSTANT Function 585
CONVX Function 589
CONVXP Function 590
COS Function 591
COSH Function 592
COUNT Function 593
COUNTC Function 595
COUNTW Function 598
CSS Function 601
CUROBS Function 601
CV Function 602
DACCDB Function 603
DACCDBSL Function 604
DACCSL Function 605
4
Contents
289
290
Contents
4
Chapter 4
DACCSYD Function 606
DACCTAB Function 607
DAIRY Function 608
DATDIF Function 608
DATE Function 611
DATEJUL Function 611
DATEPART Function 612
DATETIME Function 613
DAY Function 613
DCLOSE Function 614
DCREATE Function 616
DEPDB Function 616
DEPDBSL Function 617
DEPSL Function 619
DEPSYD Function 619
DEPTAB Function 620
DEQUOTE Function 621
DEVIANCE Function 623
DHMS Function 627
DIF Function 628
DIGAMMA Function 629
DIM Function 630
DINFO Function 632
DIVIDE Function 633
DNUM Function 634
DOPEN Function 635
DOPTNAME Function 637
DOPTNUM Function 638
DREAD Function 639
DROPNOTE Function 640
DSNAME Function 641
DUR Function 642
DURP Function 643
ENVLEN Function 645
ERF Function 645
ERFC Function 646
EUCLID Function 647
EXIST Function 648
EXP Function 651
FACT Function 651
FAPPEND Function 652
FCLOSE Function 654
FCOL Function 655
FDELETE Function 656
FETCH Function 658
FETCHOBS Function 659
FEXIST Function 660
FGET Function 661
FILEEXIST Function 663
FILENAME Function 663
FILEREF Function 666
FINANCE Function 667
FIND Function 705
FINDC Function 707
Functions and CALL Routines
FINDW Function 713
FINFO Function 718
FINV Function 719
FIPNAME Function 721
FIPNAMEL Function 722
FIPSTATE Function 723
FIRST Function 724
FLOOR Function 725
FLOORZ Function 726
FNONCT Function 728
FNOTE Function 729
FOPEN Function 731
FOPTNAME Function 733
FOPTNUM Function 735
FPOINT Function 736
FPOS Function 737
FPUT Function 739
FREAD Function 741
FREWIND Function 742
FRLEN Function 743
FSEP Function 744
FUZZ Function 746
FWRITE Function 746
GAMINV Function 748
GAMMA Function 749
GARKHCLPRC Function 749
GARKHPTPRC Function 751
GCD Function 753
GEODIST Function 754
GEOMEAN Function 756
GEOMEANZ Function 758
GETOPTION Function 759
GETVARC Function 762
GETVARN Function 763
GRAYCODE Function 764
HARMEAN Function 767
HARMEANZ Function 768
HBOUND Function 770
HMS Function 771
HOLIDAY Function 772
HOUR Function 774
HTMLDECODE Function 775
HTMLENCODE Function 777
IBESSEL Function 778
IFC Function 779
IFN Function 781
INDEX Function 784
INDEXC Function 786
INDEXW Function 787
INPUT Function 790
INPUTC Function 792
INPUTN Function 794
INT Function 796
INTCINDEX Function 797
4
Contents
291
292
Contents
4
Chapter 4
INTCK Function 799
INTCYCLE Function 803
INTFIT Function 805
INTFMT Function 808
INTGET Function 810
INTINDEX Function 811
INTNX Function 814
INTRR Function 820
INTSEAS Function 821
INTSHIFT Function 823
INTTEST Function 825
INTZ Function 827
IORCMSG Function 828
IQR Function 829
IRR Function 830
JBESSEL Function 831
JULDATE Function 832
JULDATE7 Function 833
KURTOSIS Function 834
LAG Function 835
LARGEST Function 841
LBOUND Function 842
LCM Function 844
LCOMB Function 845
LEFT Function 846
LENGTH Function 847
LENGTHC Function 848
LENGTHM Function 849
LENGTHN Function 851
LEXCOMB Function 852
LEXCOMBI Function 855
LEXPERK Function 856
LEXPERM Function 859
LFACT Function 861
LGAMMA Function 862
LIBNAME Function 863
LIBREF Function 865
LOG Function 866
LOG1PX Function 867
LOG10 Function 868
LOG2 Function 868
LOGBETA Function 869
LOGCDF Function 870
LOGPDF Function 871
LOGSDF Function 873
LOWCASE Function 875
LPERM Function 875
LPNORM Function 876
MAD Function 878
MARGRCLPRC Function 879
MARGRPTPRC Function 881
MAX Function 883
MD5 Function 884
MDY Function 885
Functions and CALL Routines
MEAN Function 886
MEDIAN Function 887
MIN Function 888
MINUTE Function 889
MISSING Function 890
MOD Function 891
MODEXIST Function 893
MODULEC Function 894
MODULEN Function 894
MODZ Function 895
MONTH Function 897
MOPEN Function 897
MORT Function 900
MSPLINT Function 901
N Function 904
NETPV Function 905
NLITERAL Function 906
NMISS Function 908
NORMAL Function 909
NOTALNUM Function 909
NOTALPHA Function 911
NOTCNTRL Function 913
NOTDIGIT Function 914
NOTE Function 916
NOTFIRST Function 918
NOTGRAPH Function 919
NOTLOWER Function 921
NOTNAME Function 923
NOTPRINT Function 925
NOTPUNCT Function 926
NOTSPACE Function 928
NOTUPPER Function 930
NOTXDIGIT Function 932
NPV Function 934
NVALID Function 934
NWKDOM Function 937
OPEN Function 939
ORDINAL Function 941
PATHNAME Function 942
PCTL Function 944
PDF Function 945
PEEK Function 958
PEEKC Function 959
PEEKCLONG Function 962
PEEKLONG Function 963
PERM Function 964
POINT Function 966
POISSON Function 967
PROBBETA Function 968
PROBBNML Function 969
PROBBNRM Function 970
PROBCHI Function 971
PROBF Function 972
PROBGAM Function 973
4
Contents
293
294
Contents
4
Chapter 4
PROBHYPR Function 974
PROBIT Function 975
PROBMC Function 976
PROBNEGB Function 989
PROBNORM Function 990
PROBT Function 991
PROPCASE Function 992
PRXCHANGE Function 994
PRXMATCH Function 999
PRXPAREN Function 1003
PRXPARSE Function 1005
PRXPOSN Function 1007
PTRLONGADD Function 1010
PUT Function 1010
PUTC Function 1012
PUTN Function 1014
PVP Function 1015
QTR Function 1016
QUANTILE Function 1017
QUOTE Function 1019
RANBIN Function 1020
RANCAU Function 1021
RAND Function 1022
RANEXP Function 1033
RANGAM Function 1034
RANGE Function 1035
RANK Function 1036
RANNOR Function 1037
RANPOI Function 1038
RANTBL Function 1039
RANTRI Function 1040
RANUNI Function 1041
RENAME Function 1042
REPEAT Function 1044
RESOLVE Function 1045
REVERSE Function 1045
REWIND Function 1046
RIGHT Function 1047
RMS Function 1048
ROUND Function 1049
ROUNDE Function 1056
ROUNDZ Function 1057
SAVING Function 1059
SCAN Function 1060
SDF Function 1069
SECOND Function 1071
SIGN Function 1072
SIN Function 1072
SINH Function 1073
SKEWNESS Function 1074
SLEEP Function 1075
SMALLEST Function 1076
SOUNDEX Function 1077
SPEDIS Function 1078
Functions and CALL Routines
SQRT Function 1081
STD Function 1081
STDERR Function 1082
STFIPS Function 1082
STNAME Function 1084
STNAMEL Function 1085
STRIP Function 1086
SUBPAD Function 1088
SUBSTR (left of =) Function 1089
SUBSTR (right of =) Function 1090
SUBSTRN Function 1091
SUM Function 1095
SUMABS Function 1096
SYMEXIST Function 1097
SYMGET Function 1098
SYMGLOBL Function 1098
SYMLOCAL Function 1099
SYSGET Function 1100
SYSMSG Function 1101
SYSPARM Function 1102
SYSPROCESSID Function 1102
SYSPROCESSNAME Function 1103
SYSPROD Function 1104
SYSRC Function 1105
SYSTEM Function 1106
TAN Function 1107
TANH Function 1108
TIME Function 1108
TIMEPART Function 1109
TINV Function 1109
TNONCT Function 1110
TODAY Function 1112
TRANSLATE Function 1112
TRANSTRN Function 1113
TRANWRD Function 1116
TRIGAMMA Function 1118
TRIM Function 1119
TRIMN Function 1121
TRUNC Function 1122
UNIFORM Function 1123
UPCASE Function 1123
URLDECODE Function 1124
URLENCODE Function 1125
USS Function 1126
UUIDGEN Function 1127
VAR Function 1128
VARFMT Function 1128
VARINFMT Function 1130
VARLABEL Function 1131
VARLEN Function 1132
VARNAME Function 1133
VARNUM Function 1134
VARRAY Function 1135
VARRAYX Function 1136
4
Contents
295
296
Contents
4
Chapter 4
VARTYPE Function 1137
VERIFY Function 1139
VFORMAT Function 1140
VFORMATD Function 1141
VFORMATDX Function 1142
VFORMATN Function 1143
VFORMATNX Function 1144
VFORMATW Function 1145
VFORMATWX Function 1146
VFORMATX Function 1147
VINARRAY Function 1148
VINARRAYX Function 1149
VINFORMAT Function 1150
VINFORMATD Function 1151
VINFORMATDX Function 1152
VINFORMATN Function 1153
VINFORMATNX Function 1155
VINFORMATW Function 1156
VINFORMATWX Function 1157
VINFORMATX Function 1158
VLABEL Function 1159
VLABELX Function 1160
VLENGTH Function 1161
VLENGTHX Function 1162
VNAME Function 1163
VNAMEX Function 1164
VTYPE Function 1165
VTYPEX Function 1166
VVALUE Function 1168
VVALUEX Function 1169
WEEK Function 1170
WEEKDAY Function 1173
WHICHC Function 1174
WHICHN Function 1175
YEAR Function 1176
YIELDP Function 1177
YRDIF Function 1179
YYQ Function 1180
ZIPCITY Function 1181
ZIPCITYDISTANCE Function 1183
ZIPFIPS Function 1184
ZIPNAME Function 1186
ZIPNAMEL Function 1187
ZIPSTATE Function 1189
Functions and CALL Routines Documented in Other SAS Publications 1191
SAS Companion for Windows 1191
SAS Companion for OpenVMS on HP Integrity SErvers 1192
SAS Companion for z/OS 1193
SAS Data Quality Server: Reference 1193
SAS Logging Facility: Configuration and Programming Reference
1194
SAS Macro Language: Reference 1195
SAS National Language Support (NLS): Reference Guide 1196
References 1197
Functions and CALL Routines
4
Syntax of Functions
297
Definitions of Functions and CALL Routines
Definition of Functions
A SAS function performs a computation or system manipulation on arguments, and
returns a value that can be used in an assignment statement or elsewhere in
expressions.
In Base SAS software, you can use SAS functions in DATA step programming
statements, in a WHERE expression, in macro language statements, in PROC
REPORT, and in Structured Query Language (SQL).
Some statistical procedures also use SAS functions. In addition, some other SAS
software products offer functions that you can use in the DATA step. Refer to the
documentation that pertains to the specific SAS software product for additional
information about these functions.
Definition of CALL Routines
A CALL routine alters variable values or performs other system functions. CALL
routines are similar to functions, but differ from functions in that you cannot use them
in assignment statements or expressions.
All SAS CALL routines are invoked with CALL statements. That is, the name of the
routine must appear after the keyword CALL in the CALL statement.
Syntax
Syntax of Functions
The syntax of a function has one of the following forms:
function-name (argument-1< , …argument-n>)
function-name (OF variable-list)
function-name (<argument | OF variable-list | OF array-name[*]><…, <argument |
OF variable-list | OF array-name[*]>>)
where
function-name
names the function.
argument
can be a variable name, constant, or any SAS expression, including another
function. The number and type of arguments that SAS allows are described with
individual functions. Multiple arguments are separated by a comma.
Tip: If the value of an argument is invalid (for example, missing or outside the
prescribed range), SAS writes a note to the log indicating that the argument is
invalid, sets _ERROR_ to 1, and sets the result to a missing value.
Examples:
3
x=max(cash,credit);
298
Syntax of CALL Routines
4
Chapter 4
3
x=sqrt(1500);
3
NewCity=left(upcase(City));
3
x=min(YearTemperature-July,YearTemperature-Dec);
3
s=repeat(’----+’,16);
3
x=min((enroll-drop),(enroll-fail));
3
dollars=int(cash);
3
if sum(cash,credit)>1000 then
put ’Goal reached’;
variable-list
can be any form of a SAS variable list, including individual variable names. If
more than one variable list appears, separate them with a space or with a comma
and another OF.
Examples:
3
a=sum(of x
y
z);
3 The following two examples are equivalent.
3 a=sum(of x1-x10 y1-y10 z1-z10);
a=sum(of x1-x10, of y1-y10, of z1-z10);
3
z=sum(of y1-y10);
3
z=msplint(x0,5,of x1-x5,of y1-y5,-2,2);
array-name{*}
names a currently defined array. Specifying an array with an asterisk as a
subscript causes SAS to treat each element of the array as a separate argument.
The OF operator has been extended to accept temporary arrays. You can use
temporary arrays in OF lists for most SAS functions just as you can use regular
variable arrays, but there are some restrictions. For a list of these restrictions, see
“Using the OF Operator with Temporary Arrays” on page 299.
Syntax of CALL Routines
The syntax of a CALL routine has one of the following forms:
CALL routine-name (argument-1<, ...argument-n>);
CALL routine-name (OF variable-list);
CALL routine-name (argument-1 | OF variable-list-1 <, ...argument-n | OF
variable-list-n>);
where
routine-name
names a SAS CALL routine.
argument
can be a variable name, a constant, any SAS expression, an external module
name, an array reference, or a function. Multiple arguments are separated by a
comma. The number and type of arguments that are allowed are described with
individual CALL routines in the dictionary section.
Functions and CALL Routines
4
Using the OF Operator with Temporary Arrays
299
Examples:
3
call prxsubstr(prx,string,position);
3
call prxchange(’/old/new’,1+k,trim(string),result,length);
3
call set(dsid);
3
call ranbin(Seed_1,n,p,X1);
3
call label(abc{j},lab);
3
call cats(result,’abc’,123);
variable-list
can be any form of a SAS variable list, including variable names. If more than one
variable list appears, separate them with a space or with a comma and another OF.
Examples:
3
call cats(inventory, of y1-y15, of z1-z15);
3
call catt(of item17-item23 pack17-pack23);
Using Functions and CALL Routines
Restrictions Affecting Function Arguments
If the value of an argument is invalid, SAS writes a note or error message to the log
and sets the result to a missing value. Here are some common restrictions for function
arguments:
3 Some functions require that their arguments be restricted within a certain range.
For example, the argument of the LOG function must be greater than 0.
3 When a numeric argument has a missing value, many functions write a note to
the SAS log and return a missing value. Exceptions include some of the
descriptive statistics functions and financial functions.
3 For some functions, the allowed range of the arguments is platform-dependent,
such as with the EXP function.
Using the OF Operator with Temporary Arrays
You can use the OF operator with temporary arrays. This capability enables the
passing of temporary arrays to most functions whose arguments contain a varying
number of parameters. You can use temporary arrays in OF lists in some functions, just
as you can use temporary arrays in OF lists in regular variable arrays.
There are some limitations in using temporary arrays. These limitations are listed
after the example.
The following example shows how you can use temporary arrays:
data _null_;
array y[10] _temporary_ (1,2,3,4,5,6,7,8,9,10);
x = sum(of y{*});
put x=;
run;
data _null_;
array y[10] $10 _temporary_ (’1’,’2’,’3’,’4’,’5’,
’6’,’7’,’8’,’9’,’10’);
300
Characteristics of Target Variables
4
Chapter 4
x = max(of y{*});
put x=;
run;
Output 4.1
Log Output for the Example of Using Temporary Arrays
x=55
x=10
The following limitations affect temporary array OF lists:
3 cannot be used as array indices
3 can be used in functions where the number of parameters matches the number of
elements in the OF list, as with regular variable arrays
3 can be used in functions that take a varying number of parameters
3 cannot be used with the DIF, LAG, SUBSTR, LENGTH, TRIM, or MISSING
functions, nor with any of the variable information functions such as VLENGTH
Characteristics of Target Variables
Some character functions produce resulting variables, or target variables, with a
default length of 200 bytes. Numeric target variables have a default length of 8 bytes.
Character functions to which the default target variable lengths do not apply are shown
in the following table. These functions obtain the length of the return argument based
on the length of the first argument.
Table 4.1 Functions Whose Return Argument Is Based on the Length of the First
Argument
Functions
COMPBL
RIGHT
COMPRESS
STRIP
DEQUOTE
SUBSTR
INPUTC
SUBSTRN
LEFT
TRANSLATE
LOWCASE
TRIM
PUTC
TRIMN
REVERSE
UPCASE
The following list of functions shows the length of the target variable if the target
variable has not been assigned a length:
BYTE
target variable is assigned a default length of 1.
INPUT
length of the target variable is determined by the width of the
informat.
PUT
length of the target variable is determined by the width of the
format.
Functions and CALL Routines
4
Notes about Financial Functions
VTYPE
target variable is assigned a default length of 1.
VTYPEX
target variable is assigned a default length of 1.
301
Notes about Descriptive Statistic Functions
SAS provides functions that return descriptive statistics. Many of these functions
correspond to the statistics produced by the MEANS and UNIVARIATE procedures.
The computing method for each statistic is discussed in the elementary statistics
procedures section of the Base SAS Procedures Guide. SAS calculates descriptive
statistics for the nonmissing values of the arguments.
Notes about Financial Functions
SAS provides a group of functions that perform financial calculations. The functions
are grouped into the following types:
Table 4.2 Types of Financial Functions
Function Type
Functions
Description
Cashflow
CONVX, CONVXP
calculates convexity for cashflows
DUR, DURP
calculates modified duration for cashflows
PVP, YIELDP
calculates present value and
yield-to-maturity for a periodic cashflow
COMPOUND
calculates compound interest parameters
MORT
calculates amortization parameters
Internal rate of return
INTRR, IRR
calculates the internal rate of return
Net present and future
value
NETPV, NPV
calculates net present and future values
SAVING
calculates the future value of periodic
saving
DACCxx
calculates the accumulated depreciation up
to the specified period
DEPxxx
calculates depreciation for a single period
BLKSHCLPRC,
BLKSHPTPRC
calculates call prices and put prices for
European options on stocks, based on the
Black-Scholes model
BLACKCLPRC,
BLACKPTPRC
calculates call prices and put prices for
European options on futures, based on the
Black model
Parameter calculations
Depreciation
Pricing
302
Using DATA Step Functions within Macro Functions
Function Type
4
Chapter 4
Functions
Description
GARKHCLPRC,
GARKHPTPRC
calculates call prices and put prices for
European options on stocks, based on the
Garman-Kohlhagen model
MARGRCLPRC,
MARGRPTPRC
calculates call prices and put prices for
European options on stocks, based on the
Margrabe model
Using Pricing Functions
A pricing model is used to calculate a theoretical market value (price) for a financial
instrument. This value is referred to as a mark-to-market (MTM) value. Typically, a
pricing function has the following form:
price = f unction (rf 1; rf 2; rf 3; :::)
In the pricing function, rf1, rf2, and rf3 are risk factors such as interest rates or foreign
exchange rates. The specific values of the risk factors that are used to calculate the
MTM value are the base case values. The set of base case values is known as the base
case market state.
After determining the MTM value, you can perform the following tasks with the base
case values of the risk factors (rf1, rf2, and rf3):
3 Set the base case values to specific values to perform scenario analyses.
3 Set the base case values to a range of values to perform profit/loss curve analyses
and profit/loss surface analyses.
3 Automatically set the base case values to different values to calculate
sensitivities—that is, to calculate the delta and gamma values of the risk factors.
3 Perturb the base case values to create many possible market states so that many
possible future prices can be calculated, and simulation analyses can be
performed. For Monte Carlo simulation, the values of the risk factors are
generated using mathematical models and the copula methodology.
A list of pricing functions and their descriptions are included in Table 4.2 on page 301.
Using DATA Step Functions within Macro Functions
The macro functions %SYSFUNC and %QSYSFUNC can call most DATA step
functions to generate text in the macro facility. %SYSFUNC and %QSYSFUNC have
one difference: %QSYSFUNC masks special characters and mnemonics and
%SYSFUNC does not. For more information about these functions, see %QSYSFUNC
and %SYSFUNC in SAS Macro Language: Reference.
%SYSFUNC arguments are a single DATA step function and an optional format, as
shown in the following examples:
%sysfunc(date(),worddate.)
%sysfunc(attrn(&dsid,NOBS))
You cannot nest DATA step functions within %SYSFUNC. However, you can nest
%SYSFUNC functions that call DATA step functions. For example:
%sysfunc(compress(%sysfunc(getoption(sasautos)),
%str(%)%(%’)));
Functions and CALL Routines
4
Using Functions to Manipulate Files
303
All arguments in DATA step functions within %SYSFUNC must be separated by
commas. You cannot use argument lists that are preceded by the word OF.
Because %SYSFUNC is a macro function, you do not need to enclose character values
in quotation marks as you do in DATA step functions. For example, the arguments to
the OPEN function are enclosed in quotation marks when you use the function alone,
but the arguments do not require quotation marks when used within %SYSFUNC.
dsid=open("sasuser.houses","i");
dsid=open("&mydata","&mode");
%let dsid=%sysfunc(open(sasuser.houses,i));
%let dsid=%sysfunc(open(&mydata,&mode));
Using CALL Routines and the %SYSCALL Macro Statement
When the %SYSCALL macro statement invokes a CALL routine, the value of each
macro variable argument is retrieved and passed unresolved to the CALL routine. Upon
completion of the CALL routine, the value for each argument is written back to the
respective macro variable. If %SYSCALL encounters an error condition, the execution
of the CALL routine terminates without updating the macro variable values and an
error message is written to the log.
When %SYSCALL invokes a CALL routine, the argument value is passed unresolved
to the CALL routine. The unresolved argument value might have been quoted using
macro quoting functions and might contain delta characters. The argument value in its
quoted form can cause unpredictable results when character values are compared.
Some CALL routines unquote their arguments when they are called by %SYSCALL and
return the unquoted values. Other CALL routines do not need to unquote their
arguments. The following is a list of CALL routines that unquote their arguments
when called by %SYSCALL:
3 “CALL COMPCOST Routine” on page 434
3 “CALL LEXCOMB Routine” on page 445
3 “CALL LEXPERK Routine” on page 451
3 “CALL LEXPERM Routine” on page 455
3 “CALL PRXCHANGE Routine” on page 465
3 “CALL PRXNEXT Routine” on page 471
3 “CALL PRXSUBSTR Routine” on page 476
3 “CALL SCAN Routine” on page 500
3 “CALL SORTC Routine” on page 512
3 “CALL STDIZE Routine” on page 514
3 “CALL SYSTEM Routine” on page 521
In comparison, %SYSCALL invokes a CALL routine and returns an unresolved
value, which contains delta characters. %SYSFUNC invokes a function and returns a
resolved value, which does not contain delta characters. For more information, see
“How Macro Quoting Works”, “%SYSCALL Macro Statement”, and “%SYSFUNC Macro
Function” in SAS Macro Language: Reference.
Using Functions to Manipulate Files
SAS manipulates files in different ways, depending on whether you use functions or
statements. If you use functions such as FOPEN, FGET, and FCLOSE, you have more
opportunity to examine and manipulate your data than when you use statements such
as INFILE, INPUT, and PUT.
304
Function Compatibility with SBCS, DBCS, and MBCS Character Sets
4
Chapter 4
When you use external files, the FOPEN function allocates a buffer called the File
Data Buffer (FDB) and opens the external file for reading or updating. The FREAD
function reads a record from the external file and copies the data into the FDB. The
FGET function then moves the data to the DATA step variables. The function returns a
value that you can check with statements or other functions in the DATA step to
determine how to further process your data. After the records are processed, the
FWRITE function writes the contents of the FDB to the external file, and the FCLOSE
function closes the file.
When you use SAS data sets, the OPEN function opens the data set. The FETCH
and FETCHOBS functions read observations from an open SAS data set into the Data
Set Data Vector (DDV). The GETVARC and GETVARN functions then move the data to
DATA step variables. The functions return a value that you can check with statements
or other functions in the DATA step to determine how you want to further process your
data. After the data is processed, the CLOSE function closes the data set.
For a complete listing of functions and CALL routines, see “Functions and CALL
Routines by Category” on page 335. For complete descriptions and examples, see the
dictionary section of this book.
Function Compatibility with SBCS, DBCS, and MBCS Character Sets
Overview
SAS string functions and CALL routines can be categorized by level numbers that are
used in internationalization. I18N is the abbreviation for internationalization, and
indicates string functions that can be adapted to different languages and locales
without program changes.
I18N recognizes the following three levels that identify the character sets that you
can use:
3 “I18N Level 0” on page 304
3 “I18N Level 1” on page 304
3 “I18N Level 2” on page 305
For more information about function compatibility, see K Functions Compatibility in
the SAS National Language Support (NLS): Reference Guide.
I18N Level 0
I18N Level 0 functions are designed for use with Single Byte Character Sets (SBCS)
only.
I18N Level 1
I18N Level 1 functions should be avoided, if possible, if you are using a non-English
language. The I18N Level 1 functions might not work correctly with Double Byte
Character Set (DBCS) or Multi-Byte Character Set (MBCS) encodings under certain
circumstances.
Functions and CALL Routines
4
Understanding How Functions Generate a Random-Number Stream
305
I18N Level 2
I18N Level 2 functions are designed for use with SBCS, DBCS, and MBCS (UTF8).
Using Random-Number Functions and CALL Routines
Types of Random-Number Functions
Two types of random-number functions are available in SAS. The newest
random-number function is the RAND function. It uses the Mersenne-Twister
pseudo-random number generator (RNG) that was developed by Matsumoto and
19937
– 1, and has very good
Nishimura (1998). This RNG has a very long period of 2
statistical properties. (A period is the number of occurrences before the pseudo-random
number sequence repeats.)
The RAND function is started with a single seed. However, the state of the process
cannot be captured by a single seed, which means that you cannot stop and restart the
generator from its stopping point. Use the STREAMINIT function to produce a
sequence of values that begins at the beginning of a stream. For more information, see
the Details section of the “RAND Function” on page 1022.
The older random-number generators include the UNIFORM, NORMAL, RANUNI,
RANNOR, and other functions that begin with RAN. These functions have a period of
31
only 2 – 2 or less. The pseudo-random number stream is started with a single seed,
and the state of the process can be captured in a new seed. This means that you can
stop and restart the generator from its stopping point by providing the proper seed to
the corresponding CALL routines. You can use the random-number functions to
produce a sequence of values that begins in the middle of a stream.
Seed Values
Random-number functions and CALL routines generate streams of pseudo-random
numbers from an initial starting point, called a seed, that either the user or the
computer clock supplies. A seed must be a nonnegative integer with a value less than
31
2 –1 (or 2,147,483,647). If you use a positive seed, you can always replicate the stream
of random numbers by using the same DATA step. If you use zero as the seed, the
computer clock initializes the stream, and the stream of random numbers cannot be
replicated.
Understanding How Functions Generate a Random-Number Stream
Using the DATA Step to Generate a Single Stream of Random Numbers
The DATA steps in this section illustrate several properties of the random-number
functions. Each of the DATA steps that call a function generates a single stream of
pseudo-random numbers based on a seed value of 7, because that is the first seed for
the first call for every step. Some of the DATA steps change the seed value in various
306
Understanding How Functions Generate a Random-Number Stream
4
Chapter 4
ways. Some of the steps have single function calls and others have multiple function
calls. None of these DATA steps change the seed. The only seed that is relevant to the
function calls is the seed that was used with the first execution of the first
random-number function. There is no way to create separate streams with functions
(CALL routines are used for this purpose), and the only way you can restart the
function random-number stream is to start a new DATA step.
The following example executes multiple DATA steps:
options nodate pageno=1 linesize=80 pagesize=60;
/* This DATA step produces a single stream of random numbers */
/* based on a seed value of 7.
*/
data a;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
a = ranuni (7); output;
run;
/* This DATA step uses a DO statement to produce a single */
/* stream of random numbers based on a seed value of 7.
*/
data b (drop = i);
do i = 7 to 18;
b = ranuni (i);
output;
end;
run;
/* This DATA step uses a DO statement to produce a single */
/* stream of random numbers based on a seed value of 7.
*/
data c (drop = i);
do i = 1 to 12;
c = ranuni (7);
output;
end;
run;
/* This DATA step calls the RANUNI and the RANNOR functions */
/* and produces a single stream of random numbers based on */
/* a seed value of 7.
*/
data d;
d = ranuni (7); f = ’ ’; output;
d = ranuni (8); f = ’ ’; output;
d = rannor (9); f = ’n’; output;
d = .;
f = ’ ’; output;
d = ranuni (0); f = ’ ’; output;
d = ranuni (1); f = ’ ’; output;
Functions and CALL Routines
d
d
d
d
d
d
run;
=
=
=
=
=
=
rannor
.;
ranuni
ranuni
rannor
.;
(2); f
f
(3); f
(4); f
(5); f
f
=
=
=
=
=
=
4
’n’;
’ ’;
’ ’;
’ ’;
’n’;
’ ’;
Understanding How Functions Generate a Random-Number Stream
307
output;
output;
output;
output;
output;
output;
/* This DATA step calls the RANNOR function and produces a
*/
/* single stream of random numbers based on a seed value of 7. */
data e (drop = i);
do i = 1 to 6;
e = rannor (7); output;
e = .;
output;
end;
run;
/* This DATA step merges the output data sets that were */
/* created from the previous five DATA steps.
*/
data five;
merge a b c d e;
run;
/* This procedure writes the output from the merged data sets. */
proc print label data=five;
options missing = ’ ’;
label f = ’00’x;
title ’Single Random Number Streams’;
run;
The following output shows the program results.
Output 4.2 Results from Generating a Single Random-Number Stream
Single Random Number Streams
1
Obs
a
b
c
d
e
1
2
3
4
5
6
7
8
9
10
11
12
0.29474
0.79062
0.79877
0.81579
0.45122
0.78494
0.80085
0.72184
0.34856
0.46597
0.73523
0.66709
0.29474
0.79062
0.79877
0.81579
0.45122
0.78494
0.80085
0.72184
0.34856
0.46597
0.73523
0.66709
0.29474
0.79062
0.79877
0.81579
0.45122
0.78494
0.80085
0.72184
0.34856
0.46597
0.73523
0.66709
0.29474
0.79062
0.26928
0.39464
0.45122
0.78494
-0.11729
0.34856
0.46597
-0.39033
n
0.26928
0.27475
n
-0.11729
-1.41879
n
-0.39033
The pseudo-random number streams in output data sets A, B, and C are identical.
The stream in output data set D mixes calls to the RANUNI and the RANNOR
functions. In observations 1, 2, 5, 6, 9, and 10, the values that are returned by
RANUNI exactly match the values in the previous streams. Observations 3, 7, and 11,
which are flagged by “n”, contain the values that are returned by the RANNOR
function. The mix of the function calls does not affect the generation of the
308
Understanding How Functions Generate a Random-Number Stream
4
Chapter 4
pseudo-random number stream. All of the results are based on a single stream of
uniformly distributed values, some of which are transformed and returned from other
functions such as RANNOR. The results of the RANNOR function are produced from
two internal calls to RANUNI. The DATA step that creates output data set D executes
the following steps three times to create 12 observations:
3
3
3
3
call to RANUNI
call to RANUNI
call to RANNOR (which internally calls RANUNI twice)
skipped line to compensate for the second internal call to RANUNI
In the DATA step that creates data set E, RANNOR is called six times, each time
skipping a line to compensate for the fact that two internal calls to RANUNI are made
for each call to RANNOR. Notice that the three values that are returned from RANNOR
in the DATA step that creates data set D match the corresponding values in data set E.
Using the %SYSFUNC Macro to Generate a Single Stream of Random
Numbers
When the RANUNI function is called through the macro language by using
%SYSFUNC, one pseudo-random number stream is created. You cannot change the
seed value unless you close SAS and start a new SAS session. The %SYSFUNC macro
produces the same pseudo-random number stream as the DATA steps that generated
the data sets A, B, and C for the first macro invocation only. Any subsequent macro
calls produce a continuation of the single stream.
%macro ran;
%do i = 1 %to 12;
%let x = %sysfunc (ranuni (7));
%put &x;
%end;
%mend;
%ran;
SAS writes the following output to the log:
Output 4.3
Results of Execution with the %SYSFUNC Macro
10
%macro ran;
11
%do i = 1 %to 12;
12
%let x = %sysfunc (ranuni (7));
13
%put &x;
14
%end;
15
%mend;
16
%ran;
0.29473798875451
0.79062100955779
0.79877014262544
0.81579051763554
0.45121804506109
0.78494144826426
0.80085421204606
0.72184205973606
0.34855818345609
0.46596586120592
0.73522999404707
0.66709365028287
Functions and CALL Routines
4
Generating Multiple Streams from Multiple Seeds in Random-Number CALL Routines
309
Comparison of Seed Values in Random-Number Functions and CALL
Routines
Each random-number function and CALL routine generates pseudo-random numbers
from a specific statistical distribution. Each random-number function requires a seed
value expressed as an integer constant or a variable that contains the integer constant.
Each CALL routine calls a variable that contains the seed value. Additionally, every
CALL routine requires a variable that contains the generated pseudo-random numbers.
The seed variable must be initialized before the first execution of the function or
CALL routine. After each execution of a function, the current seed is updated internally,
but the value of the seed argument remains unchanged. However, after each iteration
of the CALL routine the seed variable contains the current seed in the stream that
generates the next pseudo-random number. With a function, it is not possible to control
the seed values, and, therefore, the pseudo-random numbers after the initialization.
Except for the NORMAL and UNIFORM functions, which are equivalent to the
RANNOR and RANUNI functions, respectively, SAS provides a CALL routine that has
the same name as each random-number function. Using CALL routines gives you
greater control over the seed values.
Generating Multiple Streams from Multiple Seeds in Random-Number
CALL Routines
Overview of Random-Number CALL Routines and Streams
You can use the random-number CALL routines to generate multiple streams of
pseudo-random numbers within a single DATA step. If you supply a different seed
value to initialize each of the seed variables, the streams of the generated
pseudo-random numbers are computationally independent, but they might not be
statistically independent unless you select the seed values carefully.
Note: Although you can create multiple streams with multiple seeds, this practice is
not recommended. It is always safer to create a single stream. With multiple streams,
as the streams become longer, the chances of the stream overlapping increase. 4
The following two examples deliberately select seeds to illustrate worst-case scenarios.
The examples show how to produce multiple streams by using multiple seeds. Although
this practice is not recommended, you can use the random-number CALL routines with
multiple seeds.
Example 1: Using Multiple Seeds to Generate Multiple Streams
This example shows that you can use multiple seeds to generate multiple streams of
pseudo-randomly distributed values by using the random-number CALL routines. The
first DATA step creates a data set with three variables that are normally distributed.
The second DATA step creates variables that are uniformly distributed. The
SGSCATTER procedure (see the SAS/GRAPH: Statistical Graphics Procedures Guide)
is used to show the relationship between each pair of variables for each of the two
distributions.
options pageno = 1 nodate ls = 80 ps = 64;
data normal;
310
Generating Multiple Streams from Multiple Seeds in Random-Number CALL Routines
4
Chapter 4
seed1 = 11111;
seed2 = 22222;
seed3 = 33333;
do i = 1 to 10000;
call rannor(seed1, x1);
call rannor(seed2, x2);
call rannor(seed3, x3);
output;
end;
run;
data uniform;
seed1 = 11111;
seed2 = 22222;
seed3 = 33333;
do i = 1 to 10000;
call ranuni(seed1, x1);
call ranuni(seed2, x2);
call ranuni(seed3, x3);
output;
end;
run;
proc sgscatter data = normal;
title ’Nonindependent Random Normal Variables’;
plot x1*x2 x1*x3 x3*x2 / markerattrs = (size = 1);
run;
proc sgscatter data = uniform;
title ’Nonindependent Random Uniform Variables’;
plot x1*x2 x1*x3 x3*x2 / markerattrs = (size = 1);
run;
Functions and CALL Routines
4
Generating Multiple Streams from Multiple Seeds in Random-Number CALL Routines
311
Display 4.1 Multiple Streams from Multiple Seeds: Nonindependent Random Normal Variables
Display 4.2 Multiple Streams from Multiple Seeds: Nonindependent Random Uniform Variables
The first plot (Display 4.1 on page 311) shows that normal variables appear to be
linearly uncorrelated, but they are obviously not independent. The second plot (Display
4.2 on page 311) shows that uniform variables are clearly related. With this class of
random-number generators, there is never any guarantee that the streams will be
independent.
312
Generating Multiple Streams from Multiple Seeds in Random-Number CALL Routines
4
Chapter 4
Example 2: Using Different Seeds with the CALL RANUNI Routine
The following example uses three different seeds and the CALL RANUNI routine to
produce multiple streams.
data uniform(drop=i);
seed1 = 255793849;
seed2 =1408147117;
seed3 = 961782675;
do i=1 to 10000;
call ranuni(seed1, x1);
call ranuni(seed2, x2);
call ranuni(seed3, x3);
i2 = lag(x2);
i3 = lag2(x3);
output;
end;
label i2=’Lag(x2)’ i3=’Lag2(x3)’;
run;
title ’Random Uniform Variables with Overlapping Streams’;
proc sgscatter data=uniform;
plot x1*x2 x1*x3 x3*x2 / markerattrs = (size = 1);
run;
proc sgscatter data=uniform;
plot i2*x1 i3*x1 / markerattrs = (size = 1);
run;
proc print noobs data=uniform(obs=10);
run;
Display 4.3 Using Different Seeds with CALL RANUNI: Random Uniform Variables with Overlapping Streams,
Plot 1
Functions and CALL Routines
4
Generating Multiple Streams from Multiple Seeds in Random-Number CALL Routines
313
Display 4.4 Using Different Seeds with CALL RANUNI: Random Uniform Variables with Overlapping Streams,
Plot 2
Output 4.4 Random Uniform Variables with Overlapping Streams
Random Uniform Variables with Overlapping Streams
seed1
1408147117
961782675
383001085
1989090982
1375749095
89319994
1345897251
561406336
1333490358
963442111
seed2
961782675
383001085
1989090982
1375749095
89319994
1345897251
561406336
1333490358
963442111
1557707418
seed3
383001085
1989090982
1375749095
89319994
1345897251
561406336
1333490358
963442111
1557707418
137842443
x1
0.65572
0.44786
0.17835
0.92624
0.64063
0.04159
0.62673
0.26143
0.62095
0.44864
x2
x3
0.44786
0.17835
0.92624
0.64063
0.04159
0.62673
0.26143
0.62095
0.44864
0.72536
0.17835
0.92624
0.64063
0.04159
0.62673
0.26143
0.62095
0.44864
0.72536
0.06419
2
i2
.
0.44786
0.17835
0.92624
0.64063
0.04159
0.62673
0.26143
0.62095
0.44864
i3
.
.
0.17835
0.92624
0.64063
0.04159
0.62673
0.26143
0.62095
0.44864
The first plot (Display 4.3 on page 312) shows expected results: the variables appear
to be statistically independent. However, the second plot (Display 4.4 on page 313) and
the listing of the first 10 observations show that there is almost complete overlap
between the two streams. The last 9999 values in x1 match the first 9999 values in x2,
and the last 9998 values in x1 match the first 9998 values in x3. In other words, there
is perfect agreement between the non-missing parts of x1 and lag(x2) and also x1 and
lag2(x3). Even if the streams appear to be independent at first glance as in the first
plot, there might be overlap, which might be undesirable depending on how the streams
are used.
In practice, if you make multiple small streams with separate and randomly selected
seeds, you probably will not encounter the problems that are shown in the first two
314
Generating Multiple Variables from One Seed in Random-Number Functions
4
Chapter 4
examples. “Example 2: Using Different Seeds with the CALL RANUNI Routine” on
page 312 deliberately selects seeds to illustrate worst-case scenarios.
It is always safer to create a single stream. With multiple streams, as the streams
get longer, the chances of the streams overlapping increase.
Generating Multiple Variables from One Seed in Random-Number
Functions
Overview of Functions and Streams
If you use functions in your program, you cannot generate more than one stream of
pseudo-random numbers by supplying multiple seeds within a DATA step.
The following example uses the RANUNI function to show the safest way to create
multiple variables from the same stream with a single seed.
Example: Generating Random Uniform Variables with Overlapping Streams
In the following example, the RANUNI function is used to create random uniform
variables with overlapping streams. The example shows the safest way to create
multiple variables by using the RANUNI function. All variables are created from the
same stream with a single seed.
options pageno=1 nodate ls=80 ps=64;
data uniform(drop=i);
do i = 1 to 10000;
x1 = ranuni(11111);
x2 = ranuni(11111);
x3 = ranuni(11111);
i2 = lag(x2);
i3 = lag2(x3);
output;
end;
label i2 = ’Lag(x2)’ i3 = ’Lag2(x3)’;
run;
title ’Random Uniform Variables with Overlapping Streams’;
proc sgscatter data = uniform;
plot x1*x2 x1*x3 x3*x2 / markerattrs = (size = 1);
run;
proc sgscatter data = uniform;
plot i2*x1 i3*x1 / markerattrs = (size = 1);
run;
Functions and CALL Routines
4
Generating Multiple Variables from One Seed in Random-Number Functions
315
Display 4.5 Random Uniform Variables with Overlapping Streams: Plot 1
Display 4.6 Random Uniform Variables with Overlapping Streams: Plot 2
In “Example: Generating Random Uniform Variables with Overlapping Streams” on
page 314, it appears that the variables are independent. However, even this
programming approach might not work well in general. The random-number functions
31
and CALL routines have a period of only 2 - 2 or less (approximately 2.1 billion).
When this limit is reached, the stream repeats. Modern computers performing
complicated simulations can easily exhaust the entire stream in minutes.
316
Using the RAND Function as an Alternative
4
Chapter 4
Using the RAND Function as an Alternative
A better approach to generating random uniform variables is to use the RAND
function, where multiple streams are not permitted. The RAND function has a period of
19937
- 1. This limit will never be reached, at least with computers of the early 21st
2
19937
6000
century. The number 2
- 1 is approximately 10 (1 followed by 6000 zeros). In
comparison, the largest value that can be represented in eight bytes on most computers
307
that run SAS is approximately 10 .
The RAND function, which is the latest random-number function that was designed,
does not allow multiple streams. The RAND function uses a different algorithm from
the random-number CALL routines, which allow you to create multiple streams with
multiple seeds. Because the state of the RAND process cannot be captured by a single
seed, you cannot stop and restart the generator from its stopping point. Therefore, the
RAND function allows only a single stream of numbers, but it can be used to make
multiple streams, just as the RANUNI function can.
Effectively Using the Random-Number CALL Routines
Starting, Stopping, and Restarting a Stream
A reasonable use of the random-number CALL routines is starting and stopping a
single stream, provided the stream never exhausts the RANUNI stream. For example,
you might want SAS to perform iterations, stop, evaluate the results, and then restart
the stream at the point it stopped. The following example illustrates this principle.
Example: Starting, Stopping, and Restarting a Stream
This example generates a stream of five numbers, stops, restarts, generates five more
numbers from the same stream, combines the results, and generates the full stream for
comparison. In the first DATA step, the state of the random-number seed is stored in a
macro variable seed for use as the starting seed in the next step. The separate streams
in the example output match the full stream.
options pageno=1 nodate ls=80 ps=64;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call ranuni(seed, x);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call ranuni(seed, x);
output;
end;
run;
Functions and CALL Routines
4
Comparison of Changing the Seed in a CALL Routine and in a Function
317
data all;
set u1 u2;
z = ranuni(104);
run;
proc print label;
title ’Random Uniform Variables with Overlapping Streams’;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.5 Starting, Stopping, and Restarting a Stream
Random Uniform Variables with Overlapping Streams
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
0.23611
0.88923
0.58173
0.97746
0.84667
0.80484
0.46983
0.29594
0.17858
0.92292
0.23611
0.88923
0.58173
0.97746
0.84667
0.80484
0.46983
0.29594
0.17858
0.92292
1
Comparison of Changing the Seed in a CALL Routine and in a Function
Example: Changing Seeds in a CALL Routine and in a Function
If you use a CALL routine to change the seed, the results are different from using a
function to change the seed. The following example shows the difference.
data seeds;
retain Seed1 Seed2 Seed3 104;
do i = 1 to 10;
call ranuni(Seed1,X1);
call ranuni(Seed2,X2);
X3 = ranuni(Seed3);
if i = 5 then do;
Seed2 = 17;
Seed3 = 17;
end;
output;
end;
run;
proc print data = seeds;
title ’Random Uniform Variables with Overlapping Streams’;
id i;
run;
318
Date and Time Intervals
Output 4.6
4
Chapter 4
Changing Seeds in a CALL Routine and in a Function
Random Uniform Variables with Overlapping Streams
i
1
2
3
4
5
6
7
8
9
10
Seed1
507036483
1909599212
1249251009
2099077474
1818205895
1728390132
1008960848
635524535
383494893
1981958542
Seed2
507036483
1909599212
1249251009
2099077474
17
310018657
1055505749
1711572821
879989345
1432895200
Seed3
X1
104
104
104
104
17
17
17
17
17
17
0.23611
0.88923
0.58173
0.97746
0.84667
0.80484
0.46983
0.29594
0.17858
0.92292
X2
0.23611
0.88923
0.58173
0.97746
0.84667
0.14436
0.49151
0.79701
0.40978
0.66724
3
X3
0.23611
0.88923
0.58173
0.97746
0.84667
0.80484
0.46983
0.29594
0.17858
0.92292
Changing Seed2 in the CALL RANUNI statement when i=5, forces the stream for X2
to deviate from the stream for X1. However, changing Seed3 in the RANUNI function
has no effect. The X3 stream continues on as if nothing has changed, and the X1 and
X3 streams are the same.
Date and Time Intervals
Definition of a Date and Time Interval
An interval is a unit of measurement that SAS counts within an elapsed period of
time, such as days, months or hours. SAS determines date and time intervals based on
fixed points on the calendar or clock. The starting point of an interval calculation
defaults to the beginning of the period in which the beginning value falls, which might
not be the actual beginning value that is specified. For example, if you are using the
INTCK function to count the months between two dates, regardless of the actual day of
the month that is specified by the date in the beginning value, SAS treats the beginning
value as the first day of that month.
Interval Names and SAS Dates
Specific interval names are used with SAS date values, while other interval names
are used with SAS time and datetime values. The interval names that are used with
SAS date values are YEAR, SEMIYEAR, QTR, MONTH, SEMIMONTH, TENDAY,
WEEK, WEEKDAY, and DAY. The interval names that are used with SAS time and
datetime values are HOUR, MINUTE, and SECOND.
Interval names that are used with SAS date values can be prefixed with ’DT’ to
construct interval names for use with SAS datetime values. The interval names
DTYEAR, DTSEMIYEAR, DTQTR, DTMONTH, DTSEMIMONTH, DTTENDAY,
DTWEEK, DTWEEKDAY, and DTDAY are used with SAS time or datetime values.
Functions and CALL Routines
4
Commonly Used Time Intervals
319
Incrementing Dates and Times by Using Multipliers and by Shifting
Intervals
SAS provides date, time, and datetime intervals for counting different periods of
elapsed time. By using multipliers and shift indexes, you can create multiples of
intervals and shift their starting point to construct more complex interval specifications.
The general form of an interval name is
name<multiplier><.shift-index>
Both the multiplier and the shift–index arguments are optional and default to 1. For
example, YEAR, YEAR1, YEAR.1, and YEAR1.1 are all equivalent ways of specifying
ordinary calendar years that begin in January. If you specify other values for multiplier
and for shift-index, you can create multiple intervals that begin in different parts of the
year. For example, the interval WEEK6.11 specifies six-week intervals starting on
second Wednesdays.
For more information, see “Single-unit Intervals”, “Multi-unit Intervals”, and
“Shifted Intervals” in SAS Language Reference: Concepts.
Commonly Used Time Intervals
Time intervals that do not nest within years or days are aligned relative to the SAS
date or datetime value 0. SAS uses the arbitrary reference time of midnight on January
1, 1960, as the origin for non-shifted intervals. Shifted intervals are defined relative to
January 1, 1960.
For example, MONTH13 defines the intervals January 1, 1960, February 1, 1961,
March 1, 1962, and so on, and the intervals December 1, 1958, November 1, 1957, and
so on, before the base date January 1, 1960.
As another example, the interval specification WEEK6.13 defines six-week periods
starting on second Fridays. The convention of alignment relative to the period that
contains January 1, 1960, determines where to start counting to determine which dates
correspond to the second Fridays of six-week intervals.
The following table lists time intervals that are commonly used.
Table 4.3 Commonly Used Intervals with Optional Multiplier and Shift Indexes
Interval
Description
DAY3
Three-day intervals
WEEK
Weekly intervals starting on Sundays
WEEK.7
Weekly intervals starting on Saturdays
WEEK6.13
Six-week intervals starting on second Fridays
WEEK2
Biweekly intervals starting on first Sundays
WEEK1.1
Same as WEEK
WEEK.2
Weekly intervals starting on Mondays
WEEK6.3
Six-week intervals starting on first Tuesdays
WEEK6.11
Six-week intervals starting on second Wednesdays
WEEK4
Four-week intervals starting on first Sundays
WEEKDAY
Five-day work week with a Saturday-Sunday weekend
320
Retail Calendar Intervals: ISO 8601 Compliant
4
Chapter 4
Interval
Description
WEEKDAY1W
Six-day week with Sunday as a weekend day
WEEKDAY35W
Five-day week with Tuesday and Thursday as weekend days
(W indicates that day 3 and day 5 are weekend days)
WEEKDAY17W
Same as WEEKDAY
WEEKDAY67W
Five-day week with Friday and Saturday as weekend days
WEEKDAY3.2
Three-weekday intervals with Saturday and Sunday as
weekend days (The intervals are aligned with respect to Jan. 1,
1960. For intervals that nest within a year, it is not necessary
to go back to Jan. 1, 1960 to determine the alignment.)
TENDAY4.2
Four ten-day periods starting at the second TENDAY period
SEMIMONTH2.2
Intervals from the sixteenth of one month through the fifteenth
of the next month
MONTH2.2
February–March, April–May, June–July, August–September,
October–November, and December–January of the following
year
MONTH2
January–February, March–April, May–June, July–August,
September–October, November–December
QTR3.2
Nine-month intervals starting on February 1, 1960, November
1, 1960, August 1, 1961, May 1, 1962, and so on.
SEMIYEAR.3
Six-month intervals, March–August and September–February
YEAR.10
Fiscal years starting in October
YEAR2.7
Biennial intervals starting in July of even years
YEAR2.19
Biennial intervals starting in July of odd years
YEAR4.11
Four-year intervals starting in November of leap years (frequency
of U.S. presidential elections)
YEAR4.35
Four-year intervals starting in November of even years between
leap years (frequency of U.S. midterm elections)
DTMONTH13
Thirteen-month intervals starting at midnight of January 1,
1960, such as November 1, 1957, December 1, 1958, January 1,
1960, February 1, 1961, and March 1, 1962
HOUR8.7
Eight-hour intervals starting at 6 a.m., 2 p.m., and 10 p.m.
(might be used for work shifts)
For a complete list of the valid values for interval, see the “Intervals Used with Date
and Time Functions” table in SAS Language Reference: Concepts.
Retail Calendar Intervals: ISO 8601 Compliant
The retail industry often accounts for its data by dividing the yearly calendar into four
13-week periods, based on one of the following formats: 4-4-5, 4-5-4, or 5-4-4. The first,
second, and third numbers specify the number of weeks in the first, second, and third
months of each period, respectively.
Functions and CALL Routines
4
Best Practices for Custom Interval Names
321
The intervals that are created from the formats can be used in any of the following
functions: INTCINDEX, INTCK, INTCYCLE, INTFIT, INTFMT, INTGET, INTINDEX,
INTNX, INTSEAS, INTSHIFT, and INTTEST.
For more information, see “Retail Calendar Intervals: ISO 8601 Compliant” in SAS
Language Reference: Concepts.
Best Practices for Custom Interval Names
The following items list best practices to use when you are creating custom interval
names:
3 Custom interval names should not conflict with existing SAS interval names. For
example, if BASE is a SAS interval name, do not use the following formats for the
name of a custom interval:
BASE
BASEm
BASEm.n
DTBASE
DTBASEm
DTBASEm.n
where
m
specifies an optional multiplier that sets the interval equal to a multiple of
the period of the basic interval type. For example, the interval YEAR2
consists of two-year, or biennial, periods.
n
specifies an optional shift index that shifts the interval to start at a specified
subperiod starting point. For example, YEAR.3 specifies yearly periods that
are shifted to start on the first day of March of each calendar year and end in
February of the following year.
If you define a custom interval such as CUSTBASE, then you can use
CUSTBASEm.n.
Because of these rules, do not begin a custom interval name with DT, and do
not end the custom interval name with a number.
3 To ensure that custom intervals work reliably, always include one of the following
formats:
date-format with beginning and ending values
specifies intervals that are used with SAS date values.
datetime-format with beginning and ending values
specifies intervals that are used with SAS datetime values.
number-format with beginning and ending values
specifies intervals that are used with SAS observation numbers.
3 Beginning and ending values should be of the same type. Both values should be
date values, datetime values, or observation numbers.
3 Calculations for custom intervals cannot be performed before the first begin value
or after the last end value. If you use the begin variable only, then the last end
value you can calculate is the last begin value –1. If you forecast or backcast the
time series, be sure to include time definitions for the forecast and backcast values.
322
Best Practices for Custom Interval Names
4
Chapter 4
3
CUSTBASEm.2 is never able to calculate a beginning period for the first date
value in a data set because, by definition, the beginning of the first interval starts
before the data set begins (at the – (m– 2) th observation). For example, you might
have an interval called CUSTBASE4.2 with the first interval beginning before the
first observation:
OBS
-2
-1
0
1
Start of partial CUSTBASE4.2 interval observation:
-(4-2) = -2.
End of partial CUSTBASE4.2 interval observation: This is the first
observation in the data set.
Start of first complete CUSTBASE4.2 interval.
2
3
4
5
6
End of first complete CUSTBASE4.2 interval.
Start of 2nd CUSTBASE4.2 interval.
If you execute the INTNX function, the result must return the date that is
associated with OBS –2, which does not exist:
INTNX(’CUSTBASE4.2’, date-at-obs1, 0, ’B’);
3 Include a variable named season in the custom interval data set to define the
seasonal index. This result is similar to the result of INTINDEX (’interval’,
date);
In the following example, the data set is associated with the custom interval
CUSTWEEK:
Obs
begin
1
2
3
4
5
6
27DEC59
03JAN60
10JAN60
17JAN60
24JAN60
31JAN60
season
52
1
2
3
4
5
The following examples show the results of using custom interval functions:
INTINDEX (’CUSTWEEK’, ’03JAN60’D);
returns a value of 1.
INTSEAS (’CUSTWEEK’);
returns a value of 52, which is the largest value of the season.
INTCYCLE (’CUSTWEEK’);
returns CUSTWEEK52, which is CUSTBASEmax(season).
INTCINDEX (’CUSTWEEK’, ’27DEC59’D);
returns a value of 1.
INTCINDEX(’CUSTWEEK’, ’03JAN60’D)
returns a value of 2.
A new cycle begins when the season is less than the previous value of season.
3 Seasonality occurs when seasons are identified, such as season1, season2, season3,
and so forth. If all seasons are identified as season1, then there is no seasonality.
No seasonality is also called trivial seasonality.
Only trivial seasonality is available for intervals of the form CUSTBASEm. If
season is not included in the data set, then trivial seasonality is valid.
Functions and CALL Routines
4
Benefits of Using Perl Regular Expressions in the DATA Step
323
3 If a format for the begin variable is included in a data set, then a message
generated by INTFMT (’CUSTBASE’, ’l’) or INTFMT (’CUSTBASE’, ’s’) appears.
The message recommends a format based on the format that is specified in the
data set.
3 Executing INTSHIFT (’CUSTBASE’); or INTSHIFT (’CUSTBASEm.s’); returns
the value of CUSTBASE.
3 With INTNX, INTCK, and INTTEST, the intervals CUSTBASE, CUSTBASEm,
and CUSTBASEm.s work as expected.
Pattern Matching Using Perl Regular Expressions (PRX)
Definition of Pattern Matching
Pattern matching enables you to search for and extract multiple matching patterns
from a character string in one step. Pattern matching also enables you to make several
substitutions in a string in one step. You do this by using the PRX functions and CALL
routines in the DATA step.
For example, you can search for multiple occurrences of a string and replace those
strings with another string. You can search for a string in your source file and return
the position of the match. You can find words in your file that are doubled.
Definition of Perl Regular Expression (PRX) Functions and CALL
Routines
Perl regular expression (PRX) functions and CALL routines refers to a group of
functions and CALL routines that use a modified version of Perl as a pattern-matching
language to parse character strings. You can do the following:
3 search for a pattern of characters within a string
3 extract a substring from a string
3 search and replace text with other text
3 parse large amounts of text, such as Web logs or other text data
Perl regular expressions comprise the character string matching category for
functions and CALL routines. For a short description of these functions and CALL
routines, see the “Functions and CALL Routines by Category” on page 335.
Benefits of Using Perl Regular Expressions in the DATA Step
Using Perl regular expressions in the DATA step enhances search-and-replace
options in text. You can use Perl regular expressions to perform the following tasks:
3 validate data
3 replace text
3 extract a substring from a string
You can write SAS programs that do not use regular expressions to produce the same
results as you do when you use Perl regular expressions. However, the code without the
324
Using Perl Regular Expressions in the DATA Step
4
Chapter 4
regular expressions requires more function calls to handle character positions in a
string and to manipulate parts of the string.
Perl regular expressions combine most, if not all, of these steps into one expression.
The resulting code is less prone to error, easier to maintain, and clearer to read.
Using Perl Regular Expressions in the DATA Step
Syntax of Perl Regular Expressions
The Components of a Perl Regular Expression
Perl regular expressions consist of characters and special characters that are called
metacharacters. When performing a match, SAS searches a source string for a
substring that matches the Perl regular expression that you specify. Using
metacharacters enables SAS to perform special actions. These actions include forcing
the match to begin in a particular location, and matching a particular set of characters.
Paired forward slashes are the default delimiters. The following two examples show
metacharacters and the values they match:
3 If you use the metacharacter \d, SAS matches a digit between 0–9.
3 If you use /\dt/, SAS finds the digits in the string “Raleigh, NC 27506”.
You can see lists of PRX metacharacters in “Tables of Perl Regular Expression (PRX)
Metacharacters” on page 2135.
Basic Syntax for Finding a Match in a String
You use the PRXMATCH function to find the position of a matched value in a source
string. PRXMATCH has the following general form:
/search-string/source-string/
The following example uses the PRXMATCH function to find the position of
search-string in source-string:
prxmatch(’world’, ’Hello world!’);
The result of PRXMATCH is the value 7, because world occurs in the seventh
position of the string Hello world!.
Basic Syntax for Searching and Replacing Text: Example 1
The basic syntax for searching and replacing text has the following form:
s/regular-expression/replacement-string/
The following example uses the PRXCHANGE function to show how substitution is
performed:
prxchange(’s/world/planet/’, 1, ’Hello world!’);
where
s
specifies the metacharacter for substitution.
Functions and CALL Routines
4
Syntax of Perl Regular Expressions
world
specifies the regular expression.
planet
specifies the replacement value for world.
1
specifies that the search ends when one match is found.
Hello world!
specifies the source string to be searched.
325
The result of the substitution is Hello planet.
Basic Syntax for Searching and Replacing Text: Example 2
Another example of using the PRXCHANGE function changes the value Jones, Fred
to Fred Jones:
prxchange(’s/(\w+), (\w+)/$2 $1’,-1, ’Jones, Fred’);
In this example, the Perl regular expression is s/(\w+), (\w+)/$2 $1. The number
of times to search for a match is –1. The source string is ’Jones, Fred’. The value –1
specifies that matching patterns continue to be replaced until the end of the source is
reached.
The Perl regular expression can be divided into its elements:
s
specifies a substitution regular expression.
(\w+)
matches one or more word characters (alphanumeric and
underscore). The parentheses indicate that the value is stored in
capture buffer 1.
,<space>
matches a comma and a space.
(\w+)
matches one or more word characters (alphanumeric and
underscore). The parentheses indicate that the value is stored in
capture buffer 2.
/
separator between the regular expression and the replacement
string.
$2
part of the replacement string that substitutes the value in capture
buffer 2, which in this case is the word after the comma, puts the
substitution in the results.
<space>
puts a space in the result.
$1
puts capture buffer 1 into the result. In this case, it is the word
before the comma.
Replacing Text: Example 3
The following example uses the \u and \L metacharacters to replace the second
character in MCLAUREN with a lower case letter:
data _null_;
x = ’MCLAUREN’;
x = prxchange("s/ (MC) /\u\L$1/i", -1, x);
put x=;
run;
326
Example 1: Validating Data
4
Chapter 4
SAS writes the following output to the log:
x=McLAUREN
Example 1: Validating Data
You can test for a pattern of characters within a string. For example, you can
examine a string to determine whether it contains a correctly formatted telephone
number. This type of test is called data validation.
The following example validates a list of phone numbers. To be valid, a phone
number must have one of the following forms: (XXX) XXX-XXXX or XXX-XXX-XXXX.
data _null_; u
if _N_ = 1 then
do;
paren = "\([2-9]\d\d\) ?[2-9]\d\d-\d\d\d\d"; v
dash = "[2-9]\d\d-[2-9]\d\d-\d\d\d\d"; w
expression = "/(" || paren || ")|(" || dash || ")/"; x
retain re;
re = prxparse(expression); y
if missing(re) then U
do;
putlog "ERROR: Invalid expression " expression; V
stop;
end;
end;
length first last home business $ 16;
input first last home business;
if ^prxmatch(re, home) then W
putlog "NOTE: Invalid home phone number for " first last home;
if ^prxmatch(re, business) then X
putlog "NOTE: Invalid business phone number for " first last business;
datalines;
Jerome Johnson (919)319-1677 (919)846-2198
Romeo Montague 800-899-2164 360-973-6201
Imani Rashid (508)852-2146 (508)366-9821
Palinor Kent . 919-782-3199
Ruby Archuleta . .
Takei Ito 7042982145 .
Tom Joad 209/963/2764 2099-66-8474
;
run;
The following items correspond to the lines that are numbered in the DATA step that
is shown above.
u Create a DATA step.
v Build a Perl regular expression to identify a phone number that matches
(XXX)XXX-XXXX, and assign the variable PAREN to hold the result. Use the
following syntax elements to build the Perl regular expression:
Functions and CALL Routines
4
Example 1: Validating Data
327
\(
matches the open parenthesis in the area code.
[2–9]
matches the digits 2–9, which is the first number in the area
code.
\d
matches a digit, which is the second number in the area code.
\d
matches a digit, which is the third number in the area code.
\)
matches the closed parenthesis in the area code.
<space>?
matches the space (which is the preceding subexpression) zero
or one time. Spaces are significant in Perl regular expressions.
They match a space in the text that you are searching. If a
space precedes the question mark metacharacter (as it does in
this case), the pattern matches either zero spaces or one space
in this position in the phone number.
w Build a Perl regular expression to identify a phone number that matches
XXX-XXX-XXXX, and assign the variable DASH to hold the result.
x Build a Perl regular expression that concatenates the regular expressions for
(XXX)XXX-XXXX and XXX—XXX—XXXX. The concatenation enables you to
search for both phone number formats from one regular expression.
The PAREN and DASH regular expressions are placed within parentheses. The
bar metacharacter (|) that is located between PAREN and DASH instructs the
compiler to match either pattern. The slashes around the entire pattern tell the
compiler where the start and end of the regular expression is located.
y Pass the Perl regular expression to PRXPARSE and compile the expression.
PRXPARSE returns a value to the compiled pattern. Using the value with other
Perl regular expression functions and CALL routines enables SAS to perform
operations with the compiled Perl regular expression.
U Use the MISSING function to check whether the regular expression was
successfully compiled.
V Use the PUTLOG statement to write an error message to the SAS log if the
regular expression did not compile.
W Search for a valid home phone number. PRXMATCH uses the value from
PRXPARSE along with the search text and returns the position where the regular
expression was found in the search text. If there is no match for the home phone
number, the PUTLOG statement writes a note to the SAS log.
X Search for a valid business phone number. PRXMATCH uses the value from
PRXPARSE along with the search text and returns the position where the regular
expression was found in the search text. If there is no match for the business
phone number, the PUTLOG statement writes a note to the SAS log.
Output 4.7 Output from Validating Data
NOTE:
NOTE:
NOTE:
NOTE:
NOTE:
NOTE:
NOTE:
Invalid
Invalid
Invalid
Invalid
Invalid
Invalid
Invalid
home phone number for
home phone number for
business phone number
home phone number for
business phone number
home phone number for
business phone number
Palinor Kent
Ruby Archuleta
for Ruby Archuleta
Takei Ito 7042982145
for Takei Ito
Tom Joad 209/963/2764
for Tom Joad 2099-66-8474
328
Example 2: Replacing Text
4
Chapter 4
Example 2: Replacing Text
This example uses a Perl regular expression to find a match and replace the matching
characters with other characters. PRXPARSE compiles the regular expression and uses
PRXCHANGE to find the match and perform the replacement. The example replaces
all occurrences of a less than sign with &lt;, a common substitution when converting
text to HTML.
data _null_; u
input; v
_infile_ = prxchange(’s/</&lt;/’, -1, _infile_); w
put _infile_; x
datalines; y
x + y < 15
x < 10 < y
y < 11
;
run;
The following items correspond to the numbered lines in the DATA step that is
shown above.
u Create a DATA step.
v Bring an input data record into the input buffer without creating any SAS
variables.
w Call the PRXCHANGE routine to perform the pattern exchange. The format for
the regular expression is s/regular-expression/replacement-text/. The s
before the regular expression signifies that this is a substitution regular
expression. The –1 is a special value that is passed to PRXCHANGE and indicates
that all possible replacements should be made.
x Write the current output line to the log by using the _INFILE_ option with the
PUT statement.
y Identify the input file.
Output 4.8
Output from Replacing Text
x + y &lt; 15
x &lt; 10 &lt; y
y &lt; 11
The ability to pass a regular expression to PRXCHANGE and return a result enables
calling PRXCHANGE from a PROC SQL query. The following query produces a column
with the same character substitution as in the preceding example. From the input table
the query reads text_lines, changes the text for the column line, and places the
results in a column named html_line:
proc sql;
select prxchange(’s/</&lt;/’, -1, line)
as html_line
from text_lines;
quit;
Functions and CALL Routines
4
Example 3: Extracting a Substring from a String
329
Example 3: Extracting a Substring from a String
You can use Perl regular expressions to find and easily extract text from a string. In
this example, the DATA step creates a subset of North Carolina business phone
numbers. The program extracts the area code and checks it against a list of area codes
for North Carolina.
data _null_; u
if _N_ = 1 then
do;
paren = "\(([2-9]\d\d)\) ?[2-9]\d\d-\d\d\d\d"; v
dash = "([2-9]\d\d)-[2-9]\d\d-\d\d\d\d"; w
regexp = "/(" || paren || ")|(" || dash || ")/"; x
retain re;
re = prxparse(regexp); y
if missing(re) then U
do;
putlog "ERROR: Invalid regexp " regexp; V
stop;
end;
retain areacode_re;
areacode_re = prxparse("/828|336|704|910|919|252/");
if missing(areacode_re) then
do;
putlog "ERROR: Invalid area code regexp";
stop;
end;
end;
W
length first last home business $ 16;
length areacode $ 3;
input first last home business;
if ^prxmatch(re, home) then
putlog "NOTE: Invalid home phone number for " first last home;
if prxmatch(re, business) then X
do;
which_format = prxparen(re); at
call prxposn(re, which_format, pos, len); ak
areacode = substr(business, pos, len);
if prxmatch(areacode_re, areacode) then al
put "In North Carolina: " first last business;
end;
else
putlog "NOTE: Invalid business phone number for " first last business;
datalines;
Jerome Johnson (919)319-1677 (919)846-2198
Romeo Montague 800-899-2164 360-973-6201
Imani Rashid (508)852-2146 (508)366-9821
Palinor Kent 704-782-4673 704-782-3199
Ruby Archuleta 905-384-2839 905-328-3892
330
Example 3: Extracting a Substring from a String
4
Chapter 4
Takei Ito 704-298-2145 704-298-4738
Tom Joad 515-372-4829 515-389-2838
;
The following items correspond to the numbered lines in the DATA step that is
shown above.
u Create a DATA step.
v Build a Perl regular expression to identify a phone number that matches
(XXX)XXX-XXXX, and assign the variable PAREN to hold the result. Use the
following syntax elements to build the Perl regular expression:
\(
matches the open parenthesis in the area code. The open
parenthesis marks the start of the submatch.
[2–9]
matches the digits 2–9.
\d
matches a digit, which is the second number in the area code.
\d
matches a digit, which is the third number in the area code.
\)
matches the closed parenthesis in the area code. The closed
parenthesis marks the end of the submatch.
?
matches the space (which is the preceding subexpression) zero
or one time. Spaces are significant in Perl regular expressions.
They match a space in the text that you are searching. If a
space precedes the question mark metacharacter (as it does in
this case), the pattern matches either zero spaces or one space
in this position in the phone number.
w Build a Perl regular expression to identify a phone number that matches
XXX-XXX-XXXX, and assign the variable DASH to hold the result.
x Build a Perl regular expression that concatenates the regular expressions for
(XXX)XXX-XXXX and XXX—XXX—XXXX. The concatenation enables you to
search for both phone number formats from one regular expression.
The PAREN and DASH regular expressions are placed within parentheses. The
bar metacharacter (|) that is located between PAREN and DASH instructs the
compiler to match either pattern. The slashes around the entire pattern tell the
compiler where the start and end of the regular expression is located.
y Pass the Perl regular expression to PRXPARSE and compile the expression.
PRXPARSE returns a value to the compiled pattern. Using the value with other
Perl regular expression functions and CALL routines enables SAS to perform
operations with the compiled Perl regular expression.
U Use the MISSING function to check whether the Perl regular expression compiled
without error.
V Use the PUTLOG statement to write an error message to the SAS log if the
regular expression did not compile.
W Compile a Perl regular expression that searches a string for a valid North
Carolina area code.
X Search for a valid business phone number.
at Use the PRXPAREN function to determine which submatch to use. PRXPAREN
returns the last submatch that was matched. If an area code matches the form
(XXX), PRXPAREN returns the value 2. If an area code matches the form XXX,
PRXPAREN returns the value 4.
ak Call the PRXPOSN routine to retrieve the position and length of the submatch.
Functions and CALL Routines
4
Example 4: Another Example of Extracting a Substring from a String
331
al Use the PRXMATCH function to determine whether the area code is a valid North
Carolina area code, and write the observation to the log.
Output 4.9 Output from Extracting a Substring from a String
In North Carolina: Jerome Johnson (919)846-2198
In North Carolina: Palinor Kent 704-782-3199
In North Carolina: Takei Ito 704-298-4738
Example 4: Another Example of Extracting a Substring from a String
In this example, the PRXPOSN function is passed to the original search text instead
of to the position and length variables. PRXPOSN returns the text that is matched.
data _null_; u
length first last phone $ 16;
retain re;
if _N_ = 1 then do; v
re=prxparse("/\(([2-9]\d\d)\) ?[2-9]\d\d-\d\d\d\d/");
end;
w
input first last phone & 16.;
if prxmatch(re, phone) then do; x
area_code = prxposn(re, 1, phone); y
if area_code ^in ("828"
"336"
"704"
"910"
"919"
"252") then
putlog "NOTE: Not in North Carolina: "
first last phone; U
end;
datalines; V
Thomas Archer
(919)319-1677
Lucy Mallory
(800)899-2164
Tom Joad
(508)852-2146
Laurie Jorgensen (252)352-7583
;
run;
The following items correspond to the numbered lines in the DATA step that is
shown above.
u Create a DATA step.
v If this is the first record, find the value of re.
w Build a Perl regular expression for pattern matching. Use the following syntax
elements to build the Perl regular expression:
/
is the beginning delimiter for a regular expression.
\(
marks the next character entry as a character or a literal.
(
marks the start of the submatch.
332
Example 4: Another Example of Extracting a Substring from a String
4
Chapter 4
[2–9]
matches the digits 2–9 and identifies the first number in the
area code.
\d
matches a digit, which is the second number in the area code.
\d
matches a digit, which is the third number in the area code.
\)
matches the close parenthesis in the area code. The close
parenthesis marks the end of the submatch.
?
matches the space (which is the preceding subexpression) zero
or one time. Spaces are significant in Perl regular expressions.
The spaces match a space in the text that you are searching. If
a space precedes the question mark metacharacter (as it does
in this case), the pattern matches either zero spaces or one
space in this position in the phone number.
||
is the concatenation operator.
[2–9]
matches the digits 2–9 and identifies the first number in the
seven-digit phone number.
\d
matches a digit, which is the second number in the seven-digit
phone number.
\d
matches a digit, which is the third number in the seven-digit
phone number.
–
is the hyphen between the first three and last four digits of the
phone number after the area code.
\d
matches a digit, which is the fourth number in the seven-digit
phone number.
\d
matches a digit, which is the fifth number in the seven-digit
phone number.
\d
matches a digit, which is the sixth number in the seven-digit
phone number.
\d
matches a digit, which is the seventh number in the seven-digit
phone number.
/
is the ending delimiter for a regular expression.
x Return the position at which the string begins.
y Identify the position at which the area code begins.
U Search for an area code from the list. If the area code is not valid for North
Carolina, use the PUTLOG statement to write a note to the SAS log.
V Identify the input file.
Output 4.10
Output from Extracting a Substring from a String
NOTE: Not in North Carolina: Lucy Mallory (800)899-2164
NOTE: Not in North Carolina: Tom Joad (508)852-2146
Functions and CALL Routines
4
Writing Perl Debug Output to the SAS Log
333
Writing Perl Debug Output to the SAS Log
The DATA step provides debugging support with the CALL PRXDEBUG routine.
CALL PRXDEBUG enables you to turn on and off Perl debug output messages that are
sent to the SAS log.
The following example writes Perl debug output to the SAS log.
data _null_;
/* CALL PRXDEBUG(1) turns on Perl debug output. */
call prxdebug(1);
putlog ’PRXPARSE: ’;
re = prxparse(’/[bc]d(ef*g)+h[ij]k$/’);
putlog ’PRXMATCH: ’;
pos = prxmatch(re, ’abcdefg_gh_’);
/* CALL PRXDEBUG(0) turns off Perl debug output. */
call prxdebug(0);
run;
SAS writes the following output to the log.
Output 4.11
SAS Debugging Output
PRXPARSE:
Compiling REx ’[bc]d(ef*g)+h[ij]k$’
size 41 first at 1
rarest char g at 0
rarest char d at 0
1: ANYOF[bc](10)
10: EXACT <d>(12)
12: CURLYX[0] {1,32767}(26)
14:
OPEN1(16)
16:
EXACT <e>(18)
18:
STAR(21)
19:
EXACT <f>(0)
21:
EXACT <g>(23)
23:
CLOSE1(25)
25:
WHILEM[1/1](0)
26: NOTHING(27)
27: EXACT <h>(29)
29: ANYOF[ij](38)
38: EXACT <k>(40)
40: EOL(41)
41: END(0)
anchored ’de’ at 1 floating ’gh’ at 3..2147483647 (checking floating) stclass
’ANYOF[bc]’ minlen 7
PRXMATCH:
Guessing start of match, REx ’[bc]d(ef*g)+h[ij]k$’ against ’abcdefg_gh_’...
Did not find floating substr ’gh’...
Match rejected by optimizer
For a detailed explanation of Perl debug output, see “CALL PRXDEBUG Routine” on
page 468.
334
Perl Artistic License Compliance
4
Chapter 4
Perl Artistic License Compliance
Perl regular expressions are supported beginning with SAS®9.
The PRX functions use a modified version of Perl 5.6.1 to perform regular expression
compilation and matching. Perl is compiled into a library for use with SAS. This library
is shipped with SAS®9. The modified and original Perl 5.6.1 files are freely available in
a ZIP file from http://support.sas.com/rnd/base. The ZIP file is provided to comply
with the Perl Artistic License and is not required in order to use the PRX functions.
Each of the modified files has a comment block at the top of the file describing how and
when the file was changed. The executables were given nonstandard Perl names. The
standard version of Perl can be obtained from http://www.perl.com.
Only Perl regular expressions are accessible from the PRX functions. Other parts of
the Perl language are not accessible. The modified version of Perl regular expressions
does not support the following items:
3
3
3
3
3
3
Perl variables (except the capture buffer variables $1 - $n, which are supported).
The regular expression options /c and /g, and the /e option with substitutions.
The regular expression option /o in SAS 9.0. (It is supported in SAS 9.1 and later.)
Named characters, which use the \N{name} syntax.
The metacharacters \pP, \PP, and \X.
Executing Perl code within a regular expression, which includes the syntax
(?{code}), (??{code}), and (?p{code}).
3 Unicode pattern matching.
3 Using ?PATTERN?. ? is treated like an ordinary regular expression start and end
delimiter.
3 The metacharacter \G.
3 Perl comments between a pattern and replacement text. For example: s{regexp} #
perl comment {replacement} is not supported.
3 Matching backslashes with m/\\\\/. Instead use m/\\/ to match a backslash.
Base SAS Functions for Web Applications
Four functions that manipulate Web-related content are available in Base SAS
software. HTMLENCODE and URLENCODE return encoded strings. HTMLDECODE
and URLDECODE return decoded strings. For information about Web-based SAS tools,
follow the Communities link on the SAS support page, at support.sas.com.
Functions and CALL Routines
4
Functions and CALL Routines by Category
Functions and CALL Routines by Category
Table 4.4 Categories and Descriptions of Functions and CALL Routines
Category
Functions and CALL
Routines
Description
“ANYXDIGIT Function” on
page 389
Searches a character string for a hexadecimal character
that represents a digit, and returns the first position at
which that character is found.
Arithmetic
“DIVIDE Function” on
page 633
Returns the result of a division that handles special
missing values for ODS output.
Array
“DIM Function” on page
630
Returns the number of elements in an array.
“HBOUND Function” on
page 770
Returns the upper bound of an array.
“LBOUND Function” on
page 842
Returns the lower bound of an array.
“BAND Function” on page
404
Returns the bitwise logical AND of two arguments.
“BLSHIFT Function” on
page 414
Returns the bitwise logical left shift of two arguments.
“BNOT Function” on page
415
Returns the bitwise logical NOT of an argument.
“BOR Function” on page
416
Returns the bitwise logical OR of two arguments.
“BRSHIFT Function” on
page 416
Returns the bitwise logical right shift of two arguments.
“BXOR Function” on page
417
Returns the bitwise logical EXCLUSIVE OR of two
arguments.
“CALL PRXCHANGE
Routine” on page 465
Performs a pattern-matching replacement.
“CALL PRXDEBUG
Routine” on page 468
Enables Perl regular expressions in a DATA step to send
debugging output to the SAS log.
“CALL PRXFREE
Routine” on page 470
Frees memory that was allocated for a Perl regular
expression.
“CALL PRXNEXT
Routine” on page 471
Returns the position and length of a substring that
matches a pattern, and iterates over multiple matches
within one string.
“CALL PRXPOSN
Routine” on page 473
Returns the start position and length for a capture buffer.
“CALL PRXSUBSTR
Routine” on page 476
Returns the position and length of a substring that
matches a pattern.
Bitwise Logical Operations
Character String Matching
335
336
Functions and CALL Routines by Category
Category
Character
4
Chapter 4
Functions and CALL
Routines
Description
“PRXCHANGE Function”
on page 994
Performs a pattern-matching replacement.
“PRXMATCH Function” on
page 999
Searches for a pattern match and returns the position at
which the pattern is found.
“PRXPAREN Function” on
page 1003
Returns the last bracket match for which there is a
match in a pattern.
“PRXPARSE Function” on
page 1005
Compiles a Perl regular expression (PRX) that can be
used for pattern matching of a character value.
“PRXPOSN Function” on
page 1007
Returns a character string that contains the value for a
capture buffer.
“ANYALNUM Function”
on page 368
Searches a character string for an alphanumeric
character, and returns the first position at which the
character is found.
“ANYALPHA Function” on
page 370
Searches a character string for an alphabetic character,
and returns the first position at which the character is
found.
“ANYCNTRL Function” on
page 372
Searches a character string for a control character, and
returns the first position at which that character is found.
“ANYDIGIT Function” on
page 373
Searches a character string for a digit, and returns the
first position at which the digit is found.
“ANYFIRST Function” on
page 375
Searches a character string for a character that is valid
as the first character in a SAS variable name under
VALIDVARNAME=V7, and returns the first position at
which that character is found.
“ANYGRAPH Function” on
page 377
Searches a character string for a graphical character, and
returns the first position at which that character is found.
“ANYLOWER Function”
on page 379
Searches a character string for a lowercase letter, and
returns the first position at which the letter is found.
“ANYNAME Function” on
page 380
Searches a character string for a character that is valid
in a SAS variable name under VALIDVARNAME=V7,
and returns the first position at which that character is
found.
“ANYPRINT Function” on
page 382
Searches a character string for a printable character, and
returns the first position at which that character is found.
“ANYPUNCT Function” on
page 384
Searches a character string for a punctuation character,
and returns the first position at which that character is
found.
“ANYSPACE Function” on
page 386
Searches a character string for a white-space character
(blank, horizontal and vertical tab, carriage return, line
feed, and form feed), and returns the first position at
which that character is found.
“ANYUPPER Function” on
page 388
Searches a character string for an uppercase letter, and
returns the first position at which the letter is found.
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“ANYXDIGIT Function” on
page 389
Searches a character string for a hexadecimal character
that represents a digit, and returns the first position at
which that character is found.
“BYTE Function” on page
418
Returns one character in the ASCII or the EBCDIC
collating sequence.
“CALL CATS Routine” on
page 428
Removes leading and trailing blanks, and returns a
concatenated character string.
“CALL CATT Routine” on
page 430
Removes trailing blanks, and returns a concatenated
character string.
“CALL CATX Routine” on
page 432
Removes leading and trailing blanks, inserts delimiters,
and returns a concatenated character string.
“CALL COMPCOST
Routine” on page 434
Sets the costs of operations for later use by the
COMPGED function
“CALL MISSING Routine”
on page 459
Assigns missing values to the specified character or
numeric variables.
“CALL SCAN Routine” on
page 500
Returns the position and length of the nth word from a
character string.
“CAT Function” on page
526
Does not remove leading or trailing blanks, and returns
a concatenated character string.
“CATQ Function” on page
528
Concatenates character or numeric values by using a
delimiter to separate items and by adding quotation
marks to strings that contain the delimiter.
“CATS Function” on page
532
Removes leading and trailing blanks, and returns a
concatenated character string.
“CATT Function” on page
534
Removes trailing blanks, and returns a concatenated
character string.
“CATX Function” on page
537
Removes leading and trailing blanks, inserts delimiters,
and returns a concatenated character string.
“CHAR Function” on page
557
Returns a single character from a specified position in a
character string.
“CHOOSEC Function” on
page 558
Returns a character value that represents the results of
choosing from a list of arguments.
“CHOOSEN Function” on
page 559
Returns a numeric value that represents the results of
choosing from a list of arguments.
“COALESCEC Function”
on page 566
Returns the first non-missing value from a list of
character arguments.
“COLLATE Function” on
page 567
Returns a character string in ASCII or EBCDIC collating
sequence.
“COMPARE Function” on
page 569
Returns the position of the leftmost character by which
two strings differ, or returns 0 if there is no difference.
“COMPBL Function” on
page 572
Removes multiple blanks from a character string.
337
338
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“COMPGED Function” on
page 573
Returns the generalized edit distance between two
strings.
“COMPLEV Function” on
page 578
Returns the Levenshtein edit distance between two
strings.
“COMPRESS Function” on
page 582
Returns a character string with specified characters
removed from the original string.
“COUNT Function” on
page 593
Counts the number of times that a specified substring
appears within a character string.
“COUNTC Function” on
page 595
Counts the number of characters in a string that appear
or do not appear in a list of characters.
“COUNTW Function” on
page 598
Counts the number of words in a character string.
“DEQUOTE Function” on
page 621
Removes matching quotation marks from a character
string that begins with a quotation mark, and deletes all
characters to the right of the closing quotation mark.
“FIND Function” on page
705
Searches for a specific substring of characters within a
character string.
“FINDC Function” on page
707
Searches a string for any character in a list of characters.
“FINDW Function” on
page 713
Returns the character position of a word in a string, or
returns the number of the word in a string.
“FIRST Function” on page
724
Returns the first character in a character string.
“IFC Function” on page
779
Returns a character value based on whether an
expression is true, false, or missing.
“INDEX Function” on page
784
Searches a character expression for a string of
characters, and returns the position of the string’s first
character for the first occurrence of the string.
“INDEXC Function” on
page 786
Searches a character expression for any of the specified
characters, and returns the position of that character.
“INDEXW Function” on
page 787
Searches a character expression for a string that is
specified as a word, and returns the position of the first
character in the word.
“LEFT Function” on page
846
Left-aligns a character string.
“LENGTH Function” on
page 847
Returns the length of a non-blank character string,
excluding trailing blanks, and returns 1 for a blank
character string.
“LENGTHC Function” on
page 848
Returns the length of a character string, including
trailing blanks.
“LENGTHM Function” on
page 849
Returns the amount of memory (in bytes) that is
allocated for a character string.
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“LENGTHN Function” on
page 851
Returns the length of a character string, excluding
trailing blanks.
“LOWCASE Function” on
page 875
Converts all letters in an argument to lowercase.
“MD5 Function” on page
884
Returns the result of the message digest of a specified
string.
“MISSING Function” on
page 890
Returns a numeric result that indicates whether the
argument contains a missing value.
“NLITERAL Function” on
page 906
Converts a character string that you specify to a SAS
name literal.
“NOTALNUM Function”
on page 909
Searches a character string for a non-alphanumeric
character, and returns the first position at which the
character is found.
“NOTALPHA Function” on
page 911
Searches a character string for a nonalphabetic
character, and returns the first position at which the
character is found.
“NOTCNTRL Function” on
page 913
Searches a character string for a character that is not a
control character, and returns the first position at which
that character is found.
“NOTDIGIT Function” on
page 914
Searches a character string for any character that is not
a digit, and returns the first position at which that
character is found.
“NOTFIRST Function” on
page 918
Searches a character string for an invalid first character
in a SAS variable name under VALIDVARNAME=V7,
and returns the first position at which that character is
found.
“NOTGRAPH Function” on
page 919
Searches a character string for a non-graphical
character, and returns the first position at which that
character is found.
“NOTLOWER Function”
on page 921
Searches a character string for a character that is not a
lowercase letter, and returns the first position at which
that character is found.
“NOTNAME Function” on
page 923
Searches a character string for an invalid character in a
SAS variable name under VALIDVARNAME=V7, and
returns the first position at which that character is found.
“NOTPRINT Function” on
page 925
Searches a character string for a nonprintable character,
and returns the first position at which that character is
found.
“NOTPUNCT Function” on
page 926
Searches a character string for a character that is not a
punctuation character, and returns the first position at
which that character is found.
“NOTSPACE Function” on
page 928
Searches a character string for a character that is not a
white-space character (blank, horizontal and vertical tab,
carriage return, line feed, and form feed), and returns
the first position at which that character is found.
339
340
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“NOTUPPER Function” on
page 930
Searches a character string for a character that is not an
uppercase letter, and returns the first position at which
that character is found.
“NOTXDIGIT Function” on
page 932
Searches a character string for a character that is not a
hexadecimal character, and returns the first position at
which that character is found.
“NVALID Function” on
page 934
Checks the validity of a character string for use as a SAS
variable name.
“PROPCASE Function” on
page 992
Converts all words in an argument to proper case.
“QUOTE Function” on
page 1019
Adds double quotation marks to a character value.
“RANK Function” on page
1036
Returns the position of a character in the ASCII or
EBCDIC collating sequence.
“REPEAT Function” on
page 1044
Returns a character value that consists of the first
argument repeated n+1 times.
“REVERSE Function” on
page 1045
Reverses a character string.
“RIGHT Function” on page
1047
Right aligns a character expression.
“SCAN Function” on page
1060
Returns the nth word from a character string.
“SOUNDEX Function” on
page 1077
Encodes a string to facilitate searching.
“SPEDIS Function” on
page 1078
Determines the likelihood of two words matching,
expressed as the asymmetric spelling distance between
the two words.
“STRIP Function” on page
1086
Returns a character string with all leading and trailing
blanks removed.
“SUBPAD Function” on
page 1088
Returns a substring that has a length you specify, using
blank padding if necessary.
“SUBSTR (left of =)
Function” on page 1089
Replaces character value contents.
“SUBSTR (right of =)
Function” on page 1090
Extracts a substring from an argument.
“SUBSTRN Function” on
page 1091
Returns a substring, allowing a result with a length of
zero.
“TRANSLATE Function”
on page 1112
Replaces specific characters in a character string.
“TRANSTRN Function” on
page 1113
Replaces or removes all occurrences of a substring in a
character string.
“TRANWRD Function” on
page 1116
Replaces all occurrences of a substring in a character
string.
Functions and CALL Routines
Category
Combinatorial
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“TRIM Function” on page
1119
Removes trailing blanks from a character string, and
returns one blank if the string is missing.
“TRIMN Function” on page
1121
Removes trailing blanks from character expressions, and
returns a string with a length of zero if the expression is
missing.
“UPCASE Function” on
page 1123
Converts all letters in an argument to uppercase.
“VERIFY Function” on
page 1139
Returns the position of the first character in a string that
is not in any of several other strings.
“ALLCOMB Function” on
page 364
Generates all combinations of the values of n variables
taken k at a time in a minimal change order.
“ALLPERM Function” on
page 366
Generates all permutations of the values of several
variables in a minimal change order.
“CALL ALLCOMB
Routine” on page 419
Generates all combinations of the values of n variables
taken k at a time in a minimal change order.
“CALL ALLCOMBI
Routine” on page 422
Generates all combinations of the indices of n objects
taken k at a time in a minimal change order.
“CALL ALLPERM
Routine” on page 424
Generates all permutations of the values of several
variables in a minimal change order.
“CALL GRAYCODE
Routine” on page 437
Generates all subsets of n items in a minimal change
order.
“CALL LEXCOMB
Routine” on page 445
Generates all distinct combinations of the non-missing
values of n variables taken k at a time in lexicographic
order.
“CALL LEXCOMBI
Routine” on page 448
Generates all combinations of the indices of n objects
taken k at a time in lexicographic order.
“CALL LEXPERK
Routine” on page 451
Generates all distinct permutations of the non-missing
values of n variables taken k at a time in lexicographic
order.
“CALL LEXPERM
Routine” on page 455
Generates all distinct permutations of the non-missing
values of several variables in lexicographic order.
“CALL RANPERK
Routine” on page 488
Randomly permutes the values of the arguments, and
returns a permutation of k out of n values.
“CALL RANPERM
Routine” on page 490
Randomly permutes the values of the arguments.
“COMB Function” on page
568
Computes the number of combinations of n elements
taken r at a time.
“GRAYCODE Function” on
page 764
Generates all subsets of n items in a minimal change
order.
“LCOMB Function” on
page 845
Computes the logarithm of the COMB function which is
the logarithm of the number of combinations of n objects
taken r at a time.
341
342
Functions and CALL Routines by Category
Category
Date and Time
4
Chapter 4
Functions and CALL
Routines
Description
“LEXCOMB Function” on
page 852
Generates all distinct combinations of the non-missing
values of n variables taken k at a time in lexicographic
order.
“LEXCOMBI Function” on
page 855
Generates all combinations of the indices of n objects
taken k at a time in lexicographic order.
“LEXPERK Function” on
page 856
Generates all distinct permutations of the non-missing
values of n variables taken k at a time in lexicographic
order.
“LEXPERM Function” on
page 859
Generates all distinct permutations of the non-missing
values of several variables in lexicographic order.
“LFACT Function” on page
861
Computes the logarithm of the FACT (factorial) function.
“LPERM Function” on
page 875
Computes the logarithm of the PERM function which is
the logarithm of the number of permutations of n objects,
with the option of including r number of elements.
“PERM Function” on page
964
Computes the number of permutations of n items that
are taken r at a time.
“CALL IS8601_CONVERT
Routine” on page 440
Converts an ISO 8601 interval to datetime and duration
values, or converts datetime and duration values to an
ISO 8601 interval.
“DATDIF Function” on
page 608
Returns the number of days between two dates after
computing the difference between the dates according to
specified day count conventions.
“DATE Function” on page
611
Returns the current date as a SAS date value.
“DATEJUL Function” on
page 611
Converts a Julian date to a SAS date value.
“DATEPART Function” on
page 612
Extracts the date from a SAS datetime value.
“DATETIME Function” on
page 613
Returns the current date and time of day as a SAS
datetime value.
“DAY Function” on page
613
Returns the day of the month from a SAS date value.
“DHMS Function” on page
627
Returns a SAS datetime value from date, hour, minute,
and second values.
“HMS Function” on page
771
Returns a SAS time value from hour, minute, and second
values.
“HOLIDAY Function” on
page 772
Returns a SAS date value of a specified holiday for a
specified year.
“HOUR Function” on page
774
Returns the hour from a SAS time or datetime value.
“INTCINDEX Function” on
page 797
Returns the cycle index when a date, time, or datetime
interval and value are specified.
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“INTCK Function” on page
799
Returns the count of the number of interval boundaries
between two dates, two times, or two datetime values.
“INTCYCLE Function” on
page 803
Returns the date, time, or datetime interval at the next
higher seasonal cycle when a date, time, or datetime
interval is specified.
“INTFIT Function” on
page 805
Returns a time interval that is aligned between two
dates.
“INTFMT Function” on
page 808
Returns a recommended SAS format when a date, time,
or datetime interval is specified.
“INTGET Function” on
page 810
Returns a time interval based on three date or datetime
values.
“INTINDEX Function” on
page 811
Returns the seasonal index when a date, time, or
datetime interval and value are specified.
“INTNX Function” on page
814
Increments a date, time, or datetime value by a given
time interval, and returns a date, time, or datetime value.
“INTSEAS Function” on
page 821
Returns the length of the seasonal cycle when a date,
time, or datetime interval is specified.
“INTSHIFT Function” on
page 823
Returns the shift interval that corresponds to the base
interval.
“INTTEST Function” on
page 825
Returns 1 if a time interval is valid, and returns 0 if a
time interval is invalid.
“JULDATE Function” on
page 832
Returns the Julian date from a SAS date value.
“JULDATE7 Function” on
page 833
Returns a seven-digit Julian date from a SAS date value.
“MDY Function” on page
885
Returns a SAS date value from month, day, and year
values.
“MINUTE Function” on
page 889
Returns the minute from a SAS time or datetime value.
“MONTH Function” on
page 897
Returns the month from a SAS date value.
“NWKDOM Function” on
page 937
Returns the date for the nth occurrence of a weekday for
the specified month and year.
“QTR Function” on page
1016
Returns the quarter of the year from a SAS date value.
“SECOND Function” on
page 1071
Returns the second from a SAS time or datetime value.
“TIME Function” on page
1108
Returns the current time of day as a numeric SAS time
value.
“TIMEPART Function” on
page 1109
Extracts a time value from a SAS datetime value.
“TODAY Function” on page
1112
Returns the current date as a numeric SAS date value.
343
344
Functions and CALL Routines by Category
Category
Descriptive Statistics
4
Chapter 4
Functions and CALL
Routines
Description
“WEEK Function” on page
1170
Returns the week-number value.
“WEEKDAY Function” on
page 1173
From a SAS date value, returns an integer that
corresponds to the day of the week.
“YEAR Function” on page
1176
Returns the year from a SAS date value.
“YRDIF Function” on page
1179
Returns the difference in years between two dates.
“YYQ Function” on page
1180
Returns a SAS date value from year and quarter year
values.
“CMISS Function” on page
562
Counts the number of missing arguments.
“CSS Function” on page
601
Returns the corrected sum of squares.
“CV Function” on page 602
Returns the coefficient of variation.
“EUCLID Function” on
page 647
Returns the Euclidean norm of the non-missing
arguments.
“GEOMEAN Function” on
page 756
Returns the geometric mean.
“GEOMEANZ Function”
on page 758
Returns the geometric mean, using zero fuzzing.
“HARMEAN Function” on
page 767
Returns the harmonic mean.
“HARMEANZ Function”
on page 768
Returns the harmonic mean, using zero fuzzing.
“IQR Function” on page
829
Returns the interquartile range.
“KURTOSIS Function” on
page 834
Returns the kurtosis.
“LARGEST Function” on
page 841
Returns the kth largest non-missing value.
“LPNORM Function” on
page 876
Returns the Lp norm of the second argument and
subsequent non-missing arguments.
“MAD Function” on page
878
Returns the median absolute deviation from the median.
“MAX Function” on page
883
Returns the largest value.
“MEAN Function” on page
886
Returns the arithmetic mean (average).
“MEDIAN Function” on
page 887
Returns the median value.
“MIN Function” on page
888
Returns the smallest value.
Functions and CALL Routines
Category
Distance
External Files
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“MISSING Function” on
page 890
Returns a numeric result that indicates whether the
argument contains a missing value.
“N Function” on page 904
Returns the number of non-missing numeric values.
“NMISS Function” on page
908
Returns the number of missing numeric values.
“ORDINAL Function” on
page 941
Returns the kth smallest of the missing and nonmissing
values.
“PCTL Function” on page
944
Returns the percentile that corresponds to the
percentage.
“RANGE Function” on
page 1035
Returns the range of the nonmissing values.
“RMS Function” on page
1048
Returns the root mean square of the nonmissing
arguments.
“SKEWNESS Function” on
page 1074
Returns the skewness of the nonmissing arguments.
“SMALLEST Function” on
page 1076
Returns the kth smallest nonmissing value.
“STD Function” on page
1081
Returns the standard deviation of the nonmissing
arguments.
“STDERR Function” on
page 1082
Returns the standard error of the mean of the
nonmissing arguments.
“SUM Function” on page
1095
Returns the sum of the nonmissing arguments.
“SUMABS Function” on
page 1096
Returns the sum of the absolute values of the
non-missing arguments.
“USS Function” on page
1126
Returns the uncorrected sum of squares of the
nonmissing arguments.
“VAR Function” on page
1128
Returns the variance of the nonmissing arguments.
“GEODIST Function” on
page 754
Returns the geodetic distance between two latitude and
longitude coordinates.
“ZIPCITYDISTANCE
Function” on page 1183
Returns the geodetic distance between two ZIP code
locations.
“DCLOSE Function” on
page 614
Closes a directory that was opened by the DOPEN
function.
“DCREATE Function” on
page 616
Returns the complete pathname of a new, external
directory.
“DINFO Function” on page
632
Returns information about a directory.
“DNUM Function” on page
634
Returns the number of members in a directory.
“DOPEN Function” on
page 635
Opens a directory, and returns a directory identifier
value.
345
346
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“DOPTNAME Function”
on page 637
Returns directory attribute information.
“DOPTNUM Function” on
page 638
Returns the number of information items that are
available for a directory.
“DREAD Function” on
page 639
Returns the name of a directory member.
“DROPNOTE Function” on
page 640
Deletes a note marker from a SAS data set or an
external file.
“FAPPEND Function” on
page 652
Appends the current record to the end of an external file.
“FCLOSE Function” on
page 654
Closes an external file, directory, or directory member.
“FCOL Function” on page
655
Returns the current column position in the File Data
Buffer (FDB).
“FDELETE Function” on
page 656
Deletes an external file or an empty directory.
“FEXIST Function” on
page 660
Verifies the existence of an external file that is associated
with a fileref.
“FGET Function” on page
661
Copies data from the File Data Buffer (FDB) into a
variable.
“FILEEXIST Function” on
page 663
Verifies the existence of an external file by its physical
name.
“FILENAME Function” on
page 663
Assigns or deassigns a fileref to an external file,
directory, or output device.
“FILEREF Function” on
page 666
Verifies whether a fileref has been assigned for the
current SAS session.
“FINFO Function” on page
718
Returns the value of a file information item.
“FNOTE Function” on
page 729
Identifies the last record that was read, and returns a
value that the FPOINT function can use.
“FOPEN Function” on
page 731
Opens an external file and returns a file identifier value.
“FOPTNAME Function” on
page 733
Returns the name of an item of information about a file.
“FOPTNUM Function” on
page 735
Returns the number of information items that are
available for an external file.
“FPOINT Function” on
page 736
Positions the read pointer on the next record to be read.
“FPOS Function” on page
737
Sets the position of the column pointer in the File Data
Buffer (FDB).
“FPUT Function” on page
739
Moves data to the File Data Buffer (FDB) of an external
file, starting at the FDB’s current column position.
Functions and CALL Routines
Category
External Routines
Financial
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“FREAD Function” on
page 741
Reads a record from an external file into the File Data
Buffer (FDB).
“FREWIND Function” on
page 742
Positions the file pointer to the start of the file.
“FRLEN Function” on
page 743
Returns the size of the last record that was read, or, if the
file is opened for output, returns the current record size.
“FSEP Function” on page
744
Sets the token delimiters for the FGET function.
“FWRITE Function” on
page 746
Writes a record to an external file.
“MOPEN Function” on
page 897
Opens a file by directory ID and member name, and
returns either the file identifier or a 0.
“PATHNAME Function” on
page 942
Returns the physical name of an external file or a SAS
library, or returns a blank.
“RENAME Function” on
page 1042
Renames a member of a SAS library, an entry in a SAS
catalog, an external file, or a directory.
“SYSMSG Function” on
page 1101
Returns error or warning message text from processing
the last data set or external file function.
“SYSRC Function” on page
1105
Returns a system error number.
“CALL MODULE Routine”
on page 460
Calls an external routine without any return code.
“MODULEC Function” on
page 894
Calls an external routine and returns a character value.
“MODULEN Function” on
page 894
Calls an external routine and returns a numeric value.
“BLACKCLPRC Function”
on page 407
Calculates call prices for European options on futures,
based on the Black model.
“BLACKPTPRC Function”
on page 409
Calculates put prices for European options on futures,
based on the Black model.
“BLKSHCLPRC Function”
on page 410
Calculates call prices for European options on stocks,
based on the Black-Scholes model.
“BLKSHPTPRC Function”
on page 412
Calculates put prices for European options on stocks,
based on the Black-Scholes model.
“COMPOUND Function”
on page 581
Returns compound interest parameters.
“CONVX Function” on
page 589
Returns the convexity for an enumerated cash flow.
“CONVXP Function” on
page 590
Returns the convexity for a periodic cash flow stream,
such as a bond.
“DACCDB Function” on
page 603
Returns the accumulated declining balance depreciation.
347
348
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“DACCDBSL Function” on
page 604
Returns the accumulated declining balance with
conversion to a straight-line depreciation.
“DACCSL Function” on
page 605
Returns the accumulated straight-line depreciation.
“DACCSYD Function” on
page 606
Returns the accumulated sum-of-years-digits
depreciation.
“DACCTAB Function” on
page 607
Returns the accumulated depreciation from specified
tables.
“DEPDB Function” on
page 616
Returns the declining balance depreciation.
“DEPDBSL Function” on
page 617
Returns the declining balance with conversion to a
straight-line depreciation.
“DEPSL Function” on page
619
Returns the straight-line depreciation.
“DEPSYD Function” on
page 619
Returns the sum-of-years-digits depreciation.
“DEPTAB Function” on
page 620
Returns the depreciation from specified tables.
“DUR Function” on page
642
Returns the modified duration for an enumerated cash
flow.
“DURP Function” on page
643
Returns the modified duration for a periodic cash flow
stream, such as a bond.
“FINANCE Function” on
page 667
Computes financial calculations such as depreciation,
maturation, accrued interest, net present value, periodic
savings, and internal rates of return.
“GARKHCLPRC Function”
on page 749
Calculates call prices for European options on stocks,
based on the Garman-Kohlhagen model.
“GARKHPTPRC Function”
on page 751
Calculates put prices for European options on stocks,
based on the Garman-Kohlhagen model.
“INTRR Function” on page
820
Returns the internal rate of return as a fraction.
“IRR Function” on page
830
Returns the internal rate of return as a percentage.
“MARGRCLPRC Function”
on page 879
Calculates call prices for European options on stocks,
based on the Margrabe model.
“MARGRPTPRC Function”
on page 881
Calculates put prices for European options on stocks,
based on the Margrabe model.
“MORT Function” on page
900
Returns amortization parameters.
“NETPV Function” on
page 905
Returns the net present value as a fraction.
“NPV Function” on page
934
Returns the net present value with the rate expressed as
a percentage.
Functions and CALL Routines
Category
Hyperbolic
Macro
Mathematical
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“PVP Function” on page
1015
Returns the present value for a periodic cash flow stream
(such as a bond), with repayment of principal at maturity.
“SAVING Function” on
page 1059
Returns the future value of a periodic saving.
“YIELDP Function” on
page 1177
Returns the yield-to-maturity for a periodic cash flow
stream, such as a bond.
“ARCOSH Function” on
page 392
Returns the inverse hyperbolic cosine.
“ARSINH Function” on
page 394
Returns the inverse hyperbolic sine.
“ARTANH Function” on
page 395
Returns the inverse hyperbolic tangent.
“COSH Function” on page
592
Returns the hyperbolic cosine.
“SINH Function” on page
1073
Returns the hyperbolic sine.
“TANH Function” on page
1108
Returns the hyperbolic tangent.
“CALL EXECUTE
Routine” on page 436
Resolves the argument, and issues the resolved value for
execution at the next step boundary.
“CALL SYMPUT Routine”
on page 519
Assigns DATA step information to a macro variable.
“CALL SYMPUTX
Routine” on page 520
Assigns a value to a macro variable, and removes both
leading and trailing blanks.
“RESOLVE Function” on
page 1045
Returns the resolved value of the argument after it has
been processed by the macro facility.
“SYMEXIST Function” on
page 1097
Returns an indication of the existence of a macro
variable.
“SYMGET Function” on
page 1098
Returns the value of a macro variable during DATA step
execution.
“SYMGLOBL Function” on
page 1098
Returns an indication of whether a macro variable is in
global scope to the DATA step during DATA step
execution.
“SYMLOCAL Function” on
page 1099
Returns an indication of whether a macro variable is in
local scope to the DATA step during DATA step execution.
“ABS Function” on page
360
Returns the absolute value.
“AIRY Function” on page
363
Returns the value of the Airy function.
“BETA Function” on page
405
Returns the value of the beta function.
“CALL LOGISTIC
Routine” on page 458
Applies the logistic function to each argument.
349
350
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“CALL SOFTMAX
Routine” on page 511
Returns the softmax value.
“CALL STDIZE Routine”
on page 514
Standardizes the values of one or more variables.
“CALL TANH Routine” on
page 522
Returns the hyperbolic tangent.
“CNONCT Function” on
page 563
Returns the noncentrality parameter from a chi-square
distribution.
“COALESCE Function” on
page 565
Returns the first non-missing value from a list of
numeric arguments.
“CONSTANT Function” on
page 585
Computes machine and mathematical constants.
“DAIRY Function” on page
608
Returns the derivative of the AIRY function.
“DEVIANCE Function” on
page 623
Returns the deviance based on a probability distribution.
“DIGAMMA Function” on
page 629
Returns the value of the digamma function.
“ERF Function” on page
645
Returns the value of the (normal) error function.
“ERFC Function” on page
646
Returns the value of the complementary (normal) error
function.
“EXP Function” on page
651
Returns the value of the exponential function.
“FACT Function” on page
651
Computes a factorial.
“FNONCT Function” on
page 728
Returns the value of the noncentrality parameter of an F
distribution.
“GAMMA Function” on
page 749
Returns the value of the gamma function.
“GCD Function” on page
753
Returns the greatest common divisor for one or more
integers.
“IBESSEL Function” on
page 778
Returns the value of the modified Bessel function.
“JBESSEL Function” on
page 831
Returns the value of the Bessel function.
“LCM Function” on page
844
Returns the least common multiple.
“LGAMMA Function” on
page 862
Returns the natural logarithm of the Gamma function.
“LOG Function” on page
866
Returns the natural (base e) logarithm.
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“LOG1PX Function” on
page 867
Returns the log of 1 plus the argument.
“LOG10 Function” on page
868
Returns the logarithm to the base 10.
“LOG2 Function” on page
868
Returns the logarithm to the base 2.
“LOGBETA Function” on
page 869
Returns the logarithm of the beta function.
“MOD Function” on page
891
Returns the remainder from the division of the first
argument by the second argument, fuzzed to avoid most
unexpected floating-point results.
“MODZ Function” on page
895
Returns the remainder from the division of the first
argument by the second argument, using zero fuzzing.
“MSPLINT Function” on
page 901
Returns the ordinate of a monotonicity-preserving
interpolating spline.
“SIGN Function” on page
1072
Returns the sign of a value.
“SQRT Function” on page
1081
Returns the square root of a value.
“TNONCT Function” on
page 1110
Returns the value of the noncentrality parameter from
the Student’s t distribution.
“TRIGAMMA Function” on
page 1118
Returns the value of the trigamma function.
Numeric
“IFN Function” on page
781
Returns a numeric value based on whether an expression
is true, false, or missing.
Probability
“CDF Function” on page
540
Returns a value from a cumulative probability
distribution.
“LOGCDF Function” on
page 870
Returns the logarithm of a left cumulative distribution
function.
“LOGPDF Function” on
page 871
Returns the logarithm of a probability density (mass)
function.
“LOGSDF Function” on
page 873
Returns the logarithm of a survival function.
“PDF Function” on page
945
Returns a value from a probability density (mass)
distribution.
“POISSON Function” on
page 967
Returns the probability from a Poisson distribution.
“PROBBETA Function” on
page 968
Returns the probability from a beta distribution.
“PROBBNML Function” on
page 969
Returns the probability from a binomial distribution.
“PROBBNRM Function”
on page 970
Returns a probability from a bivariate normal
distribution.
351
352
Functions and CALL Routines by Category
Category
Quantile
Random Number
4
Chapter 4
Functions and CALL
Routines
Description
“PROBCHI Function” on
page 971
Returns the probability from a chi-square distribution.
“PROBF Function” on page
972
Returns the probability from an F distribution.
“PROBGAM Function” on
page 973
Returns the probability from a gamma distribution.
“PROBHYPR Function” on
page 974
Returns the probability from a hypergeometric
distribution.
“PROBMC Function” on
page 976
Returns a probability or a quantile from various
distributions for multiple comparisons of means.
“PROBNEGB Function” on
page 989
Returns the probability from a negative binomial
distribution.
“PROBNORM Function”
on page 990
Returns the probability from the standard normal
distribution.
“PROBT Function” on page
991
Returns the probability from a t distribution.
“SDF Function” on page
1069
Returns a survival function.
“BETAINV Function” on
page 406
Returns a quantile from the beta distribution.
“CINV Function” on page
560
Returns a quantile from the chi-square distribution.
“FINV Function” on page
719
Returns a quantile from the F distribution.
“GAMINV Function” on
page 748
Returns a quantile from the gamma distribution.
“PROBIT Function” on
page 975
Returns a quantile from the standard normal
distribution.
“QUANTILE Function” on
page 1017
Returns the quantile from a distribution that you specify.
“TINV Function” on page
1109
Returns a quantile from the t distribution.
“CALL RANBIN Routine”
on page 478
Returns a random variate from a binomial distribution.
“CALL RANCAU Routine”
on page 480
Returns a random variate from a Cauchy distribution.
“CALL RANEXP Routine”
on page 482
Returns a random variate from an exponential
distribution.
“CALL RANGAM Routine”
on page 484
Returns a random variate from a gamma distribution.
“CALL RANNOR Routine”
on page 486
Returns a random variate from a normal distribution.
Functions and CALL Routines
Category
SAS File I/O
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“CALL RANPOI Routine”
on page 492
Returns a random variate from a Poisson distribution.
“CALL RANTBL Routine”
on page 494
Returns a random variate from a tabled probability
distribution.
“CALL RANTRI Routine”
on page 497
Returns a random variate from a triangular distribution.
“CALL RANUNI Routine”
on page 499
Returns a random variate from a uniform distribution.
“CALL STREAMINIT
Routine” on page 518
Specifies a seed value to use for subsequent random
number generation by the RAND function.
“NORMAL Function” on
page 909
Returns a random variate from a normal, or Gaussian,
distribution.
“RANBIN Function” on
page 1020
Returns a random variate from a binomial distribution.
“RANCAU Function” on
page 1021
Returns a random variate from a Cauchy distribution.
“RAND Function” on page
1022
Generates random numbers from a distribution that you
specify.
“RANEXP Function” on
page 1033
Returns a random variate from an exponential
distribution.
“RANGAM Function” on
page 1034
Returns a random variate from a gamma distribution.
“RANNOR Function” on
page 1037
Returns a random variate from a normal distribution.
“RANPOI Function” on
page 1038
Returns a random variate from a Poisson distribution.
“RANTBL Function” on
page 1039
Returns a random variate from a tabled probability
distribution.
“RANTRI Function” on
page 1040
Returns a random variate from a triangular distribution.
“RANUNI Function” on
page 1041
Returns a random variate from a uniform distribution.
“UNIFORM Function” on
page 1123
Returns a random variate from a uniform distribution.
“ATTRC Function” on page
398
Returns the value of a character attribute for a SAS data
set.
“ATTRN Function” on page
400
Returns the value of a numeric attribute for a SAS data
set.
“CEXIST Function” on
page 556
Verifies the existence of a SAS catalog or SAS catalog
entry.
“CLOSE Function” on page
562
Closes a SAS data set.
353
354
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“CUROBS Function” on
page 601
Returns the observation number of the current
observation.
“DROPNOTE Function” on
page 640
Deletes a note marker from a SAS data set or an
external file.
“DSNAME Function” on
page 641
Returns the SAS data set name that is associated with a
data set identifier.
“ENVLEN Function” on
page 645
Returns the length of an environment variable.
“EXIST Function” on page
648
Verifies the existence of a SAS library member.
“FETCH Function” on
page 658
Reads the next non-deleted observation from a SAS data
set into the Data Set Data Vector (DDV).
“FETCHOBS Function” on
page 659
Reads a specified observation from a SAS data set into
the Data Set Data Vector (DDV).
“GETVARC Function” on
page 762
Returns the value of a SAS data set character variable.
“GETVARN Function” on
page 763
Returns the value of a SAS data set numeric variable.
“IORCMSG Function” on
page 828
Returns a formatted error message for _IORC_.
“LIBNAME Function” on
page 863
Assigns or deassigns a libref for a SAS library.
“LIBREF Function” on
page 865
Verifies that a libref has been assigned.
“NOTE Function” on page
916
Returns an observation ID for the current observation of
a SAS data set.
“OPEN Function” on page
939
Opens a SAS data set.
“PATHNAME Function” on
page 942
Returns the physical name of an external file or a SAS
library, or returns a blank.
“POINT Function” on page
966
Locates an observation that is identified by the NOTE
function.
“RENAME Function” on
page 1042
Renames a member of a SAS library, an entry in a SAS
catalog, an external file, or a directory.
“REWIND Function” on
page 1046
Positions the data set pointer at the beginning of a SAS
data set.
“SYSMSG Function” on
page 1101
Returns error or warning message text from processing
the last data set or external file function.
“SYSRC Function” on page
1105
Returns a system error number.
“VARFMT Function” on
page 1128
Returns the format that is assigned to a SAS data set
variable.
Functions and CALL Routines
Category
Search
Sort
Special
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“VARINFMT Function” on
page 1130
Returns the informat that is assigned to a SAS data set
variable.
“VARLABEL Function” on
page 1131
Returns the label that is assigned to a SAS data set
variable.
“VARLEN Function” on
page 1132
Returns the length of a SAS data set variable.
“VARNAME Function” on
page 1133
Returns the name of a SAS data set variable.
“VARNUM Function” on
page 1134
Returns the number of a variable’s position in a SAS
data set.
“VARTYPE Function” on
page 1137
Returns the data type of a SAS data set variable.
“WHICHC Function” on
page 1174
Searches for a character value that is equal to the first
argument, and returns the index of the first matching
value.
“WHICHN Function” on
page 1175
Searches for a numeric value that is equal to the first
argument, and returns the index of the first matching
value.
“CALL SORTC Routine”
on page 512
Sorts the values of character arguments.
“CALL SORTN Routine”
on page 513
Sorts the values of numeric arguments.
“ADDR Function” on page
361
Returns the memory address of a variable on a 32–bit
platform.
“ADDRLONG Function” on
page 362
Returns the memory address of a variable on 32-bit and
64-bit platforms.
“CALL POKE Routine” on
page 463
Writes a value directly into memory on a 32-bit platform.
“CALL POKELONG
Routine” on page 464
Writes a value directly into memory on 32-bit and 64-bit
platforms.
“CALL SLEEP Routine” on
page 510
For a specified period of time, suspends the execution of
a program that invokes this CALL routine.
“CALL SYSTEM Routine”
on page 521
Submits an operating environment command for
execution.
“DIF Function” on page
628
Returns differences between an argument and its nth lag.
“GETOPTION Function”
on page 759
Returns the value of a SAS system or graphics option.
“INPUT Function” on page
790
Returns the value that is produced when SAS converts
an expression using the specified informat.
“INPUTC Function” on
page 792
Enables you to specify a character informat at run time.
355
356
Functions and CALL Routines by Category
Category
State and ZIP Code
4
Chapter 4
Functions and CALL
Routines
Description
“INPUTN Function” on
page 794
Enables you to specify a numeric informat at run time.
“LAG Function” on page
835
Returns values from a queue.
“PEEK Function” on page
958
Stores the contents of a memory address in a numeric
variable on a 32–bit platform.
“PEEKC Function” on
page 959
Stores the contents of a memory address in a character
variable on a 32–bit platform.
“PEEKCLONG Function”
on page 962
Stores the contents of a memory address in a character
variable on 32-bit and 64-bit platforms.
“PEEKLONG Function” on
page 963
Stores the contents of a memory address in a numeric
variable on 32-bit and 64-bit platforms.
“PTRLONGADD Function”
on page 1010
Returns the pointer address as a character variable on
32-bit and 64-bit platforms.
“PUT Function” on page
1010
Returns a value using a specified format.
“PUTC Function” on page
1012
Enables you to specify a character format at run time.
“PUTN Function” on page
1014
Enables you to specify a numeric format at run time.
“SLEEP Function” on page
1075
For a specified period of time, suspends the execution of
a program that invokes this function.
“SYSGET Function” on
page 1100
Returns the value of the specified operating environment
variable.
“SYSPARM Function” on
page 1102
Returns the system parameter string.
“SYSPROCESSID
Function” on page 1102
Returns the process ID of the current process.
“SYSPROCESSNAME
Function” on page 1103
Returns the process name that is associated with a given
process ID, or returns the name of the current process.
“SYSPROD Function” on
page 1104
Determines whether a product is licensed.
“SYSTEM Function” on
page 1106
Issues an operating environment command during a SAS
session, and returns the system return code.
“UUIDGEN Function” on
page 1127
Returns the short or binary form of a Universal Unique
Identifier (UUID).
“FIPNAME Function” on
page 721
Converts two-digit FIPS codes to uppercase state names.
“FIPNAMEL Function” on
page 722
Converts two-digit FIPS codes to mixed case state names.
“FIPSTATE Function” on
page 723
Converts two-digit FIPS codes to two-character state
postal codes.
Functions and CALL Routines
Category
Trigonometric
Truncation
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“STFIPS Function” on
page 1082
Converts state postal codes to FIPS state codes.
“STNAME Function” on
page 1084
Converts state postal codes to uppercase state names.
“STNAMEL Function” on
page 1085
Converts state postal codes to mixed case state names.
“ZIPCITY Function” on
page 1181
Returns a city name and the two-character postal code
that corresponds to a ZIP code.
“ZIPCITYDISTANCE
Function” on page 1183
Returns the geodetic distance between two ZIP code
locations.
“ZIPFIPS Function” on
page 1184
Converts ZIP codes to two-digit FIPS codes.
“ZIPNAME Function” on
page 1186
Converts ZIP codes to uppercase state names.
“ZIPNAMEL Function” on
page 1187
Converts ZIP codes to mixed case state names.
“ZIPSTATE Function” on
page 1189
Converts ZIP codes to two-character state postal codes.
“ARCOS Function” on
page 391
Returns the arccosine.
“ARSIN Function” on page
393
Returns the arcsine.
“ATAN Function” on page
396
Returns the arc tangent.
“ATAN2 Function” on page
397
Returns the arc tangent of the ratio of two numeric
variables.
“COS Function” on page
591
Returns the cosine.
“SIN Function” on page
1072
Returns the sine.
“TAN Function” on page
1107
Returns the tangent.
“CEIL Function” on page
553
Returns the smallest integer that is greater than or
equal to the argument, fuzzed to avoid unexpected
floating-point results.
“CEILZ Function” on page
555
Returns the smallest integer that is greater than or
equal to the argument, using zero fuzzing.
“FLOOR Function” on
page 725
Returns the largest integer that is less than or equal to
the argument, fuzzed to avoid unexpected floating-point
results.
“FLOORZ Function” on
page 726
Returns the largest integer that is less than or equal to
the argument, using zero fuzzing.
357
358
Functions and CALL Routines by Category
Category
Variable Control
Variable Information
4
Chapter 4
Functions and CALL
Routines
Description
“FUZZ Function” on page
746
Returns the nearest integer if the argument is within
1E−12 of that integer.
“INT Function” on page
796
Returns the integer value, fuzzed to avoid unexpected
floating-point results.
“INTZ Function” on page
827
Returns the integer portion of the argument, using zero
fuzzing.
“ROUND Function” on
page 1049
Rounds the first argument to the nearest multiple of the
second argument, or to the nearest integer when the
second argument is omitted.
“ROUNDE Function” on
page 1056
Rounds the first argument to the nearest multiple of the
second argument, and returns an even multiple when the
first argument is halfway between the two nearest
multiples.
“ROUNDZ Function” on
page 1057
Rounds the first argument to the nearest multiple of the
second argument, using zero fuzzing.
“TRUNC Function” on
page 1122
Truncates a numeric value to a specified number of bytes.
“CALL LABEL Routine”
on page 444
Assigns a variable label to a specified character variable.
“CALL SET Routine” on
page 509
Links SAS data set variables to DATA step or macro
variables that have the same name and data type.
“CALL VNAME Routine”
on page 523
Assigns a variable name as the value of a specified
variable.
“CALL VNEXT Routine”
on page 524
Returns the name, type, and length of a variable that is
used in a DATA step.
“VARRAY Function” on
page 1135
Returns a value that indicates whether the specified
name is an array.
“VARRAYX Function” on
page 1136
Returns a value that indicates whether the value of the
specified argument is an array.
“VFORMAT Function” on
page 1140
Returns the format that is associated with the specified
variable.
“VFORMATD Function” on
page 1141
Returns the decimal value of the format that is
associated with the specified variable.
“VFORMATDX Function”
on page 1142
Returns the decimal value of the format that is
associated with the value of the specified argument.
“VFORMATN Function” on
page 1143
Returns the format name that is associated with the
specified variable.
“VFORMATNX Function”
on page 1144
Returns the format name that is associated with the
value of the specified argument.
“VFORMATW Function”
on page 1145
Returns the format width that is associated with the
specified variable.
“VFORMATWX Function”
on page 1146
Returns the format width that is associated with the
value of the specified argument.
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“VFORMATX Function” on
page 1147
Returns the format that is associated with the value of
the specified argument.
“VINARRAY Function” on
page 1148
Returns a value that indicates whether the specified
variable is a member of an array.
“VINARRAYX Function”
on page 1149
Returns a value that indicates whether the value of the
specified argument is a member of an array.
“VINFORMAT Function”
on page 1150
Returns the informat that is associated with the specified
variable.
“VINFORMATD Function”
on page 1151
Returns the decimal value of the informat that is
associated with the specified variable.
“VINFORMATDX
Function” on page 1152
Returns the decimal value of the informat that is
associated with the value of the specified variable.
“VINFORMATN Function”
on page 1153
Returns the informat name that is associated with the
specified variable.
“VINFORMATNX
Function” on page 1155
Returns the informat name that is associated with the
value of the specified argument.
“VINFORMATW Function”
on page 1156
Returns the informat width that is associated with the
specified variable.
“VINFORMATWX
Function” on page 1157
Returns the informat width that is associated with the
value of the specified argument.
“VINFORMATX Function”
on page 1158
Returns the informat that is associated with the value of
the specified argument.
“VLABEL Function” on
page 1159
Returns the label that is associated with the specified
variable.
“VLABELX Function” on
page 1160
Returns the label that is associated with the value of the
specified argument.
“VLENGTH Function” on
page 1161
Returns the compile-time (allocated) size of the specified
variable.
“VLENGTHX Function” on
page 1162
Returns the compile-time (allocated) size for the variable
that has a name that is the same as the value of the
argument.
“VNAME Function” on
page 1163
Returns the name of the specified variable.
“VNAMEX Function” on
page 1164
Validates the value of the specified argument as a
variable name.
“VTYPE Function” on page
1165
Returns the type (character or numeric) of the specified
variable.
“VTYPEX Function” on
page 1166
Returns the type (character or numeric) for the value of
the specified argument.
“VVALUE Function” on
page 1168
Returns the formatted value that is associated with the
variable that you specify.
“VVALUEX Function” on
page 1169
Returns the formatted value that is associated with the
argument that you specify.
359
360
Dictionary
4
Chapter 4
Category
Functions and CALL
Routines
Description
Web Tools
“HTMLDECODE
Function” on page 775
Decodes a string that contains HTML numeric character
references or HTML character entity references, and
returns the decoded string.
“HTMLENCODE
Function” on page 777
Encodes characters using HTML character entity
references, and returns the encoded string.
“URLDECODE Function”
on page 1124
Returns a string that was decoded using the URL escape
syntax.
“URLENCODE Function”
on page 1125
Returns a string that was encoded using the URL escape
syntax.
Dictionary
ABS Function
Returns the absolute value.
Category:
Mathematical
Syntax
ABS (argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The ABS function returns a nonnegative number that is equal in magnitude to the
magnitude of the argument.
Examples
SAS Statements
Results
x=abs(2.4);
2.4
x=abs(-3);
3
Functions and CALL Routines
4
ADDR Function
361
ADDR Function
Returns the memory address of a variable on a 32–bit platform.
Category: Special
Restriction:
Use on 32–bit platforms only.
Syntax
ADDR(variable)
Arguments
variable
specifies a variable name.
Details
The value that is returned is numeric. Because the storage location of a variable can
vary from one execution to the next, the value that is returned by ADDR can vary. The
ADDR function is used mostly in combination with the PEEK and PEEKC functions
and the CALL POKE routine.
You cannot use the ADDR function on 64-bit platforms. If you attempt to use it, SAS
writes a message to the log stating that this restriction applies. If you have legacy
applications that use ADDR, change the applications and use ADDRLONG instead. You
can use ADDRLONG on both 32–bit and 64–bit platforms.
Comparisons
The ADDR function returns the memory address of a variable on a 32–bit platform.
ADDRLONG returns the memory address of a variable on 32–bit and 64–bit platforms.
Note: SAS recommends that you use ADDRLONG instead of ADDR because
ADDRLONG can be used on both 32–bit and 64–bit platforms. 4
Examples
The following example returns the address at which the variable FIRST is stored:
data numlist;
first=3;
x=addr(first);
run;
See Also
CALL Routine:
“CALL POKE Routine” on page 463
362
ADDRLONG Function
4
Chapter 4
Functions:
“PEEK Function” on page 958
“PEEKC Function” on page 959
“ADDRLONG Function” on page 362
ADDRLONG Function
Returns the memory address of a variable on 32-bit and 64-bit platforms.
Category:
Special
Syntax
ADDRLONG(variable)
Arguments
variable
specifies a variable.
Details
The return value is a character string that contains the binary representation of the
address. To display this value, use the $HEXw. format to convert the binary value to
its hexadecimal equivalent. If you store the result in a variable, that variable should be
a character variable with a length of at least eight characters for portability. If you
assign the result to a variable that does not yet have a length defined, that variable is
given a length of 20 characters.
Examples
The following example returns the pointer address for the variable ITEM, and
formats the value.
data characterlist;
item=6345;
x=addrlong(item);
put x $hex16.;
run;
The following line is written to the SAS log:
480063B020202020
Functions and CALL Routines
4
AIRY Function
AIRY Function
Returns the value of the Airy function.
Category: Mathematical
Syntax
AIRY(x)
Arguments
x
specifies a numeric constant, variable, or expression.
Details
The AIRY function returns the value of the Airy function (Abramowitz and Stegun
1964; Amos, Daniel and Weston 1977) (See “References” on page 1197). It is the
solution of the differential equation
w(2) 0 xw = 0
with the conditions
w (0) =
10
30
2
3
2
3
1
and
w
0
(0) =
0
1
1
33 0
011
3
Examples
SAS Statements
Results
x=airy(2.0);
0.0349241304
x=airy(-2.0);
0.2274074282
363
364
4
ALLCOMB Function
Chapter 4
ALLCOMB Function
Generates all combinations of the values of n variables taken k at a time in a minimal change
order.
Category:
Restriction:
Combinatorial
The ALLCOMB function cannot be executed when you use the %SYSFUNC
macro.
Syntax
ALLCOMB(count, k, variable-1, … , variable-n)
Arguments
count
specifies an integer variable that is assigned values from 1 to the number of
combinations in a loop.
k
specifies an integer constant, variable, or expression between 1 and n, inclusive, that
specifies the number of items in each combination.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted.
Requirement:
Initialize these variables before executing the ALLCOMB function.
Restriction: Specify no more than 33 items. If you need to find combinations of
more than 33 items, use the CALL ALLCOMBI routine.
After executing ALLCOMB, the first k variables contain the values in one
combination.
Tip:
Details
Use the ALLCOMB function in a loop where the first argument to ALLCOMB accepts
each integral value from 1 to the number of combinations, and where k is constant. The
number of combinations can be computed by using the COMB function. On the first
execution, the argument types and lengths are checked for consistency. On each
subsequent execution, the values of two variables are interchanged.
For the ALLCOMB function, the following actions occur:
3 On the first execution, ALLCOMB returns 0.
3 If the values of variable-i and variable-j were interchanged, wherei<j, then
ALLCOMB returns i.
3 If no values were interchanged because all combinations were already generated,
then ALLCOMB returns –1.
If you execute the ALLCOMB function with the first argument out of sequence, the
results are not useful. In particular, if you initialize the variables and then immediately
th
execute the ALLCOMB function with a first argument of j, then you will not get the j
th
combination (except when j is 1). To get the j combination, you must execute
Functions and CALL Routines
4
ALLCOMB Function
365
ALLCOMB j times, with the first argument taking values from 1 through j in that exact
order.
Comparisons
SAS provides four functions or CALL routines for generating combinations:
3 ALLCOMB generates all possible combinations of the values, missing or
nonmissing, of N variables. The values can be any numeric or character values.
Each combination is formed from the previous combination by removing one value
and inserting another value.
3 LEXCOMB generates all distinct combinations of the nonmissing values of several
variables. The values can be any numeric or character values. The combinations
are generated in lexicographic order.
3 ALLCOMBI generates all combinations of the indices of N items, where indices
are integers from 1 to N. Each combination is formed from the previous
combination by removing one index and inserting another index.
3 LEXCOMBI generates all combinations of the indices of N items, where indices
are integers from 1 to N. The combinations are generated in lexicographic order.
ALLCOMBI is the fastest of these functions and CALL routines. LEXCOMB is the
slowest.
Examples
The following is an example of the ALLCOMB function.
data _null_;
array x[5] $3 (’ant’ ’bee’ ’cat’ ’dog’ ’ewe’);
n=dim(x);
k=3;
ncomb=comb(n,k);
do j=1 to ncomb+1;
rc=allcomb(j, k, of x[*]);
put j 5. +3 x1-x3 +3 rc=;
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
ant
ant
ant
ant
ant
ant
bee
bee
bee
dog
dog
bee
bee
bee
cat
cat
dog
dog
dog
ewe
ewe
ewe
cat
ewe
dog
dog
ewe
ewe
ewe
cat
cat
cat
cat
rc=0
rc=3
rc=3
rc=2
rc=3
rc=2
rc=1
rc=3
rc=2
rc=1
rc=-1
366
ALLPERM Function
4
Chapter 4
See Also
Functions and CALL Routines:
“CALL ALLCOMB Routine” on page 419
ALLPERM Function
Generates all permutations of the values of several variables in a minimal change order.
Category:
Combinatorial
Syntax
ALLPERM(count, variable-1 < ,variable-2 …>)
Arguments
count
specifies a variable with an integer value that ranges from 1 to the number of
permutations.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted.
Requirement: Initialize these variables before you execute the ALLPERM function.
Restriction: Specify no more than 18 variables.
Details
The Basics
Use the ALLPERM function in a loop where the first argument to
ALLPERM accepts each integral value from 1 to the number of permutations. On the
first execution, the argument types and lengths are checked for consistency. On each
subsequent execution, the values of two consecutive variables are interchanged.
Note: You can compute the number of permutations by using the PERM function.
See “PERM Function” on page 964 for more information.
For the ALLPERM function, the following values are returned:
3 0 if count=1
3 J if the values of variable-J and variable-K are interchanged, where K=J+1
3 –1 if count>N!
4
If you use the ALLPERM function and the first argument is out of sequence, the
results are not useful. For example, if you initialize the variables and then immediately
execute the ALLPERM function with a first argument of K, your result will not be the
Kth permutation (except when K is 1). To get the Kth permutation, you must execute
the ALLPERM function K times, with the first argument taking values from 1 through
K in that exact order.
Functions and CALL Routines
4
ALLPERM Function
367
ALLPERM always produces N! permutations even if some of the variables have
equal values or missing values. If you want to generate only the distinct permutations
when there are equal values, or if you want to omit missing values from the
permutations, use the LEXPERM function instead.
Note: The ALLPERM function cannot be executed when you use the %SYSFUNC
macro. 4
Comparisons
SAS provides three functions or CALL routines for generating all permutations:
3 ALLPERM generates all possible permutations of the values, missing or
non-missing, of several variables. Each permutation is formed from the previous
permutation by interchanging two consecutive values.
3 LEXPERM generates all distinct permutations of the non-missing values of
several variables. The permutations are generated in lexicographic order.
3 LEXPERK generates all distinct permutations of K of the non-missing values of N
variables. The permutations are generated in lexicographic order.
ALLPERM is the fastest of these functions and CALL routines. LEXPERK is the
slowest.
Examples
The following example generates permutations of given values by using the
ALLPERM function.
data _null_;
array x [4] $3 (’ant’ ’bee’ ’cat’ ’dog’);
n=dim(x);
nfact=fact(n);
do i=1 to nfact+1;
change=allperm(i, of x[*]);
put i 5. +2 change +2 x[*];
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
3
2
1
3
1
2
3
1
3
2
1
3
1
2
3
1
ant
ant
ant
dog
dog
ant
ant
ant
cat
cat
cat
dog
dog
cat
cat
cat
bee
bee
bee
dog
ant
ant
dog
cat
cat
ant
ant
dog
cat
cat
dog
bee
bee
cat
cat
dog
bee
bee
cat
cat
dog
bee
bee
dog
ant
ant
bee
bee
dog
ant
ant
dog
cat
cat
cat
bee
bee
bee
dog
dog
bee
bee
bee
ant
ant
ant
dog
dog
368
ANYALNUM Function
4
18
19
20
21
22
23
24
25
Chapter 4
3
2
1
3
1
2
3
-1
bee cat dog ant
bee dog cat ant
dog bee cat ant
dog bee ant cat
bee dog ant cat
bee ant dog cat
bee ant cat dog
bee ant cat dog
See Also
Functions and CALL Routines:
“CALL ALLPERM Routine” on page 424
“LEXPERM Function” on page 859
“CALL RANPERK Routine” on page 488
“CALL RANPERM Routine” on page 490
ANYALNUM Function
Searches a character string for an alphanumeric character, and returns the first position at which
the character is found.
Character
Restriction: “I18N Level 2” on page 305
Category:
Syntax
ANYALNUM(string <,start>)
Arguments
string
specifies a character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYALNUM function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYALNUM function searches a string for the first occurrence of any character
that is a digit or an uppercase or lowercase letter. If such a character is found,
ANYALNUM returns the position in the string of that character. If no such character is
found, ANYALNUM returns a value of 0.
Functions and CALL Routines
4
ANYALNUM Function
369
If you use only one argument, ANYALNUM begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYALNUM returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYALNUM function searches a character string for an alphanumeric character.
The NOTALNUM function searches a character string for a non-alphanumeric character.
Examples
Example 1: Scanning a String from Left to Right
The following example uses the
ANYALNUM function to search a string from left to right for alphanumeric characters.
data _null_;
string=’Next = Last + 1;’;
j=0;
do until(j=0);
j=anyalnum(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=2 c=e
j=3 c=x
j=4 c=t
j=8 c=L
j=9 c=a
j=10 c=s
j=11 c=t
j=15 c=1
That’s all
Example 2: Scanning a String from Right to Left
The following example uses the
ANYALNUM function to search a string from right to left for alphanumeric characters.
data _null_;
string=’Next = Last + 1;’;
j=999999;
370
4
ANYALPHA Function
Chapter 4
do until(j=0);
j=anyalnum(string,1-j);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=15 c=1
j=11 c=t
j=10 c=s
j=9 c=a
j=8 c=L
j=4 c=t
j=3 c=x
j=2 c=e
j=1 c=N
That’s all
See Also
Function:
“NOTALNUM Function” on page 909
ANYALPHA Function
Searches a character string for an alphabetic character, and returns the first position at which the
character is found.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
ANYALPHA(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Functions and CALL Routines
4
ANYALPHA Function
371
Details
The results of the ANYALPHA function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option”and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYALPHA function searches a string for the first occurrence of any character
that is an uppercase or lowercase letter. If such a character is found, ANYALPHA
returns the position in the string of that character. If no such character is found,
ANYALPHA returns a value of 0.
If you use only one argument, ANYALPHA begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYALPHA returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYALPHA function searches a character string for an alphabetic character. The
NOTALPHA function searches a character string for a non-alphabetic character.
Examples
Example 1: Searching a String for Alphabetic Characters
The following example uses
the ANYALPHA function to search a string from left to right for alphabetic characters.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anyalpha(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=2 c=e
j=3 c=x
j=4 c=t
j=9 c=n
j=16 c=E
That’s all
372
ANYCNTRL Function
4
Chapter 4
Example 2: Identifying Control Characters by Using the ANYALPHA Function
You can
execute the following program to show the control characters that are identified by the
ANYALPHA function.
data test;
do dec=0 to 255;
byte=byte(dec);
hex=put(dec,hex2.);
anyalpha=anyalpha(byte);
output;
end;
proc print data=test;
run;
See Also
Function:
“NOTALPHA Function” on page 911
ANYCNTRL Function
Searches a character string for a control character, and returns the first position at which that
character is found.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
ANYCNTRL(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYCNTRL function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in the SAS National Language Support
(NLS): Reference Guide.
Functions and CALL Routines
4
ANYDIGIT Function
373
The ANYCNTRL function searches a string for the first occurrence of a control
character. If such a character is found, ANYCNTRL returns the position in the string of
that character. If no such character is found, ANYCNTRL returns a value of 0.
If you use only one argument, ANYCNTRL begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYCNTRL returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYCNTRL function searches a character string for a control character. The
NOTCNTRL function searches a character string for a character that is not a control
character.
Examples
You can execute the following program to show the control characters that are identified
by the ANYCNTRL function.
data test;
do dec=0 to 255;
drop byte;
byte=byte(dec);
hex=put(dec,hex2.);
anycntrl=anycntrl(byte);
if anycntrl then output;
end;
proc print data=test;
run;
See Also
Function:
“NOTCNTRL Function” on page 913
ANYDIGIT Function
Searches a character string for a digit, and returns the first position at which the digit is found.
Category: Character
Restriction:
“I18N Level 2” on page 305
374
4
ANYDIGIT Function
Chapter 4
Syntax
ANYDIGIT(string < ,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The ANYDIGIT function does not depend on the TRANTAB, ENCODING, or LOCALE
options.
The ANYDIGIT function searches a string for the first occurrence of any character
that is a digit. If such a character is found, ANYDIGIT returns the position in the
string of that character. If no such character is found, ANYDIGIT returns a value of 0.
If you use only one argument, ANYDIGIT begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYDIGIT returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYDIGIT function searches a character string for a digit. The NOTDIGIT
function searches a character string for any character that is not a digit.
Examples
The following example uses the ANYDIGIT function to search for a character that is
a digit.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anydigit(string,j+1);
if j=0 then put +3 "That’s all";
else do;
Functions and CALL Routines
4
ANYFIRST Function
375
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=14 c=1
j=15 c=2
j=17 c=3
That’s all
See Also
Function:
“NOTDIGIT Function” on page 914
ANYFIRST Function
Searches a character string for a character that is valid as the first character in a SAS variable
name under VALIDVARNAME=V7, and returns the first position at which that character is found.
Category: Character
Restriction:
“I18N Level 2” on page 305
Syntax
ANYFIRST(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The ANYFIRST function does not depend on the TRANTAB, ENCODING, or LOCALE
options.
The ANYFIRST function searches a string for the first occurrence of any character
that is valid as the first character in a SAS variable name under VALIDVARNAME=V7.
These characters are the underscore (_) and uppercase or lowercase English letters. If
such a character is found, ANYFIRST returns the position in the string of that
character. If no such character is found, ANYFIRST returns a value of 0.
376
ANYFIRST Function
4
Chapter 4
If you use only one argument, ANYFIRST begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYFIRST returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYFIRST function searches a string for the first occurrence of any character that
is valid as the first character in a SAS variable name under VALIDVARNAME=V7. The
NOTFIRST function searches a string for the first occurrence of any character that is
not valid as the first character in a SAS variable name under VALIDVARNAME=V7.
Examples
The following example uses the ANYFIRST function to search a string for any
character that is valid as the first character in a SAS variable name under
VALIDVARNAME=V7.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anyfirst(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=2 c=e
j=3 c=x
j=4 c=t
j=8 c=_
j=9 c=n
j=10 c=_
j=16 c=E
That’s all
See Also
Functions and CALL Routines
4
ANYGRAPH Function
377
Function:
“NOTFIRST Function” on page 918
ANYGRAPH Function
Searches a character string for a graphical character, and returns the first position at which that
character is found.
Category: Character
Restriction:
“I18N Level 2” on page 305
Syntax
ANYGRAPH(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYGRAPH function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYGRAPH function searches a string for the first occurrence of a graphical
character. A graphical character is defined as any printable character other than white
space. If such a character is found, ANYGRAPH returns the position in the string of
that character. If no such character is found, ANYGRAPH returns a value of 0.
If you use only one argument, ANYGRAPH begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYGRAPH returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
378
ANYGRAPH Function
4
Chapter 4
Comparisons
The ANYGRAPH function searches a character string for a graphical character. The
NOTGRAPH function searches a character string for a non-graphical character.
Examples
Example 1: Searching a String for Graphical Characters
The following example uses
the ANYGRAPH function to search a string for graphical characters.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anygraph(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=2 c=e
j=3 c=x
j=4 c=t
j=6 c==
j=8 c=_
j=9 c=n
j=10 c=_
j=12 c=+
j=14 c=1
j=15 c=2
j=16 c=E
j=17 c=3
j=18 c=;
That’s all
Example 2: Identifying Control Characters by Using the ANYGRAPH Function
You can
execute the following program to show the control characters that are identified by the
ANYGRAPH function.
data test;
do dec=0 to 255;
byte=byte(dec);
hex=put(dec,hex2.);
anygraph=anygraph(byte);
output;
end;
proc print data=test;
run;
Functions and CALL Routines
4
ANYLOWER Function
379
See Also
Function:
“NOTGRAPH Function” on page 919
ANYLOWER Function
Searches a character string for a lowercase letter, and returns the first position at which the letter
is found.
Category: Character
Restriction:
“I18N Level 2” on page 305
Syntax
ANYLOWER(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYLOWER function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYLOWER function searches a string for the first occurrence of a lowercase
letter. If such a character is found, ANYLOWER returns the position in the string of
that character. If no such character is found, ANYLOWER returns a value of 0.
If you use only one argument, ANYLOWER begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYLOWER returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
380
ANYNAME Function
4
Chapter 4
3 The value of start = 0.
Comparisons
The ANYLOWER function searches a character string for a lowercase letter. The
NOTLOWER function searches a character string for a character that is not a
lowercase letter.
Examples
The following example uses the ANYLOWER function to search a string for any
character that is a lowercase letter.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anylower(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=2 c=e
j=3 c=x
j=4 c=t
j=9 c=n
That’s all
See Also
Function:
“NOTLOWER Function” on page 921
ANYNAME Function
Searches a character string for a character that is valid in a SAS variable name under
VALIDVARNAME=V7, and returns the first position at which that character is found.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
ANYNAME(string <,start>)
Functions and CALL Routines
4
ANYNAME Function
381
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The ANYNAME function does not depend on the TRANTAB, ENCODING, or LOCALE
system options.
The ANYNAME function searches a string for the first occurrence of any character
that is valid in a SAS variable name under VALIDVARNAME=V7. These characters are
the underscore (_), digits, and uppercase or lowercase English letters. If such a
character is found, ANYNAME returns the position in the string of that character. If no
such character is found, ANYNAME returns a value of 0.
If you use only one argument, ANYNAME begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYNAME returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYNAME function searches a string for the first occurrence of any character that
is valid in a SAS variable name under VALIDVARNAME=V7. The NOTNAME function
searches a string for the first occurrence of any character that is not valid in a SAS
variable name under VALIDVARNAME=V7.
Examples
The following example uses the ANYNAME function to search a string for any
character that is valid in a SAS variable name under VALIDVARNAME=V7.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anyname(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
382
4
ANYPRINT Function
Chapter 4
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=2 c=e
j=3 c=x
j=4 c=t
j=8 c=_
j=9 c=n
j=10 c=_
j=14 c=1
j=15 c=2
j=16 c=E
j=17 c=3
That’s all
See Also
Function:
“NOTNAME Function” on page 923
ANYPRINT Function
Searches a character string for a printable character, and returns the first position at which that
character is found.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
ANYPRINT(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYPRINT function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Functions and CALL Routines
4
ANYPRINT Function
383
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYPRINT function searches a string for the first occurrence of a printable
character. If such a character is found, ANYPRINT returns the position in the string of
that character. If no such character is found, ANYPRINT returns a value of 0.
If you use only one argument, ANYPRINT begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYPRINT returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYPRINT function searches a character string for a printable character. The
NOTPRINT function searches a character string for a non-printable character.
Examples
Example 1: Searching a String for a Printable Character
The following example uses
the ANYPRINT function to search a string for printable characters.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anyprint(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=2 c=e
j=3 c=x
j=4 c=t
j=5 c=
j=6 c==
j=7 c=
j=8 c=_
j=9 c=n
j=10 c=_
j=11 c=
j=12 c=+
384
4
ANYPUNCT Function
Chapter 4
j=13 c=
j=14 c=1
j=15 c=2
j=16 c=E
j=17 c=3
j=18 c=;
That’s all
Example 2: Identifying Control Characters by Using the ANYPRINT Function
You can
execute the following program to show the control characters that are identified by the
ANYPRINT function.
data test;
do dec=0 to 255;
byte=byte(dec);
hex=put(dec,hex2.);
anyprint=anyprint(byte);
output;
end;
proc print data=test;
run;
See Also
Function:
“NOTPRINT Function” on page 925
ANYPUNCT Function
Searches a character string for a punctuation character, and returns the first position at which that
character is found.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
ANYPUNCT(string < ,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Functions and CALL Routines
4
ANYPUNCT Function
385
Details
The results of the ANYPUNCT function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYPUNCT function searches a string for the first occurrence of a punctuation
character. If such a character is found, ANYPUNCT returns the position in the string of
that character. If no such character is found, ANYPUNCT returns a value of 0.
If you use only one argument, ANYPUNCT begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYPUNCT returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYPUNCT function searches a character string for a punctuation character. The
NOTPUNCT function searches a character string for a character that is not a
punctuation character.
Examples
Example 1: Searching a String for Punctuation Characters
The following example uses
the ANYPUNCT function to search a string for punctuation characters.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anypunct(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=6 c==
j=8 c=_
j=10 c=_
j=12 c=+
j=18 c=;
That’s all
386
ANYSPACE Function
4
Chapter 4
Example 2: Identifying Control Characters by Using the ANYPUNCT Function
You can
execute the following program to show the control characters that are identified by the
ANYPUNCT function.
data test;
do dec=0 to 255;
byte=byte(dec);
hex=put(dec,hex2.);
anypunct=anypunct(byte);
output;
end;
proc print data=test;
run;
See Also
Function:
“NOTPUNCT Function” on page 926
ANYSPACE Function
Searches a character string for a white-space character (blank, horizontal and vertical tab, carriage
return, line feed, and form feed), and returns the first position at which that character is found.
Character
Restriction: “I18N Level 2” on page 305
Category:
Syntax
ANYSPACE(string <,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYSPACE function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYSPACE function searches a string for the first occurrence of any character
that is a blank, horizontal tab, vertical tab, carriage return, line feed, or form feed. If
Functions and CALL Routines
4
ANYSPACE Function
387
such a character is found, ANYSPACE returns the position in the string of that
character. If no such character is found, ANYSPACE returns a value of 0.
If you use only one argument, ANYSPACE begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYSPACE returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYSPACE function searches a character string for the first occurrence of a
character that is a blank, horizontal tab, vertical tab, carriage return, line feed, or form
feed. The NOTSPACE function searches a character string for the first occurrence of a
character that is not a blank, horizontal tab, vertical tab, carriage return, line feed, or
form feed.
Examples
Example 1: Searching a String for a White-Space Character
The following example
uses the ANYSPACE function to search a string for a character that is a white-space
character.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anyspace(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=5 c=
j=7 c=
j=11 c=
j=13 c=
That’s all
Example 2: Identifying Control Characters by Using the ANYSPACE Function
You can
execute the following program to show the control characters that are identified by the
ANYSPACE function.
data test;
do dec=0 to 255;
388
ANYUPPER Function
4
Chapter 4
byte=byte(dec);
hex=put(dec,hex2.);
anyspace=anyspace(byte);
output;
end;
proc print data=test;
run;
See Also
Function:
“NOTSPACE Function” on page 928
ANYUPPER Function
Searches a character string for an uppercase letter, and returns the first position at which the
letter is found.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
ANYUPPER(string < ,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The results of the ANYUPPER function depend directly on the translation table that is
in effect (see “TRANTAB System Option”) and indirectly on the “ENCODING System
Option” and the “LOCALE System Option” in SAS National Language Support (NLS):
Reference Guide.
The ANYUPPER function searches a string for the first occurrence of an uppercase
letter. If such a character is found, ANYUPPER returns the position in the string of
that character. If no such character is found, ANYUPPER returns a value of 0.
If you use only one argument, ANYUPPER begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
Functions and CALL Routines
4
ANYXDIGIT Function
389
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYUPPER returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYUPPER function searches a character string for an uppercase letter. The
NOTUPPER function searches a character string for a character that is not an
uppercase letter.
Examples
The following example uses the ANYUPPER function to search a string for an
uppercase letter.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=anyupper(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=1 c=N
j=16 c=E
That’s all
See Also
Function:
“NOTUPPER Function” on page 930
ANYXDIGIT Function
Searches a character string for a hexadecimal character that represents a digit, and returns the
first position at which that character is found.
Category: Character
390
ANYXDIGIT Function
4
Chapter 4
Restriction:
“I18N Level 2” on page 305
Syntax
ANYXDIGIT(string < ,start>)
Arguments
string
is the character constant, variable, or expression to search.
start
is an optional integer that specifies the position at which the search should start and
the direction in which to search.
Details
The ANYXDIGIT function does not depend on the TRANTAB, ENCODING, or LOCALE
options.
The ANYXDIGIT function searches a string for the first occurrence of any character
that is a digit or an uppercase or lowercase A, B, C, D, E, or F. If such a character is
found, ANYXDIGIT returns the position in the string of that character. If no such
character is found, ANYXDIGIT returns a value of 0.
If you use only one argument, ANYXDIGIT begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
specifies the position at which to begin the search. The direction in which to search is
determined in the following way:
3 If the value of start is positive, the search proceeds to the right.
3 If the value of start is negative, the search proceeds to the left.
3 If the value of start is less than the negative length of the string, the search begins
at the end of the string.
ANYXDIGIT returns a value of zero when one of the following is true:
3 The character that you are searching for is not found.
3 The value of start is greater than the length of the string.
3 The value of start = 0.
Comparisons
The ANYXDIGIT function searches a character string for a character that is a
hexadecimal character. The NOTXDIGIT function searches a character string for a
character that is not a hexadecimal character.
Examples
The following example uses the ANYXDIGIT function to search a string for a
hexadecimal character that represents a digit.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
Functions and CALL Routines
4
ARCOS Function
391
j=anyxdigit(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=2 c=e
j=14 c=1
j=15 c=2
j=16 c=E
j=17 c=3
That’s all
See Also
Function:
“NOTXDIGIT Function” on page 932
ARCOS Function
Returns the arccosine.
Category: Trigonometric
Syntax
ARCOS (argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Range: between −1 and 1
Details
The ARCOS function returns the arccosine (inverse cosine) of the argument. The value
that is returned is specified in radians.
392
ARCOSH Function
4
Chapter 4
Examples
SAS Statements
Results
x=arcos(1);
0
x=arcos(0);
1.5707963268
x=arcos(-0.5);
2.0943951024
ARCOSH Function
Returns the inverse hyperbolic cosine.
Category:
Hyperbolic
Syntax
ARCOSH(x)
Arguments
x
specifies a numeric constant, variable, or expression.
Range:
x >= 1
Details
The ARCOSH function computes the inverse hyperbolic cosine. The ARCOSH function
is mathematically defined by the following equation, where x >= 1:
p
ARCOSH (x) = log x + x2 0 1
Examples
The following example computes the inverse hyperbolic cosine.
data _null_;
x=arcosh(5);
x1=arcosh(13);
put x=;
put x1=;
run;
Functions and CALL Routines
4
ARSIN Function
393
SAS writes the following output to the log:
x=2.2924316696
x1=3.2566139548
See Also
Functions:
“COSH Function” on page 592
“SINH Function” on page 1073
“TANH Function” on page 1108
“ARSINH Function” on page 394
“ARTANH Function” on page 395
ARSIN Function
Returns the arcsine.
Category: Trigonometric
Syntax
ARSIN (argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Range: between −1 and 1
Details
The ARSIN function returns the arcsine (inverse sine) of the argument. The value that
is returned is specified in radians.
Examples
SAS Statements
Results
x=arsin(0);
0
x=arsin(1);
1.5707963268
x=arsin(-0.5);
-0.523598776
394
ARSINH Function
4
Chapter 4
ARSINH Function
Returns the inverse hyperbolic sine.
Hyperbolic
Category:
Syntax
ARSINH(x)
Arguments
x
01 < x < 1
specifies a numeric constant, variable, or expression.
Range:
Details
01 < x < 1
The ARSINH function computes the inverse hyperbolic sine. The ARSINH function is
:
mathematically defined by the following equation, where
p
ARSINH (x) = log x + x2 + 1
Replace the infinity symbol with the largest double precision number that is
available on your machine.
Examples
The following example computes the inverse hyperbolic sine.
data _null_;
x=arsinh(5);
x1=arsinh(-5);
put x=;
put x1=;
run;
SAS writes the following output to the log:
x=2.3124383413
x1=-2.312438341
See Also
Functions:
“COSH Function” on page 592
“SINH Function” on page 1073
Functions and CALL Routines
4
ARTANH Function
“TANH Function” on page 1108
“ARCOSH Function” on page 392
“ARTANH Function” on page 395
ARTANH Function
Returns the inverse hyperbolic tangent.
Category: Hyperbolic
Syntax
ARTANH(x)
Arguments
x
specifies a numeric constant, variable, or expression.
Range: –1 < x < 1
Details
The ARTANH function computes the inverse hyperbolic tangent. The ARTANH
function is mathematically defined by the following equation, where –1 < x< 1:
ARTANH (x) = 2 log 1 0 xx
1
1+
Examples
The following example computes the inverse hyperbolic tangent.
data _null_;
x=artanh(0.5);
put x=;
run;
SAS writes the following output to the log:
x=0.5493061443
See Also
Functions:
“COSH Function” on page 592
“SINH Function” on page 1073
395
396
ATAN Function
4
Chapter 4
“TANH Function” on page 1108
“ARCOSH Function” on page 392
“ARSINH Function” on page 394
ATAN Function
Returns the arc tangent.
Category:
Trigonometric
Syntax
ATAN (argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The ATAN function returns the 2-quadrant arc tangent (inverse tangent) of the
argument. The value that is returned is the angle (in radians) whose tangent is x and
whose value ranges from -=2 to =2. If the argument is missing, then ATAN returns a
missing value.
Comparisons
The ATAN function is similar to the ATAN2 function except that ATAN2 calculates the
arc tangent of the angle from the ratio of two arguments rather than from one
argument.
Examples
SAS Statements
Results
x=atan(0);
0
x=atan(1);
0.7853981634
x=atan(-9.0);
-1.460139106
See Also
“ATAN2 Function” on page 397
Functions and CALL Routines
4
ATAN2 Function
397
ATAN2 Function
Returns the arc tangent of the ratio of two numeric variables.
Category: Trigonometric
Syntax
ATAN2(argument-1, argument-2)
Arguments
argument-1
specifies a numeric constant, variable, or expression.
argument-2
specifies a numeric constant, variable, or expression.
Details
The ATAN2 function returns the arc tangent (inverse tangent) of two numeric variables.
The result of this function is similar to the result of calculating the arc tangent of
argument-1 / argument-2, except that the signs of both arguments are used to
determine the quadrant of the result. ATAN2 returns the result in radians, which is a
value between - and . If either of the arguments in ATAN2 is missing, then ATAN2
returns a missing value.
Comparisons
The ATAN2 function is similar to the ATAN function except that ATAN calculates the
arc tangent of the angle from the value of one argument rather than from two
arguments.
Examples
SAS statements
Results
a=atan2(-1, 0.5);
-1.107148718
b=atan2(6,8);
0.6435011088
c=atan2(5,-3);
2.1112158271
See Also
Functions:
“ATAN Function” on page 396
398
ATTRC Function
4
Chapter 4
ATTRC Function
Returns the value of a character attribute for a SAS data set.
Category:
SAS File I/O
Syntax
ATTRC(data-set-id,attr-name)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
attr-name
is an attribute name. If attr-name is invalid, a missing value is returned.
Valid values for use with attr-name are:
CHARSET
returns a value for the character set of the computer that created the data set.
empty string
Data set not sorted
ASCII
ASCII character set
EBCDIC
EBCDIC character set
ANSI
OS/2 ANSI standard ASCII character set
OEM
OS/2 OEM code format
ENCRYPT
returns ’YES’ or ’NO’ depending on whether the SAS data set is encrypted.
ENGINE
returns the name of the engine that is used to access the data set.
LABEL
returns the label assigned to the data set.
LIB
returns the libref of the SAS library in which the data set resides.
MEM
returns the SAS data set name.
MODE
returns the mode in which the SAS data set was opened, such as:
I
INPUT mode allows random access if the engine supports it.
Otherwise, it defaults to IN mode.
IN
INPUT mode reads sequentially and allows revisiting
observations.
IS
INPUT mode reads sequentially but does not allow revisiting
observations.
Functions and CALL Routines
4
ATTRC Function
N
NEW mode creates a new data set.
U
UPDATE mode allows random access if the engine supports it.
Otherwise, it defaults to UN mode.
UN
UPDATE mode reads sequentially and allows revisiting
observations.
US
UPDATE mode reads sequentially but does not allow revisiting
observations.
V
UTILITY mode allows modification of variable attributes and
indexes associated with the data set.
399
MTYPE
returns the SAS library member type.
SORTEDBY
returns an empty string if the data set is not sorted. Otherwise, it returns the names
of the BY variables in the standard BY statement format.
SORTLVL
returns a value that indicates how a data set was sorted:
Empty string
Data set is not sorted.
WEAK
Sort order of the data set was established by the user (for
example, through the SORTEDBY data set option). The system
cannot validate its correctness, so the order of observations
cannot be depended on.
STRONG
Sort order of the data set was established by the software (for
example, through PROC SORT or the OUT= option in the
CONTENTS procedure).
SORTSEQ
returns an empty string if the data set is sorted on the native computer or if the sort
collating sequence is the default for the operating environment. Otherwise, it returns
the name of the alternate collating sequence used to sort the file.
TYPE
returns the SAS data set type.
Examples
3 This example generates a message if the SAS data set has not been opened in
INPUT SEQUENTIAL mode. The message is written to the SAS log as follows:
%let mode=%sysfunc(attrc(&dsid,MODE));
%if &mode ne IS %then
%put Data set has not been opened in INPUT SEQUENTIAL mode.;
3 This example tests whether a data set has been sorted and writes the result to the
SAS log.
data _null_;
dsid=open("sasdata.sortcars","i");
charset=attrc(dsid,"CHARSET");
if charset = "" then
put "Data set has not been sorted.";
else put "Data set sorted with " charset
"character set.";
400
ATTRN Function
4
Chapter 4
rc=close(dsid);
run;
See Also
Functions:
“ATTRN Function” on page 400
“OPEN Function” on page 939
ATTRN Function
Returns the value of a numeric attribute for a SAS data set.
Category:
SAS File I/O
Syntax
ATTRN(data-set-id,attr-name)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
attr-name
is the name of the SAS data set attribute whose numeric value is returned. If the
value of attr-name is invalid, a missing value is returned. The following is a list of
SAS data set attribute names and their values:
ALTERPW
specifies whether a password is required to alter the data set.
1
the data set is alter protected.
0
the data set is not alter protected.
ANOBS
specifies whether the engine knows the number of observations.
1
the engine knows the number of observations.
0
the engine does not know the number of observations.
ANY
specifies whether the data set has observations or variables.
−1
the data set has no observations or variables.
0
the data set has no observations.
1
the data set has observations and variables.
Alias: VAROBS
Functions and CALL Routines
4
ATTRN Function
401
ARAND
specifies whether the engine supports random access.
1
the engine supports random access.
0
the engine does not support random access.
Alias: RANDOM
ARWU
specifies whether the engine can manipulate files.
1
the engine is not read-only. It can create or update SAS files.
0
the engine is read-only.
AUDIT
specifies whether logging to an audit file is enabled.
1
logging is enabled.
0
logging is suspended.
AUDIT_DATA
specifies whether after-update record images are stored.
1
after-update record images are stored.
0
after-update record images are not stored.
AUDIT_BEFORE
specifies whether before-update record images are stored.
1
before-update record images are stored.
0
before-update record images are not stored.
AUDIT_ERROR
specifies whether unsuccessful after-update record images are stored.
1
unsuccessful after-update record images are stored.
0
unsuccessful after-update record images are not stored.
CRDTE
specifies the date that the data set was created. The value that is returned is the
internal SAS datetime value for the creation date.
Tip: Use the DATETIME. format to display this value.
ICONST
returns information about the existence of integrity constraints for a SAS data set.
0
no integrity constraints.
1
one or more general integrity constraints.
2
one or more referential integrity constraints.
3
both one or more general integrity constraints and one or more
referential integrity constraints.
INDEX
specifies whether the data set supports indexing.
1
indexing is supported.
0
indexing is not supported.
402
ATTRN Function
4
Chapter 4
ISINDEX
specifies whether the data set is indexed.
1
at least one index exists for the data set.
0
the data set is not indexed.
ISSUBSET
specifies whether the data set is a subset.
1
at least one WHERE clause is active.
0
no WHERE clause is active.
LRECL
specifies the logical record length.
LRID
specifies the length of the record ID.
MAXGEN
specifies the maximum number of generations.
MAXRC
specifies whether an application checks return codes.
1
an application checks return codes.
0
an application does not check return codes.
MODTE
specifies the last date and time that the data set was modified. The value returned
is the internal SAS datetime value.
Tip: Use the DATETIME. format to display this value.
NDEL
specifies the number of observations in the data set that are marked for deletion.
NEXTGEN
specifies the next generation number to generate.
NLOBS
specifies the number of logical observations (the observations that are not marked
for deletion). An active WHERE clause does not affect this number.
−1
the number of observations is not available.
NLOBSF
specifies the number of logical observations (the observations that are not marked
for deletion) by forcing each observation to be read and by taking the FIRSTOBS
system option, the OBS system option, and the WHERE clauses into account.
Tip: Passing NLOBSF to ATTRN requires the engine to read every observation
from the data set that matches the WHERE clause. Based on the file type and
file size, reading these observations can be a time-consuming process.
NOBS
specifies the number of physical observations (including the observations that are
marked for deletion). An active WHERE clause does not affect this number.
−1
the number of observations is not available.
NVARS
specifies the number of variables in the data set.
Functions and CALL Routines
4
ATTRN Function
403
PW
specifies whether a password is required to access the data set.
1
the data set is protected.
0
the data set is not protected.
RADIX
specifies whether access by observation number (radix addressability) is allowed.
1
access by observation number is allowed.
0
access by observation number is not allowed.
Note: A data set that is accessed by a tape engine is index addressable although it
cannot be accessed by an observation number.
READPW
specifies whether a password is required to read the data set.
1
the data set is read protected.
0
the data set is not read protected.
TAPE
specifies the status of the data set tape.
1
the data set is a sequential file.
0
the data set is not a sequential file.
WHSTMT
specifies the active WHERE clauses.
0
no WHERE clause is active.
1
a permanent WHERE clause is active.
2
a temporary WHERE clause is active.
3
both permanent and temporary WHERE clauses are active.
WRITEPW
specifies whether a password is required to write to the data set.
1
the data set is write protected.
0
the data set is not write protected.
Examples
3 This example checks whether a WHERE clause is currently active for a data set.
%let iswhere=%sysfunc(attrn(&dsid,whstmt));
%if &iswhere %then
%put A WHERE clause is currently active.;
3 This example checks whether a data set is indexed.
data _null_;
dsid=open("mydata");
isindex=attrn(dsid,"isindex");
if isindex then put "data set is indexed";
else put "data set is not indexed";
run;
404
BAND Function
4
Chapter 4
3 This example checks whether a data set is protected with a password.
data _null_;
dsid=open("mydata");
pw=attrn(dsid,"pw");
if pw then put "data set is protected";
run;
See Also
Functions:
“ATTRC Function” on page 398
“OPEN Function” on page 939
BAND Function
Returns the bitwise logical AND of two arguments.
Category:
Bitwise Logical Operations
Syntax
band(argument-1,argument-2)
Arguments
argument-1, argument-2
specifies a numeric constant, variable, or expression.
32
Range: between 0 and (2 )-1 inclusive
Details
If either argument contains a missing value, then the function returns a missing value
and sets _ERROR_ equal to 1.
Examples
SAS Statements
Results
x=band(0Fx,05x);
put x=hex.;
x=00000005
Functions and CALL Routines
4
BETA Function
Returns the value of the beta function.
Category: Mathematical
Syntax
BETA(a,b)
Arguments
a
is the first shape parameter, where a>0.
b
is the second shape parameter, where b>0.
Details
The BETA function is mathematically given by the equation
(a; b) =
Z
1
0
x
a01
(1
0 x) b 0 1 dx
with a>0, b>0. It should be noted that
(a; b) =
0 ( a) 0 ( b)
0 ( a + b)
where 0 (:) is the gamma function.
If the expression cannot be computed, BETA returns a missing value.
Examples
SAS Statements
Results
x=beta(5,3);
0.9523809524e-2
See Also
Function:
“LOGBETA Function” on page 869
BETA Function
405
406
BETAINV Function
4
Chapter 4
BETAINV Function
Returns a quantile from the beta distribution.
Quantile
Category:
Syntax
BETAINV (p,a,b)
Arguments
p
is a numeric probability.
0≤p≤1
Range:
a
is a numeric shape parameter.
a>0
Range:
b
is a numeric shape parameter.
b>0
Range:
Details
The BETAINV function returns the pth quantile from the beta distribution with shape
parameters a and b. The probability that an observation from a beta distribution is less
than or equal to the returned quantile is p.
Note:
BETAINV is the inverse of the PROBBETA function.
Examples
SAS Statements
Results
x=betainv(0.001,2,4);
0.0101017879
See Also
Functions:
“QUANTILE Function” on page 1017
4
Functions and CALL Routines
4
BLACKCLPRC Function
407
BLACKCLPRC Function
Calculates call prices for European options on futures, based on the Black model.
Category: Financial
Syntax
BLACKCLPRC(E, t, F, r, sigma)
Arguments
E
is a non-missing, positive value that specifies exercise price.
Requirement:
Specify E and F in the same units.
t
is a non-missing value that specifies time to maturity.
F
is a non-missing, positive value that specifies future price.
Requirement:
Specify F and E in the same units.
r
is a non-missing, positive fraction that specifies the risk-free interest rate between
the present time and t.
Requirement:
Specify a value for r for the same time period as the unit of t.
sigma
is a non-missing, positive fraction that specifies the volatility (the square root of the
variance of r).
Requirement:
Specify a value for sigma for the same time period as the unit of t.
Details
The BLACKCLPRC function calculates call prices for European options on futures,
based on the Black model. The function is based on the following relationship:
CALL = e0rt (F N (d1 ) 0 EN (d2 ))
where
F
specifies future price.
N
specifies the cumulative normal density function.
E
specifies the exercise price of the option.
r
specifies the risk-free interest rate for period t.
t
specifies the time to expiration.
408
4
BLACKCLPRC Function
Chapter 4
0 1 2 ln F + t
E
pt
=
p
d2 = d1 0 t
d1
2
where
specifies the volatility of the underlying asset.
2
specifies the variance of the rate of return.
For the special case of t=0, the following equation is true:
CALL = max ((F
0 E ) ; 0)
For information about the basics of pricing, see “Using Pricing Functions” on page
302.
Comparisons
The BLACKCLPRC function calculates call prices for European options on futures,
based on the Black model. The BLACKPTPRC function calculates put prices for
European options on futures, based on the Black model. These functions return a scalar
value.
Examples
SAS Statements
Results
----+----1----+-----2--
a=blackclprc(1000, .5, 950, 4, 2);
put a;
65.335687119
b=blackclprc(850, 2.5, 125, 3, 1);
put b;
0.012649067
c=blackclprc(7500, .9, 950, 3, 2);
put c;
17.880939441
d=blackclprc(5000, -.5, 237, 3, 2);
put d;
See Also
Function:
“BLACKPTPRC Function” on page 409
0
Functions and CALL Routines
4
BLACKPTPRC Function
409
BLACKPTPRC Function
Calculates put prices for European options on futures, based on the Black model.
Category: Financial
Syntax
BLACKPTPRC(E, t, F, r, sigma)
Arguments
E
is a non-missing, positive value that specifies exercise price.
Requirement:
Specify E and F in the same units.
t
is a non-missing value that specifies time to maturity.
F
is a non-missing, positive value that specifies future price.
Requirement:
Specify F and E in the same units.
r
is a non-missing, positive fraction that specifies the risk-free interest rate between
the present time and t.
Requirement:
Specify a value for r for the same time period as the unit of t.
sigma
is a non-missing, positive fraction that specifies the volatility (the square root of the
variance of r).
Requirement:
Specify a value for sigma for the same time period as the unit of t.
Details
The BLACKPTPRC function calculates put prices for European options on futures,
based on the Black model. The function is based on the following relationship:
PUT = CALL + e0rt (E 0 F )
where
E
specifies the exercise price of the option.
r
specifies the risk-free interest rate for period t.
t
specifies the time to expiration.
F
specifies future price.
410
BLKSHCLPRC Function
4
Chapter 4
0 1 2 ln F + t
E
pt
=
p
d2 = d1 0 t
d1
2
where
2
specifies the volatility of the underlying asset.
specifies the variance of the rate of return.
For the special case of t=0, the following equation is true:
PUT = max ((E
0 F ) ; 0)
For information about the basics of pricing, see “Using Pricing Functions” on page
302.
Comparisons
The BLACKPTPRC function calculates put prices for European options on futures,
based on the Black model. The BLACKCLPRC function calculates call prices for
European options on futures, based on the Black model. These functions return a scalar
value.
Examples
SAS Statements
Results
----+----1----+-----2--
a=blackptprc(1000, .5, 950, 4, 2);
put a;
72.102451281
b=blackptprc(850, 2.5, 125, 3, 1);
put b;
0.4136352354
c=blackptprc(7500, .9, 950, 3, 2);
put c;
458.07704789
d=blackptprc(5000, -.5, 237, 3, 2);
put d;
0
See Also
Function:
“BLACKCLPRC Function” on page 407
BLKSHCLPRC Function
Calculates call prices for European options on stocks, based on the Black-Scholes model.
Functions and CALL Routines
4
BLKSHCLPRC Function
411
Category: Financial
Syntax
BLKSHCLPRC(E, t, S, r, sigma)
Arguments
E
is a non-missing, positive value that specifies the exercise price.
Requirement:
Specify E and S in the same units.
t
is a non-missing value that specifies the time to maturity.
S
is a non-missing, positive value that specifies the share price.
Requirement:
Specify S and E in the same units.
r
is a non-missing, positive fraction that specifies the risk-free interest rate for period t.
Requirement:
Specify a value for r for the same time period as the unit of t.
sigma
is a non-missing, positive fraction that specifies the volatility of the underlying asset.
Requirement:
Specify a value for sigma for the same time period as the unit of t.
Details
The BLKSHCLPRC function calculates the call prices for European options on stocks,
based on the Black-Scholes model. The function is based on the following relationship:
CALL = SN (d1 ) 0 EN (d2 ) e0rt
where
S
is a non-missing, positive value that specifies the share price.
N
specifies the cumulative normal density function.
E
is a non-missing, positive value that specifies the exercise price of
the option.
d1 =
d2
=
0S 1 2
ln
E + r+ 2 t
d1
0
p
pt
t
where
t
specifies the time to expiration.
412
BLKSHPTPRC Function
4
Chapter 4
r
specifies the risk-free interest rate for period t.
2
specifies the volatility (the square root of the variance).
specifies the variance of the rate of return.
For the special case of t=0, the following equation is true:
CALL = max ((S 0 E ) ; 0)
For information about the basics of pricing, see “Using Pricing Functions” on page
302.
Comparisons
The BLKSHCLPRC function calculates the call prices for European options on stocks,
based on the Black-Scholes model. The BLKSHPTPRC function calculates the put
prices for European options on stocks, based on the Black-Scholes model. These
functions return a scalar value.
Examples
SAS Statements
Results
----+----1----+-----2--
a=blkshclprc(1000, .5, 950, 4, 2);
put a;
831.05008469
b=blkshclprc(850, 2.5, 125, 3, 1);
put b;
124.53035232
c=blkshclprc(7500, .9, 950, 3, 2);
put c;
719.40891129
d=blkshclprc(5000, -.5, 237, 3, 2);
put d;
0
See Also
Function:
“BLKSHPTPRC Function” on page 412
BLKSHPTPRC Function
Calculates put prices for European options on stocks, based on the Black-Scholes model.
Category:
Financial
Functions and CALL Routines
4
BLKSHPTPRC Function
413
Syntax
BLKSHPTPRC(E, t, S, r, sigma)
Arguments
E
is a non-missing, positive value that specifies the exercise price.
Requirement:
Specify E and S in the same units.
t
is a non-missing value that specifies the time to maturity.
S
is a non-missing, positive value that specifies the share price.
Requirement:
Specify S and E in the same units.
r
is a non-missing, positive fraction that specifies the risk-free interest rate for period t.
Requirement:
Specify a value for r for the same time period as the unit of t.
sigma
is a non-missing, positive fraction that specifies the volatility of the underlying asset.
Requirement:
Specify a value for sigma for the same time period as the unit of t.
Details
The BLKSHPTPRC function calculates the put prices for European options on stocks,
based on the Black-Scholes model. The function is based on the following relationship:
PUT = CALL 0 S + Ee0rt
where
S
is a non-missing, positive value that specifies the share price.
E
is a non-missing, positive value that specifies the exercise price of
the option.
d1 =
d2
ln
0S 1
+ r + 2
E
= d1 0 p
p
t
2
t
t
where
t
specifies the time to expiration.
r
specifies the risk-free interest rate for period t.
specifies the volatility (the square root of the variance).
2
specifies the variance of the rate of return.
414
BLSHIFT Function
4
Chapter 4
For the special case of t=0, the following equation is true:
PUT = max ((E 0 S ) ; 0)
For information about the basics of pricing, see “Using Pricing Functions” on page
302.
Comparisons
The BLKSHPTPRC function calculates the put prices for European options on stocks,
based on the Black-Scholes model. The BLKSHCLPRC function calculates the call
prices for European options on stocks, based on the Black-Scholes model. These
functions return a scalar value.
Examples
SAS Statements
Results
----+----1----+-----2--
a=blkshptprc(1000, .5, 950, 4, 2);
put a;
16.385367922
b=blkshptprc(850, 1.2, 125, 3, 1);
put b;
1.426971358
c=blkshptprc(7500, .9, 950, 3, 2);
put c;
273.45025684
d=blkshptprc(5000, -.5, 237, 3, 2);
put d;
See Also
Function:
“BLKSHCLPRC Function” on page 410
BLSHIFT Function
Returns the bitwise logical left shift of two arguments.
Category:
Bitwise Logical Operations
Syntax
BLSHIFT(argument-1,argument-2)
0
Functions and CALL Routines
4
BNOT Function
415
Arguments
argument-1
specifies a numeric constant, variable, or expression.
32
Range: between 0 and (2 )-1 inclusive
argument-2
specifies a numeric constant, variable, or expression.
Range: 0 to 31, inclusive
Details
If either argument contains a missing value, then the function returns a missing value
and sets _ERROR_ equal to 1.
Examples
SAS Statements
Results
x=blshift(07x,2);
put x=hex.;
x=0000001C
BNOT Function
Returns the bitwise logical NOT of an argument.
Category: Bitwise Logical Operations
Syntax
BNOT(argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
32
Range: between 0 and (2 )-1 inclusive
Details
If the argument contains a missing value, then the function returns a missing value
and sets _ERROR_ equal to 1.
416
BOR Function
4
Chapter 4
Examples
SAS Statements
Results
x=bnot(0F000000Fx);
put x=hex.;
x=0FFFFFF0
BOR Function
Returns the bitwise logical OR of two arguments.
Category:
Bitwise Logical Operations
Syntax
BOR(argument-1,argument-2)
Arguments
argument-1, argument-2
specifies a numeric constant, variable, or expression.
Range:
32
between 0 and (2 )-1 inclusive
Details
If either argument contains a missing value, then the function returns a missing value
and sets _ERROR_ equal to 1.
Examples
SAS Statements
Results
x=bor(01x,0F4x);
put x=hex.;
x=000000F5
BRSHIFT Function
Returns the bitwise logical right shift of two arguments.
Category:
Bitwise Logical Operations
Functions and CALL Routines
4
BXOR Function
417
Syntax
BRSHIFT(argument-1, argument-2)
Arguments
argument-1
specifies a numeric constant, variable, or expression.
32
Range: between 0 and (2 )-1 inclusive
argument-2
specifies a numeric constant, variable, or expression.
Range: 0 to 31, inclusive
Details
If either argument contains a missing value, then the function returns a missing value
and sets _ERROR_ equal to 1.
Examples
SAS Statements
Results
x=brshift(01Cx,2);
put x=hex.;
x=00000007
BXOR Function
Returns the bitwise logical EXCLUSIVE OR of two arguments.
Category: Bitwise Logical Operations
Syntax
BXOR(argument-1, argument-2)
Arguments
argument-1, argument-2
specifies a numeric constant, variable, or expression.
32
Range: between 0 and (2 )-1 inclusive
Details
If either argument contains a missing value, then the function returns a missing value
and sets _ERROR_ equal to 1.
418
BYTE Function
4
Chapter 4
Examples
SAS Statements
Results
x=bxor(03x,01x);
put x=hex.;
x=00000002
BYTE Function
Returns one character in the ASCII or the EBCDIC collating sequence.
Character
Restriction: “I18N Level 0” on page 304
See: BYTE Function in the documentation for your operating environment.
Category:
Syntax
BYTE (n)
Arguments
n
specifies an integer that represents a specific ASCII or EBCDIC character.
Range: 0–255
Details
Length of Returned Variable
In a DATA step, if the BYTE function returns a value to
a variable that has not previously been assigned a length, then that variable is
assigned a length of 1.
ASCII and EBCDIC Collating Sequences
For EBCDIC collating sequences, n is between
0 and 255. For ASCII collating sequences, the characters that correspond to values
between 0 and 127 represent the standard character set. Other ASCII characters that
correspond to values between 128 and 255 are available on certain ASCII operating
environments, but the information those characters represent varies with the operating
environment.
Functions and CALL Routines
4
CALL ALLCOMB Routine
419
Examples
SAS Statements
Results
x=byte(80);
put x;
ASCII
EBCDIC
----+----1----+----2
----+----1----+----2
P
&
See Also
Functions:
“COLLATE Function” on page 567
“RANK Function” on page 1036
CALL ALLCOMB Routine
Generates all combinations of the values of n variables taken k at a time in a minimal change
order.
Category: Combinatorial
Syntax
CALL ALLCOMB(count, k, variable-1, …, variable-n);
Arguments
count
specifies an integer variable that is assigned from 1 to the number of combinations in
a loop.
k
specifies an integer constant, variable, or expression between 1 and n, inclusive, that
specifies the number of items in each combination.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted.
Requirement:
Initialize these variables before calling the ALLCOMB routine.
Restriction: Specify no more than 33 items. If you need to find combinations of
more than 33 items, use the CALL ALLCOMBI routine.
After calling the ALLCOMB routine, the first k variables contain the values in
one combination.
Tip:
420
CALL ALLCOMB Routine
4
Chapter 4
Details
CALL ALLCOMB Processing
Use the CALL ALLCOMB routine in a loop where the
first argument to CALL ALLCOMB accepts each integral value from 1 to the number of
combinations, and where k is constant. The number of combinations can be computed by
using the COMB function. On the first call, the argument types and lengths are checked
for consistency. On each subsequent call, the values of two variables are interchanged.
If you call the ALLCOMB routine with the first argument out of sequence, the
results are not useful. In particular, if you initialize the variables and then immediately
th
call ALLCOMB with a first argument of j, then you will not get the j combination
th
(except when j is 1). To get the j combination, you must call ALLCOMB j times, with
the first argument taking values from 1 through j in that exact order.
Using the CALL ALLCOMB Routine with Macros
You can call the ALLCOMB routine
when you use the %SYSCALL macro. In this case, the variable arguments are not
required to be the same type or length. If %SYSCALL identifies an argument as
numeric, then %SYSCALL reformats the returned value.
If an error occurs during the execution of the CALL ALLCOMB routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 0 if count=1
3 j if the values of variable-j and variable-k were interchanged, where j<k
3 –1 if no values were interchanged because all distinct combinations were already
generated
Comparisons
SAS provides four functions or CALL routines for generating combinations:
3 ALLCOMB generates all possible combinations of the values, missing or
non-missing, of n variables. The values can be any numeric or character values.
Each combination is formed from the previous combination by removing one value
and inserting another value.
3 LEXCOMB generates all distinct combinations of the non-missing values of several
variables. The values can be any numeric or character values. The combinations
are generated in lexicographic order.
3 ALLCOMBI generates all combinations of the indices of n items, where indices are
integers from 1 to n. Each combination is formed from the previous combination
by removing one index and inserting another index.
3 LEXCOMBI generates all combinations of the indices of n items, where indices are
integers from 1 to n. The combinations are generated in lexicographic order.
ALLCOMBI is the fastest of these functions and CALL routines. LEXCOMB is the
slowest.
Examples
Example 1: Using CALL ALLCOMB in a DATA Step
The following is an example of the
CALL ALLCOMB routine that is used with the DATA step.
data _null_;
array x[5] $3 (’ant’ ’bee’ ’cat’ ’dog’ ’ewe’);
Functions and CALL Routines
4
CALL ALLCOMB Routine
421
n=dim(x);
k=3;
ncomb=comb(n,k);
do j=1 to ncomb+1;
call allcomb(j, k, of x[*]);
put j 5. +3 x1-x3;
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
ant
ant
ant
ant
ant
ant
bee
bee
bee
dog
dog
bee
bee
bee
cat
cat
dog
dog
dog
ewe
ewe
ewe
cat
ewe
dog
dog
ewe
ewe
ewe
cat
cat
cat
cat
Example 2: Using CALL ALLCOMB with Macros and Displaying the Return Code
The
following is an example of the CALL ALLCOMB routine that is used with macros. The
output includes values for the %SYSINFO macro.
%macro test;
%let x1=ant;
%let x2=-.1234;
%let x3=1e10;
%let x4=hippopotamus;
%let x5=zebra;
%let k=2;
%let ncomb=%sysfunc(comb(5,&k));
%do j=1 %to &ncomb+1;
%syscall allcomb(j, k, x1, x2, x3, x4, x5);
%let jfmt=%qsysfunc(putn(&j,5.));
%let pad=%qsysfunc(repeat(%str(),30-%length(&x1 &x2)));
%put &jfmt: &x1 &x2 &pad sysinfo=&sysinfo;
%end;
%mend;
%test
SAS writes the following output to the log:
1: ant -0.1234 sysinfo=0
2: ant zebra sysinfo=2
3: ant hippopotamus sysinfo=2
4: ant 10000000000 sysinfo=2
5: -0.1234 10000000000 sysinfo=1
6: -0.1234 zebra sysinfo=2
7: -0.1234 hippopotamus sysinfo=2
8: 10000000000 hippopotamus sysinfo=1
9: 10000000000 zebra sysinfo=2
422
4
CALL ALLCOMBI Routine
10:
11:
Chapter 4
hippopotamus zebra
hippopotamus zebra
sysinfo=1
sysinfo=-1
See Also
Functions and CALL Routines:
“ALLCOMB Function” on page 364
CALL ALLCOMBI Routine
Generates all combinations of the indices of n objects taken k at a time in a minimal change order.
Category:
Combinatorial
Syntax
CALL ALLCOMBI(N, K, index-1, …, index-K, <, index-added, index-removed>);
Arguments
N
is a numeric constant, variable, or expression that specifies the total number of
objects.
K
is a numeric constant, variable, or expression that specifies the number of objects in
each combination.
index
is a numeric variable that contains indices of the objects in the returned
combination. Indices are integers between 1 and N inclusive.
Tip: If index-1 is missing or zero, then ALLCOMBI initializes the indices to
index-1=1 through index-K=K. Otherwise, ALLCOMBI creates a new combination
by removing one index from the combination and adding another index.
index-added
is a numeric variable in which ALLCOMBI returns the value of the index that was
added.
index-removed
is a numeric variable in which ALLCOMBI returns the value of the index that was
removed.
Details
CALL ALLCOMBI Processing
Before you make the first call to ALLCOMBI, complete
one of the following tasks:
3 Set index-1 equal to zero or to a missing value.
Functions and CALL Routines
4
CALL ALLCOMBI Routine
423
3 Initialize index-1 through index-K to distinct integers between 1 and N inclusive.
The number of combinations of N objects taken K at a time can be computed as
COMB(N, K). To generate all combinations of N objects taken K at a time, call
ALLCOMBI in a loop that executes COMB(N, K) times.
Using the CALL ALLCOMBI Routine with Macros
If you call ALLCOMBI from the
macro processor with %SYSCALL, then you must initialize all arguments to numeric
values. &SYSCALL reformats the values that are returned.
If an error occurs during the execution of the CALL ALLCOMBI routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR and &SYSINFO are set to zero.
Comparisons
The CALL ALLCOMBI routine generates all combinations of the indices of N objects
taken K at a time in a minimal change order. The CALL ALLCOMB routine generates
all combinations of the values of N variables taken K at a time in a minimal change
order.
Examples
Example 1: Using CALL ALLCOMBI in a DATA Step
The following is an example of the
CALL ALLCOMBI routine that is used in a DATA step.
data _null_;
array x[5] $3 (’ant’ ’bee’ ’cat’ ’dog’ ’ewe’);
array c[3] $3;
array i[3];
n=dim(x);
k=dim(i);
i[1]=0;
ncomb=comb(n,k);
/* The one extra call goes back */
do j=1 to ncomb+1; /* to the first combination. */
call allcombi(n, k, of i[*], add, remove);
do h=1 to k;
c[h]=x[i[h]];
end;
put @4 j= @10 ’i= ’ i[*] +3 ’c= ’ c[*] +3 add= remove=;
end;
run;
SAS writes the following output to the log:
j=1
j=2
j=3
j=4
j=5
j=6
j=7
j=8
j=9
i=
i=
i=
i=
i=
i=
i=
i=
i=
1
1
2
1
1
2
3
1
2
2
3
3
2
4
4
4
3
3
3
4
4
4
5
5
5
5
5
c=
c=
c=
c=
c=
c=
c=
c=
c=
ant
ant
bee
ant
ant
bee
cat
ant
bee
bee
cat
cat
bee
dog
dog
dog
cat
cat
cat
dog
dog
dog
ewe
ewe
ewe
ewe
ewe
add=0
add=4
add=2
add=1
add=5
add=2
add=3
add=1
add=2
remove=0
remove=2
remove=1
remove=3
remove=2
remove=1
remove=2
remove=4
remove=1
424
4
CALL ALLPERM Routine
j=10
j=11
Chapter 4
i= 1 2 5
i= 1 2 3
c= ant bee ewe
c= ant bee cat
add=1 remove=3
add=3 remove=5
Example 2: Using CALL ALLCOMBI with Macros
The following is an example of the
CALL ALLCOMBI routine that is used with macros.
%macro test;
%let x1=0;
%let x2=0;
%let x3=0;
%let add=0;
%let remove=0;
%let n=5;
%let k=3;
%let ncomb=%sysfunc(comb(&n,&k));
%do j=1 %to &ncomb;
%syscall allcombi(n,k,x1,x2,x3,add,remove);
%let jfmt=%qsysfunc(putn(&j,5.));
%put &jfmt: &x1 &x2 &x3 add=&add remove=&remove;
%end;
%mend;
%test
SAS writes the following output to the log:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
1
1
2
1
1
2
3
1
2
1
2
3
3
2
4
4
4
3
3
2
3
4
4
4
5
5
5
5
5
5
add=0
add=4
add=2
add=1
add=5
add=2
add=3
add=1
add=2
add=1
remove=0
remove=2
remove=1
remove=3
remove=2
remove=1
remove=2
remove=4
remove=1
remove=3
Examples
See Also
Functions and CALL Routines:
“CALL ALLCOMB Routine” on page 419
CALL ALLPERM Routine
Generates all permutations of the values of several variables in a minimal change order.
Category:
Combinatorial
Functions and CALL Routines
4
CALL ALLPERM Routine
425
Syntax
CALL ALLPERM(count, variable–1< , variable–2 ...>);
Arguments
count
specifies an integer variable that ranges from 1 to the number of permutations.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted.
Requirement:
Initialize these variables before you call the ALLPERM routine.
Restriction: Specify no more than 18 variables.
Details
CALL ALLPERM Processing
Use the CALL ALLPERM routine in a loop where the first
argument to CALL ALLPERM takes each integral value from 1 to the number of
permutations. On the first call, the argument types and lengths are checked for
consistency. On each subsequent call, the values of two consecutive variables are
interchanged.
Note: You can compute the number of permutations by using the PERM function.
See “PERM Function” on page 964 for more information. 4
If you call the ALLPERM routine and the first argument is out of sequence, the
results are not useful. In particular, if you initialize the variables and then immediately
call the ALLPERM routine with a first argument of K, your result will not be the Kth
permutation (except when K is 1). To get the Kth permutation, you must call the
ALLPERM routine K times, with the first argument taking values from 1 through K in
that exact order.
ALLPERM always produces N! permutations even if some of the variables have
equal values or missing values. If you want to generate only the distinct permutations
when there are equal values, or if you want to omit missing values from the
permutations, use the LEXPERM function instead.
Using the CALL ALLPERM Routine with Macros
You can call the ALLPERM routine
when you use the %SYSCALL macro. In this case, the variable arguments are not
required to be the same type or length. If %SYSCALL identifies an argument as
numeric, then %SYSCALL reformats the returned value.
If an error occurs during the execution of the CALL ALLPERM routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than -100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 0 if count=1
3 J if 1<count<=N! and the values of variable-J and variable-K were interchanged,
where J+1=K
3 -1 if count>N!
426
CALL ALLPERM Routine
4
Chapter 4
Comparisons
SAS provides three functions or CALL routines for generating all permutations:
3 ALLPERM generates all possible permutations of the values, missing or
nonmissing, of several variables. Each permutation is formed from the previous
permutation by interchanging two consecutive values.
3 LEXPERM generates all distinct permutations of the nonmissing values of several
variables. The permutations are generated in lexicographic order.
3 LEXPERK generates all distinct permutations of K of the nonmissing values of N
variables. The permutations are generated in lexicographic order.
ALLPERM is the fastest of these functions and CALL routines. LEXPERK is the
slowest.
Examples
Example 1: Using CALL ALLPERM in a DATA Step
The following example generates
permutations of given values by using the CALL ALLPERM routine.
data _null_;
array x [4] $3 (’ant’ ’bee’ ’cat’ ’dog’);
n=dim(x);
nfact=fact(n);
do i=1 to nfact;
call allperm(i, of x[*]);
put i 5. +2 x[*];
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ant
ant
ant
dog
dog
ant
ant
ant
cat
cat
cat
dog
dog
cat
cat
cat
bee
bee
bee
dog
dog
bee
bee
bee
bee
bee
dog
ant
ant
dog
cat
cat
ant
ant
dog
cat
cat
dog
bee
bee
cat
cat
dog
bee
bee
dog
ant
ant
cat
dog
bee
bee
cat
cat
dog
bee
bee
dog
ant
ant
bee
bee
dog
ant
ant
dog
cat
cat
ant
ant
dog
cat
dog
cat
cat
cat
bee
bee
bee
dog
dog
bee
bee
bee
ant
ant
ant
dog
dog
ant
ant
ant
cat
cat
cat
dog
Functions and CALL Routines
4
Example 2: Using CALL ALLPERM with Macros
CALL ALLPERM Routine
427
The following is an example of the
CALL ALLPERM routine that is used with macros. The output includes values for the
%SYSINFO macro.
%macro test;
%let x1=ant;
%let x2=-.1234;
%let x3=1e10;
%let x4=hippopotamus;
%let nperm=%sysfunc(perm(4));
%do j=1 %to &nperm+1;
%syscall allperm(j, x1, x2, x3, x4);
%let jfmt=%qsysfunc(putn(&j,5.));
%put &jfmt:
&x1 &x2 &x3 &x4 sysinfo=&sysinfo;
%end;
%mend;
%test;
SAS writes the following output to the log:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
ant -0.1234 10000000000 hippopotamus
ant -0.1234 hippopotamus 10000000000
ant hippopotamus -0.1234 10000000000
hippopotamus ant -0.1234 10000000000
hippopotamus ant 10000000000 -0.1234
ant hippopotamus 10000000000 -0.1234
ant 10000000000 hippopotamus -0.1234
ant 10000000000 -0.1234 hippopotamus
10000000000 ant -0.1234 hippopotamus
10000000000 ant hippopotamus -0.1234
10000000000 hippopotamus ant -0.1234
hippopotamus 10000000000 ant -0.1234
hippopotamus 10000000000 -0.1234 ant
10000000000 hippopotamus -0.1234 ant
10000000000 -0.1234 hippopotamus ant
10000000000 -0.1234 ant hippopotamus
-0.1234 10000000000 ant hippopotamus
-0.1234 10000000000 hippopotamus ant
-0.1234 hippopotamus 10000000000 ant
hippopotamus -0.1234 10000000000 ant
hippopotamus -0.1234 ant 10000000000
-0.1234 hippopotamus ant 10000000000
-0.1234 ant hippopotamus 10000000000
-0.1234 ant 10000000000 hippopotamus
-0.1234 ant 10000000000 hippopotamus
See Also
Functions and CALL Routines:
“LEXPERM Function” on page 859
“ALLPERM Function” on page 366
“CALL RANPERK Routine” on page 488
“CALL RANPERM Routine” on page 490
sysinfo=0
sysinfo=3
sysinfo=2
sysinfo=1
sysinfo=3
sysinfo=1
sysinfo=2
sysinfo=3
sysinfo=1
sysinfo=3
sysinfo=2
sysinfo=1
sysinfo=3
sysinfo=1
sysinfo=2
sysinfo=3
sysinfo=1
sysinfo=3
sysinfo=2
sysinfo=1
sysinfo=3
sysinfo=1
sysinfo=2
sysinfo=3
sysinfo=-1
428
CALL CATS Routine
4
Chapter 4
CALL CATS Routine
Removes leading and trailing blanks, and returns a concatenated character string.
Category:
Character
Syntax
CALL CATS(result <, item-1, …, item-n>);
Arguments
result
specifies a character variable.
Restriction: The CALL CATS routine accepts only a character variable as a valid
argument for result. Do not use a constant or a SAS expression because CALL
CATS is unable to update these arguments.
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string using the BESTw. format.
In this case, SAS does not write a note to the log.
Details
The CALL CATS routine returns the result in the first argument, result. The routine
appends the values of the arguments that follow to result. If the length of result is not
large enough to contain the entire result, SAS does the following:
3 writes a warning message to the log stating that the result was truncated
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation, except in SQL or in a WHERE clause
3 sets _ERROR_ to 1 in the DATA step, except in a WHERE clause
The CALL CATS routine removes leading and trailing blanks from numeric
arguments after it formats the numeric value with the BESTw. format.
Comparisons
The results of the CALL CATS, CALL CATT, and CALL CATX routines are usually
equivalent to statements that use the concatenation operator (||) and the TRIM and
LEFT functions. However, using the CALL CATS, CALL CATT, and CALL CATX
routines is faster than using TRIM and LEFT.
The following table shows statements that are equivalent to CALL CATS, CALL
CATT, and CALL CATX. The variables X1 through X4 specify character variables, and
SP specifies a separator, such as a blank or comma.
Functions and CALL Routines
4
CALL CATS Routine
429
CALL Routine
Equivalent Statement
CALL CATS(OF X1-X4);
X1=TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4));
CALL CATT(OF X1-X4);
X1=TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4);
CALL CATX(SP, OF X1-X4); *
X1=TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4));
* If any of the arguments is blank, the results that are produced by CALL CATX differ slightly from
the results that are produced by the concatenated code. In this case, CALL CATX omits the
corresponding separator. For example, CALL CATX("+","X"," ", "Z"," "); produces
X+Z.
Examples
The following example shows how the CALL CATS routine concatenates strings.
data _null_;
length answer $ 36;
x=’Athens is t ’;
y=’ he Olym
’;
z=’
pic site for 2004. ’;
call cats(answer,x,y,z);
put answer;
run;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
Athens is the Olympic site for 2004.
See Also
Functions and CALL Routines:
“CALL CATT Routine” on page 430
“CALL CATX Routine” on page 432
“CAT Function” on page 526
“CATQ Function” on page 528
“CATS Function” on page 532
“CATT Function” on page 534
“CATX Function” on page 537
430
CALL CATT Routine
4
Chapter 4
CALL CATT Routine
Removes trailing blanks, and returns a concatenated character string.
Category:
Character
Syntax
CALL CATT(result <, item-1, … item-n>);
Arguments
result
specifies a character variable.
Restriction: The CALL CATT routine accepts only a character variable as a valid
argument for result. Do not use a constant or a SAS expression because CALL
CATT is unable to update these arguments.
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string using the BESTw. format.
In this case, leading blanks are removed and SAS does not write a note to the log.
Details
The CALL CATT routine returns the result in the first argument, result. The routine
appends the values of the arguments that follow to result. If the length of result is not
large enough to contain the entire result, SAS does the following:
3 writes a warning message to the log stating that the result was truncated
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation, except in SQL or in a WHERE clause
3 sets _ERROR_ to 1 in the DATA step, except in a WHERE clause
The CALL CATT routine removes leading and trailing blanks from numeric
arguments after it formats the numeric value with the BESTw. format.
Comparisons
The results of the CALL CATS, CALL CATT, and CALL CATX routines are usually
equivalent to statements that use the concatenation operator (||) and the TRIM and
LEFT functions. However, using the CALL CATS, CALL CATT, and CALL CATX
routines is faster than using TRIM and LEFT.
The following table shows statements that are equivalent to CALL CATS, CALL
CATT, and CALL CATX. The variables X1 through X4 specify character variables, and
SP specifies a separator, such as a blank or comma.
Functions and CALL Routines
4
CALL CATT Routine
431
CALL Routine
Equivalent Statement
CALL CATS(OF X1-X4);
X1=TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4));
CALL CATT(OF X1-X4);
X1=TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4);
CALL CATX(SP, OF X1-X4); *
X1=TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4));
* If any of the arguments is blank, the results that are produced by CALL CATX differ slightly from
the results that are produced by the concatenated code. In this case, CALL CATX omits the
corresponding separator. For example, CALL CATX("+","X"," ", "Z"," "); produces
X+Z.
Examples
The following example shows how the CALL CATT routine concatenates strings.
data _null_;
length answer $ 36;
x=’Athens is t ’;
y=’he Olym
’;
z=’pic site for 2004. ’;
call catt(answer,x,y,z);
put answer;
run;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4
Athens is the Olympic site for 2004.
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATX Routine” on page 432
“CAT Function” on page 526
“CATQ Function” on page 528
“CATS Function” on page 532
“CATT Function” on page 534
“CATX Function” on page 537
432
CALL CATX Routine
4
Chapter 4
CALL CATX Routine
Removes leading and trailing blanks, inserts delimiters, and returns a concatenated character
string.
Category:
Character
Syntax
CALL CATX(delimiter, result<, item-1 , … item-n>);
Arguments
delimiter
specifies a character string that is used as a delimiter between concatenated strings.
result
specifies a character variable.
Restriction: The CALL CATX routine accepts only a character variable as a valid
argument for result. Do not use a constant or a SAS expression because CALL
CATX is unable to update these arguments.
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string using the BESTw. format.
In this case, SAS does not write a note to the log.
Details
The CALL CATX routine returns the result in the second argument, result. The routine
appends the values of the arguments that follow to result. If the length of result is not
large enough to contain the entire result, SAS does the following:
3 writes a warning message to the log stating that the result was truncated
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation, except in SQL or in a WHERE clause
3 sets _ERROR_ to 1 in the DATA step, except in a WHERE clause
The CALL CATX routine removes leading and trailing blanks from numeric
arguments after formatting the numeric value with the BESTw. format.
Comparisons
The results of the CALL CATS, CALL CATT, and CALL CATX routines are usually
equivalent to statements that use the concatenation operator (||) and the TRIM and
LEFT functions. However, using the CALL CATS, CALL CATT, and CALL CATX
routines is faster than using TRIM and LEFT.
The following table shows statements that are equivalent to CALL CATS, CALL
CATT, and CALL CATX. The variables X1 through X4 specify character variables, and
SP specifies a delimiter, such as a blank or comma.
Functions and CALL Routines
4
CALL CATX Routine
433
CALL Routine
Equivalent Statement
CALL CATS(OF X1-X4);
X1=TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4));
CALL CATT(OF X1-X4);
X1=TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4);
CALL CATX(SP, OF X1-X4); *
X1=TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4));
* If any of the arguments are blank, the results that are produced by CALL CATX differ slightly
from the results that are produced by the concatenated code. In this case, CALL CATX omits the
corresponding delimiter. For example, CALL CATX("+",newvar,"X"," ", "Z"," ");
produces X+Z.
Examples
The following example shows how the CALL CATX routine concatenates strings.
data _null_;
length answer $ 50;
separator=’%%$%%’;
x=’Athens is t ’;
y=’he Olym
’;
z=’ pic site for 2004. ’;
call catx(separator,answer,x,y,z);
put answer;
run;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4----+----5
Athens is t%%$%%he Olym%%$%%pic site for 2004.
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATT Routine” on page 430
“CAT Function” on page 526
“CATQ Function” on page 528
“CATS Function” on page 532
“CATT Function” on page 534
“CATX Function” on page 537
434
CALL COMPCOST Routine
4
Chapter 4
CALL COMPCOST Routine
Sets the costs of operations for later use by the COMPGED function
Category:
Character
Restriction:
Use with the COMPGED function
When invoked by the %SYSCALL macro statement, CALL COMPCOST
removes quotation marks from its arguments. For more information, see “Using CALL
Routines and the %SYSCALL Macro Statement” on page 303.
Interaction:
Syntax
CALL COMPCOST(operation-1, value-1 <,operation-2, value-2 …>);
Arguments
operation
is a character constant, variable, or expression that specifies an operation that is
performed by the COMPGED function.
value
is a numeric constant, variable, or expression that specifies the cost of the operation
that is indicated by the preceding argument.
Restriction: Must be an integer that ranges from -32767 to 32767, or a missing
value
Details
Computing the Cost of Operations
Each argument that specifies an operation must
have a value that is a character string. The character string corresponds to one of the
terms that is used to denote an operation that the COMPGED function performs. See
“Computing the Generalized Edit Distance” on page 574 to view a table of operations
that the COMPGED function uses.
The character strings that specify operations can be in uppercase, lowercase, or
mixed case. Blanks are ignored. Each character string must end with an equal sign (=).
Valid values for operations, and the default cost of the operations are listed in the
following table.
Operation
Default Cost
APPEND=
very large
BLANK=
very large
DELETE=
100
DOUBLE=
very large
FDELETE=
equal to DELETE
FINSERT=
equal to INSERT
FREPLACE=
equal to REPLACE
Functions and CALL Routines
Operation
Default Cost
INSERT=
100
MATCH=
0
PUNCTUATION=
very large
REPLACE=
100
SINGLE=
very large
SWAP=
very large
TRUNCATE=
very large
4
CALL COMPCOST Routine
435
If an operation does not appear in the call to the COMPCOST routine, or if the
operation appears and is followed by a missing value, then that operation is assigned a
default cost. A “very large” cost indicates a cost that is sufficiently large that the
COMPGED function will not use the corresponding operation.
After your program calls the COMPCOST routine, the costs that are specified remain
in effect until your program calls the COMPCOST routine again, or until the step that
contains the call to COMPCOST terminates.
Abbreviating Character Strings
You can abbreviate character strings. That is, you can
use the first one or more letters of a specific operation rather than use the entire term.
You must, however, use as many letters as necessary to uniquely identify the term. For
example, you can specify the INSERT= operation as “in=”, and the REPLACE=
operation as “r=”. To specify the DELETE= or the DOUBLE= operation, you must use
the first two letters because both DELETE= and DOUBLE= begin with “d”. The
character string must always end with an equal sign.
Examples
The following example calls the COMPCOST routine to compute the generalized edit
distance for the operations that are specified.
options pageno=1 nodate linesize=80 pagesize=60;
data test;
length String $8 Operation $40;
if _n_ = 1 then call compcost(’insert=’,10,’DEL=’,11,’r=’, 12);
input String Operation;
GED=compged(string, ’baboon’);
datalines;
baboon match
xbaboon insert
babon
delete
baXoon replace
;
proc print data=test label;
label GED=’Generalized Edit Distance’;
var String Operation GED;
run;
The following output shows the results.
436
CALL EXECUTE Routine
4
Output 4.12
Chapter 4
Generalized Edit Distance Based on Operation
The SAS System
Obs
1
2
3
4
String
baboon
xbaboon
babon
baXoon
Operation
match
insert
delete
replace
1
Generalized
Edit
Distance
0
10
11
12
See Also
Functions:
“COMPGED Function” on page 573
“COMPARE Function” on page 569
“COMPLEV Function” on page 578
CALL EXECUTE Routine
Resolves the argument, and issues the resolved value for execution at the next step boundary.
Category:
Macro
Syntax
CALL EXECUTE(argument);
Arguments
argument
specifies a character expression or a constant that yields a macro invocation or a SAS
statement. Argument can be:
3 a character string, enclosed in quotation marks.
3 the name of a DATA step character variable. Do not enclose the name of the
DATA step variable in quotation marks.
3 a character expression that the DATA step resolves to a macro text expression
or a SAS statement.
Details
If argument resolves to a macro invocation, the macro executes immediately and DATA
step execution pauses while the macro executes. If argument resolves to a SAS
statement or if execution of the macro generates SAS statements, the statement(s)
execute after the end of the DATA step that contains the CALL EXECUTE routine.
CALL EXECUTE is fully documented in SAS Macro Language: Reference.
Functions and CALL Routines
4
CALL GRAYCODE Routine
437
CALL GRAYCODE Routine
Generates all subsets of n items in a minimal change order.
Category: Combinatorial
Syntax
CALL GRAYCODE(k, numeric-variable-1, ..., numeric-variable-n);
CALL GRAYCODE(k, character-variable <, n < , in-out>>);
Arguments
k
specifies a numeric variable. Initialize k to either of the following values before
executing the CALL GRAYCODE routine:
3 a negative number to cause CALL GRAYCODE to initialize the subset to be
empty
3 the number of items in the initial set indicated by numeric-variable-1 through
numeric-variable-n, or character-variable, which must be an integer value
between 0 and N inclusive
The value of k is updated when CALL GRAYCODE is executed. The value that is
returned is the number of items in the subset.
numeric-variable
specifies numeric variables that have values of 0 or 1 which are updated when CALL
th
GRAYCODE is executed. A value of 1 for numeric-variable-j indicates that the j
th
item is in the subset. A value of 0 for numeric-variable-j indicates that the j item is
not in the subset.
If you assign a negative value to k before you execute CALL GRAYCODE, then
you do not need to initialize numeric-variable-1 through numeric-variable-n before
executing CALL GRAYCODE unless you want to suppress the note about
uninitialized variables.
If you assign a value between 0 and n inclusive to k before you execute CALL
GRAYCODE, then you must initialize numeric-variable-1 through numeric-variable-n
to k values of 1 and n-k values of 0.
character-variable
specifies a character variable that has a length of at least n characters. The first n
th
characters indicate which items are in the subset. By default, an "I" in the j position
th
th
indicates that thej item is in the subset, and an "O" in the j position indicates that
th
the j item is out of the subset. You can change the two characters by specifying the
in-out argument.
If you assign a negative value to k before you execute CALL GRAYCODE, then
you do not need to initialize character-variable before executing CALL GRAYCODE
unless you want to suppress the note about an uninitialized variable.
If you assign a value between 0 and n inclusive to k before you execute CALL
GRAYCODE, then you must initialize character-variable to k characters that indicate
an item is in the subset, and k-k characters that indicate an item is out of the subset.
438
CALL GRAYCODE Routine
4
Chapter 4
n
specifies a numeric constant, variable, or expression. By default, n is the length of
character-variable.
in-out
specifies a character constant, variable, or expression. The default value is "IO." The
first character is used to indicate that an item is in the subset. The second character
is used to indicate that an item is out of the subset.
Details
Using CALL GRAYCODE in a DATA Step
When you execute the CALL GRAYCODE
routine with a negative value of k, the subset is initialized to be empty.
When you execute the CALL GRAYCODE routine with an integer value of k between
0 and n inclusive, one item is either added to the subset or removed from the subset,
and the value of k is updated to equal the number of items in the subset.
To generate all subsets of n items, you can initialize k to a negative value and
execute CALL GRAYCODE in a loop that iterates 2**n times. If you want to start with
a non-empty subset, then initialize k to be the number of items in the subset, initialize
the other arguments to specify the desired initial subset, and execute CALL
GRAYCODE in a loop that iterates 2**n-1 times. The sequence of subsets that are
generated by CALL GRAYCODE is cyclical, so you can begin with any subset you want.
Using the CALL GRAYCODE Routine with Macros
You can call the GRAYCODE routine
when you use the %SYSCALL macro. Differences exist when you use CALL
GRAYCODE in a DATA step and when you use the routine with macros. The following
list describes usage with macros:
3 All arguments must be initialized to nonblank values.
3 If you use the character-variable argument, then it must be initialized to a
nonblank, nonnumeric character string that contains at least n characters.
3 If you use the in-out argument, then it must be initialized to a string that contains
two characters that are not blanks, digits, decimal points, or plus and minus signs.
If %SYSCALL identifies an argument as being the wrong type, or if %SYSCALL is
unable to identify the type of argument, then &SYSERR and &SYSINFO are not set.
Otherwise, if an error occurs during the execution of the CALL GRAYCODE routine,
then both of the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 0 if the value of k on input is negative
3 the index of the item that was added or removed from the subset if the value of k
on input is a valid nonnegative integer.
Examples
Example 1: Using a Character Variable and Positive Initial k with CALL GRAYCODE
The
following example uses the CALL GRAYCODE routine to generate subsets in a minimal
change order.
data _null_;
x=’++++’;
n=length(x);
Functions and CALL Routines
4
CALL GRAYCODE Routine
k=countc(x, ’+’);
put ’
1’ +3 k= +2 x=;
nsubs=2**n;
do i=2 to nsubs;
call graycode(k, x, n, ’+-’);
put i 5. +3 k= +2 x=;
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
k=4
k=3
k=2
k=3
k=2
k=1
k=0
k=1
k=2
k=1
k=2
k=3
k=2
k=1
k=2
k=3
x=++++
x=-+++
x=-+-+
x=++-+
x=+--+
x=---+
x=---x=+--x=++-x=-+-x=-++x=+++x=+-+x=--+x=--++
x=+-++
Example 2: Using %SYSCALL with Numeric Variables and Negative k
The following
example uses the %SYSCALL macro with numeric variables to generate subsets in a
minimal change order.
%macro test;
%let n=3;
%let x1=.;
%let x2=.;
%let x3=.;
%let k=-1;
%let nsubs=%eval(2**&n + 1);
%put nsubs=&nsubs k=&k x: &x1 &x2 &x3;
%do j=1 %to &nsubs;
%syscall graycode(k, x1, x2, x3);
%put &j: k=&k x: &x1 &x2 &x3 sysinfo=&sysinfo;
%end;
%mend;
%test;
SAS writes the following output to the log:
nsubs=9 k=-1 x:
1: k=0 x: 0 0 0
2: k=1 x: 1 0 0
3: k=2 x: 1 1 0
4: k=1 x: 0 1 0
5: k=2 x: 0 1 1
6: k=3 x: 1 1 1
. . .
sysinfo=0
sysinfo=1
sysinfo=2
sysinfo=1
sysinfo=3
sysinfo=1
439
440
CALL IS8601_CONVERT Routine
4
Chapter 4
7: k=2 x: 1 0 1 sysinfo=2
8: k=1 x: 0 0 1 sysinfo=1
9: k=0 x: 0 0 0 sysinfo=3
Example 3: Using %SYSCALL with a Character Variable and Negative k
The following
example uses the %SYSCALL macro with a character variable to generate subsets in a
minimal change order.
%macro test(n);
%*** Initialize the character variable to a
sufficiently long nonblank, nonnumeric value. ;
%let x=%sysfunc(repeat(_, &n-1));
%let k=-1;
%let nsubs=%eval(2**&n + 1);
%put nsubs=&nsubs k=&k x="&x";
%do j=1 %to &nsubs;
%syscall graycode(k, x, n);
%put &j: k=&k x="&x" sysinfo=&sysinfo;
%end;
%mend;
%test(3);
SAS writes the following output to the log:
nsubs=9 k=-1 x="___"
1: k=0 x="OOO" sysinfo=0
2: k=1 x="IOO" sysinfo=1
3: k=2 x="IIO" sysinfo=2
4: k=1 x="OIO" sysinfo=1
5: k=2 x="OII" sysinfo=3
6: k=3 x="III" sysinfo=1
7: k=2 x="IOI" sysinfo=2
8: k=1 x="OOI" sysinfo=1
9: k=0 x="OOO" sysinfo=3
See Also
Functions:
“GRAYCODE Function” on page 764
CALL IS8601_CONVERT Routine
Converts an ISO 8601 interval to datetime and duration values, or converts datetime and duration
values to an ISO 8601 interval.
Category:
Date and Time
Syntax
CALL IS8601_CONVERT( convert-from, convert-to, <from-variables>, <to-variables>,
<date_time_replacements>
Functions and CALL Routines
4
CALL IS8601_CONVERT Routine
441
Arguments
convert-from
specifies a keyword in single quotation marks that indicates whether the source for
the conversion is an interval, a datetime and duration value, or a duration value.
convert-from can have one of the following values:
’intvl’
specifies that the source value for the conversion is an interval
value.
’dt/du’
specifies that the source value for the conversion is a
datetime/duration value.
’du/dt’
specifies that the source value for the conversion is a
duration/datetime value.
’dt/dt’
specifies that the source value for the conversion is a
datetime/datetime value.
’du’
specifies that the source value for the conversion is a duration
value.
convert-to
specifies a keyword in single quotation marks that indicates the results of the
conversion. convert-to can have one of the following values:
’intvl’
specifies to create an interval value.
’dt’/du’
specifies to create a datetime/duration interval.
’du/dt’
specifies to create a duration/datetime interval.
’dt/dt’
specifies to create a datetime/datetime interval.
’du’
specifies to create a duration.
’start’
specifies to create a value that is the beginning datetime or
duration of an interval value.
’end’
specifies to create a value that is the ending datetime or duration
of an interval value.
from-variable
specifies one or two variables that contain the source value. Specify one variable for
an interval value and two variables, one each, for datetime and duration values. The
datetime and duration values are interval components where the first value is the
beginning value of the interval and the second value is the ending value of the
interval.
An integer variable must be at least a 16-byte character variable
whose value is determined by reading the value using either the $N8601B
informat or the $N8601E informat, or the integer variable is an integer value
returned from invoking the CALL ISO8601_CONVERT routine.
Requirement:
A datetime value must be either a SAS datetime value or an 8-byte
character value that is read by the $N8601B informat or the $N8601E informat, or
by invoking the CALL ISO8601_CONVERT routine.
Requirement:
A duration value must be a numeric value that represents the
number of seconds in the duration or an 8–byte character value whose value is
determined by reading the value using either the $N8601B informat or the
$N8601E informat, or by invoking the CALL ISO8601_CONVERT routine.
Requirement:
442
CALL IS8601_CONVERT Routine
4
Chapter 4
to-variable
specifies one or two variables that contain converted values. Specify one variable for
in interval value and two variables, one each, for datetime and duration values.
Requirement: The interval variable must be at least a 16-byte character variable.
Tip: The datetime and duration variables can be either numeric or character. To
avoid losing precision of a numeric value, the length of a numeric variable needs to
be at least eight characters. Datetime and duration character variables must be at
least 16 bytes; they are padded with blank characters for values that are less than
the length of the variable.
date_time_replacements
specifies date or time component values to use when a month, day, or time component
is omitted from an interval, datetime, or duration value. date_time_replacements is
specified as a series of numbers separated by a comma to represent, in this order, the
year, month, day, hour, minute, or second. Components of date_time_replacements
can be omitted only in the reverse order, seconds, minutes, hours, day, and month. If
no substitute values are specified, the conversion is done using default values.
Defaults: The following are default values for omitted date and time components:
month
1
day
1
hour
0
minute
0
second
0
Requirements: A year component must be part of the datetime or duration value,
and therefore is not valid in date_time_replacements. A comma is required as a
placeholder for the year in date_time_replacements. For example, in the
replacement value string, ,9,4,,2,’, the first comma is a placeholder for a year
value.
Examples
This DATA step uses the ISO8601_CONVERT function to do the following:
3 create an interval by using datetime and duration values
3 create datetime and duration values from an interval that was created using the
CALL IS8601_CONVERT routine
3 create an interval from datetime and duration values, using replacement values
for omitted date and time components in the datetime value
For easier reading, numeric variables end with an N and character variables end with a
C.
data _null_;
/**
/**
/**
/**
declare variable length and type
**/
Character datetime and duration values must be at least **/
16 characters. In order not to lose precision, the
**/
numeric datetime value has a length of 8.
**/
length dtN duN 8 dtC duC $16 intervalC $32;
/** assign a numeric datetime value and a
/** character duration value.
**/
**/
Functions and CALL Routines
4
CALL IS8601_CONVERT Routine
443
dtN=’15Sep2008:09:00:00’dt;
duC=input(’P2y3m4dT5h6m7s’, $n8601b.);
put dtN=;
put duC=;
/** Create an interval from a datetime and duration value
/** and format it using the ISO 8601 extended notation for
/** character values.
**/
**/
**/
call is8601_convert(’dt/du’, ’intvl’, dtN, duC, intervalC);
put ’** Character interval created from datetime and duration values **/’;
put intervalC $n8601e.;
put ’ ’;
/** Create numeric datetime and duration values from an interval
/** and format it using the ISO 8601 extended notation for
/** numeric values.
**/
**/
**/
call is8601_convert(’intvl’, ’dt/du’, intervalC, dtN, duN);
put
put
put
put
’** Character datetime and duration created from an interval
dtN=;
duN=;
’ ’;
/** assign a new datetime value with omitted components
**/’;
**/
dtC=input(’2009---15T10:-:-’, $n8601b.);
put ’** This datetime is a character value. **’;
put dtC $n8601h.;
put ’ ’;
/** Create an interval by reading in a datetime value
**/
/** with omitted date and time components. Use replacement **/
/** values for the month, minutes, and seconds.
**/
call is8601_convert(’du/dt’, ’intvl’, duC, dtC, intervalC,,7,,,35,45);
put
put
put
put
put
run;
’** Interval created using a datetime with omitted values,
’** inserting replacement values for month (7), minute (35)
’** seconds (45).
intervalC $n8601e.;
’ ’;
**’;
**’;
**’;
444
CALL LABEL Routine
4
Chapter 4
The following output appears in the SAS log:
dtN=1537088400
duC=0002304050607FFC
** Character interval created from datetime and duration values **/
2008-09-15T09:00:00.000/P2Y3M4DT5H6M7S
** Character datetime and duration created from an interval
dtN=1537088400
duN=71211967
**/
** This datetime is a character value. **
2009---15T10:-:**
**
**
Interval created using a datetime with omitted values,
inserting replacement values for month (7), minute (35)
seconds (45).
**
**
**
P2Y3M4DT5H6M7S/2009-07-15T10:35:45
NOTE: DATA statement used (Total process time):
real time
0.04 seconds
cpu time
0.03 seconds
CALL LABEL Routine
Assigns a variable label to a specified character variable.
Category:
Variable Control
Syntax
CALL LABEL(variable-1,variable-2);
Arguments
variable-1
specifies any SAS variable. If variable-1 does not have a label, the variable name is
assigned as the value of variable-2.
variable-2
specifies any SAS character variable. Variable labels can be up to 256 characters
long. Therefore, the length of variable-2 should be at least 256 characters to avoid
truncating variable labels.
Note: To conserve space, you should set the length of variable-2 to the length of
the label for variable-1, if it is known. 4
Details
The CALL LABEL routine assigns the label of the variable-1 variable to the character
variable variable-2.
Functions and CALL Routines
4
CALL LEXCOMB Routine
445
Examples
This example uses the CALL LABEL routine with array references to assign the
labels of all variables in the data set OLD as values of the variable LAB in data set
NEW:
data new;
set old;
/* lab is not in either array */
length lab $256;
/* all character variables in old */
array abc{*} _character_;
/* all numeric variables in old */
array def{*} _numeric_;
do i=1 to dim(abc);
/* get label of character variable */
call label(abc{i},lab);
/* write label to an observation */
output;
end;
do j=1 to dim(def);
/* get label of numeric variable */
call label(def{j},lab);
/* write label to an observation */
output;
end;
stop;
keep lab;
run;
See Also
Function:
“VLABEL Function” on page 1159
CALL LEXCOMB Routine
Generates all distinct combinations of the non-missing values of n variables taken k at a time in
lexicographic order.
Category: Combinatorial
When invoked by the %SYSCALL macro statement, CALL LEXCOMB
removes the quotation marks from its arguments. For more information, see “Using
CALL Routines and the %SYSCALL Macro Statement” on page 303.
Interaction:
Syntax
CALL LEXCOMB(count, k, variable-1, …, variable-n);
446
CALL LEXCOMB Routine
4
Chapter 4
Arguments
count
specifies an integer value that is assigned values from 1 to the number of
combinations in a loop.
k
specifies an integer constant, variable, or expression between 1 and n, inclusive, that
specifies the number of items in each combination.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted.
Requirement:
Initialize these variables before you call the LEXCOMB routine.
After calling LEXCOMB, the first k variables contain the values in one
combination.
Tip:
Details
The Basics
Use the CALL LEXCOMB routine in a loop where the first argument to
CALL LEXCOMB takes each integral value from 1 to the number of distinct
combinations of the non-missing values of the variables. In each call to LEXCOMB
within this loop, k should have the same value.
Number of Combinations
When all of the variables have non-missing, unequal values,
then the number of combinations is COMB(n,k). If the number of variables that have
missing values is m, and all the non-missing values are unequal, then LEXCOMB
produces COMB(n-m,k) combinations because the missing values are omitted from the
combinations.
When some of the variables have equal values, the exact number of combinations is
difficult to compute. If you cannot compute the exact number of combinations, use the
LEXCOMB function instead of the CALL LEXCOMB routine.
CALL LEXCOMB Processing
On the first call to the LEXCOMB routine, the following
actions occur:
3 The argument types and lengths are checked for consistency.
3 The m missing values are assigned to the last m arguments.
3 The n-m non-missing values are assigned in ascending order to the first n-m
arguments following count.
On subsequent calls, up to and including the last combination, the next distinct
combination of the non-missing values is generated in lexicographic order.
If you call the LEXCOMB routine with the first argument out of sequence, then the
results are not useful. In particular, if you initialize the variables and then immediately
th
call the LEXCOMB routine with a first argument of j, you will not get the j combination
th
(except when j is 1). To get the j combination, you must call the LEXCOMB routine j
times, with the first argument taking values from 1 through j in that exact order.
Using the CALL LEXCOMB Routine with Macros
You can call the LEXCOMB routine
when you use the %SYSCALL macro. In this case, the variable arguments are not
required to be the same length, but they are required to be the same type. If
%SYSCALL identifies an argument as numeric, then %SYSCALL reformats the
returned value.
Functions and CALL Routines
4
CALL LEXCOMB Routine
447
If an error occurs during the execution of the CALL LEXCOMB routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 1 if count=1 and at lease one variable has a non-missing value
3 1 if the value of variable-1 changed
3 j if variable-1 through variable-i did not change, but variable-j did change, where
j=i+1
3 –1 if all distinct combinations have already been generated
Comparisons
The CALL LEXCOMB routine generates all distinct combinations of the non-missing
values of n variables taken k at a time in lexicographic order. The CALL ALLCOMB
routine generates all combinations of the values of n variables taken k at a time in a
minimal change order.
Examples
Example 1: Using CALL LEXCOMB in a DATA Step
The following example calls the
LEXCOMB routine to generate distinct combinations in lexicographic order.
data _null_;
array x[5] $3 (’ant’ ’bee’ ’cat’ ’dog’ ’ewe’);
n=dim(x);
k=3;
ncomb=comb(n,k);
do j=1 to ncomb;
call lexcomb(j, k, of x[*]);
put j 5. +3 x1-x3;
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
ant
ant
ant
ant
ant
ant
bee
bee
bee
cat
bee
bee
bee
cat
cat
dog
cat
cat
dog
dog
cat
dog
ewe
dog
ewe
ewe
dog
ewe
ewe
ewe
Example 2: Using CALL LEXCOMB with Macros
The following is an example of the
CALL LEXCOMB routine that is used with macros. The output includes values for the
%SYSINFO macro.
%macro test;
%let x1=ant;
%let x2=baboon;
448
4
CALL LEXCOMBI Routine
Chapter 4
%let x3=baboon;
%let x4=hippopotamus;
%let x5=zebra;
%let k=2;
%let ncomb=%sysfunc(comb(5,&k));
%do j=1 %to &ncomb;
%syscall lexcomb(j, k, x1, x2, x3, x4, x5);
%let jfmt=%qsysfunc(putn(&j, 5. ));
%let pad=%qsysfunc(repeat(%str( ), 20-%length(&x1 &x2)));
%put &jfmt: &x1 &x2 &pad sysinfo=&sysinfo;
%if &sysinfo < 0 %then %let j=%eval(&ncomb+1);
%end;
%mend;
%test
SAS writes the following output to the log:
1:
2:
3:
4:
5:
6:
7:
8:
ant baboon
ant hippopotamus
ant zebra
baboon baboon
baboon hippopotamus
baboon zebra
hippopotamus zebra
hippopotamus zebra
sysinfo=1
sysinfo=2
sysinfo=2
sysinfo=1
sysinfo=2
sysinfo=2
sysinfo=1
sysinfo=-1
See Also
Functions and CALL Routines:
“LEXCOMB Function” on page 852
“CALL ALLCOMB Routine” on page 419
CALL LEXCOMBI Routine
Generates all combinations of the indices of n objects taken k at a time in lexicographic order.
Category:
Combinatorial
Syntax
CALL LEXCOMBI(n, k, index-1, …, index-k);
Arguments
n
is a numeric constant, variable, or expression that specifies the total number of
objects.
Functions and CALL Routines
4
CALL LEXCOMBI Routine
449
k
is a numeric constant, variable, or expression that specifies the number of objects in
each combination.
index
is a numeric variable that contains indices of the objects in the combination that is
returned. Indices are integers between 1 and n, inclusive.
Tip: If index-1 is missing or zero, then the CALL LEXCOMBI routine initializes the
indices to index-1=1 through index-k=k. Otherwise, CALL LEXCOMBI creates a
new combination by removing one index from the combination and adding another
index.
Details
CALL LEXCOMBI Processing
Before the first call to the LEXCOMBI routine, complete
one of the following tasks:
3 Set index-1 equal to zero or to a missing value.
3 Initialize index-1 through index-k to distinct integers between 1 and n inclusive.
The number of combinations of n objects taken k at a time can be computed as
COMB(n,k). To generate all combinations of n objects taken k at a time, call
LEXCOMBI in a loop that executes COMB(n,k) times.
Using the CALL LEXCOMBI Routine with Macros
If you call the LEXCOMBI routine
from the macro processor with %SYSCALL, then you must initialize all arguments to
numeric values. %SYSCALL reformats the values that are returned.
If an error occurs during the execution of the CALL LEXCOMBI routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 1 if the value of variable-1 changed
3 j if variable-1 through variable-i did not change, but variable-j did change, where
j=i+1
3 –1 if all distinct combinations have already been generated
Comparisons
The CALL LEXCOMBI routine generates all combinations of the indices of n objects
taken k at a time in lexicographic order. The CALL ALLCOMBI routine generates all
combinations of the indices of n objects taken k at a time in a minimum change order.
Examples
Example 1: Using the CALL LEXCOMBI Routine with the DATA Step
The following
example uses the CALL LEXCOMBI routine to generate combinations of indices in
lexicographic order.
data _null_;
array x[5] $3 (’ant’ ’bee’ ’cat’ ’dog’ ’ewe’);
array c[3] $3;
array i[3];
n=dim(x);
450
CALL LEXCOMBI Routine
4
Chapter 4
k=dim(i);
i[1]=0;
ncomb=comb(n,k);
do j=1 to ncomb;
call lexcombi(n, k, of i[*]);
do h=1 to k;
c[h]=x[i[h]];
end;
put @4 j= @10 ’i= ’ i[*] +3 ’c= ’ c[*];
end;
run;
SAS writes the following output to the log:
j=1
j=2
j=3
j=4
j=5
j=6
j=7
j=8
j=9
j=10
i=
i=
i=
i=
i=
i=
i=
i=
i=
i=
1
1
1
1
1
1
2
2
2
3
2
2
2
3
3
4
3
3
4
4
3
4
5
4
5
5
4
5
5
5
c=
c=
c=
c=
c=
c=
c=
c=
c=
c=
ant
ant
ant
ant
ant
ant
bee
bee
bee
cat
bee
bee
bee
cat
cat
dog
cat
cat
dog
dog
cat
dog
ewe
dog
ewe
ewe
dog
ewe
ewe
ewe
Example 2: Using the CALL LEXCOMBI Routine with Macros and Displaying the Return
Code
The following example uses the CALL LEXCOMBI routine with macros. The
output includes values for the %SYSINFO macro.
%macro test;
%let x1=0;
%let x2=0;
%let x3=0;
%let n=5;
%let k=3;
%let ncomb=%sysfunc(comb(&n,&k));
%do j=1 %to &ncomb+1;
%syscall lexcombi(n,k,x1,x2,x3);
%let jfmt=%qsysfunc(putn(&j,5.));
%let pad=%qsysfunc(repeat(%str(),6-%length(&x1 &x2 &x3)));
%put &jfmt: &x1 &x2 &x3 &pad sysinfo=&sysinfo;
%end;
%mend;
%test
SAS writes the following output to the log:
1:
2:
3:
4:
5:
6:
7:
8:
9:
1
1
1
1
1
1
2
2
2
2
2
2
3
3
4
3
3
4
3
4
5
4
5
5
4
5
5
sysinfo=1
sysinfo=3
sysinfo=3
sysinfo=2
sysinfo=3
sysinfo=2
sysinfo=1
sysinfo=3
sysinfo=2
Functions and CALL Routines
10: 3 4 5
11: 3 4 5
4
CALL LEXPERK Routine
451
sysinfo=1
sysinfo=-1
See Also
Functions and CALL Routines:
“CALL LEXCOMB Routine” on page 445
“CALL ALLCOMBI Routine” on page 422
CALL LEXPERK Routine
Generates all distinct permutations of the non-missing values of n variables taken k at a time in
lexicographic order.
Category: Combinatorial
When invoked by THE %SYSCALL macro statement, CALL LEXPERK
removes the quotation marks from its arguments. For more information, see “Using
CALL Routines and the %SYSCALL Macro Statement” on page 303.
Interaction:
Syntax
CALL LEXPERK(count, k, variable-1, …, variable-n);
Arguments
count
specifies an integer variable that is assigned a value from 1 to the number of
permutations in a loop.
k
specifies an integer constant, variable, or expression between 1 and n, inclusive, that
specifies the number of items in each permutation.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted.
Requirement:
Initialize these variables before you call the LEXPERK routine.
After calling LEXPERK, the first k variables contain the values in one
permutation.
Tip:
Details
The Basics
Use the CALL LEXPERK routine in a loop where the first argument to
CALL LEXPERK accepts each integral value from 1 to the number of distinct
permutations of k non-missing values of the variables. In each call to LEXPERK within
this loop, k should have the same value.
452
CALL LEXPERK Routine
4
Chapter 4
Number of Permutations
When all of the variables have non-missing, unequal values,
the number of permutations is PERM(,k). If the number of variables that have missing
values is m, and all the non-missing values are unequal, CALL LEXPERK produces
PERM(n-m,k) permutations because the missing values are omitted from the
permutations. When some of the variables have equal values, the exact number of
permutations is difficult to compute. If you cannot compute the exact number of
permutations, use the LEXPERK function instead of the CALL LEXPERK routine.
CALL LEXPERK Processing
On the first call to the LEXPERK routine, the following
actions occur:
3 The argument types and lengths are checked for consistency.
3 The m missing values are assigned to the last m arguments.
3 The n-m non-missing values are assigned in ascending order to the first n-m
arguments following count.
On subsequent calls, up to and including the last permutation, the next distinct
permutation of k non-missing values is generated in lexicographic order.
If you call the LEXPERK routine with the first argument out of sequence, then the
results are not useful. In particular, if you initialize the variables and then immediately
th
call the LEXPERK routine with a first argument of j, you will not get thej permutation
th
(except when j is 1). To get the j permutation, you must call LEXPERK j times, with
the first argument taking values from 1 through j in that exact order.
Using the CALL LEXPERK Routine with Macros
You can call the LEXPERK routine
when you use the %SYSCALL macro. In this case, the variable arguments are not
required to be the same length, but they are required to be the same type. If
%SYSCALL identifies an argument as numeric, then %SYSCALL reformats the
returned value.
If an error occurs during the execution of the CALL LEXPERK routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 1 if count=1 and at least one variable has a non-missing value
3 1 if count>1 and the value of variable-1 changed
3 j if count>1 and variable-1 through variable-i did not change, but variable-j did
change, where j=i+1
3 –1 if all distinct permutations were already generated
Comparisons
The CALL LEXPERK routine generates all distinct permutations of the non-missing
values of n variables taken k at a time in lexicographic order. The CALL ALLPERM
routine generates all permutations of the values of several variables in a minimal
change order.
Examples
Example 1: Using CALL LEXPERK in a DATA Step
CALL LEXPERK routine.
data _null_;
array x[5] $3 (’V’ ’W’ ’X’ ’Y’ ’Z’);
The following is an example of the
Functions and CALL Routines
n=dim(x);
k=3;
nperm=perm(n,k);
do j=1 to nperm;
call lexperk(j, k, of x[*]);
put j 5. +3 x1-x3;
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
V
V
V
V
V
V
V
V
V
V
V
V
W
W
W
W
W
W
W
W
W
W
W
W
X
X
X
X
X
X
X
X
X
X
X
X
Y
Y
Y
Y
Y
Y
Y
Y
W
W
W
X
X
X
Y
Y
Y
Z
Z
Z
V
V
V
X
X
X
Y
Y
Y
Z
Z
Z
V
V
V
W
W
W
Y
Y
Y
Z
Z
Z
V
V
V
W
W
W
X
X
X
Y
Z
W
Y
Z
W
X
Z
W
X
Y
X
Y
Z
V
Y
Z
V
X
Z
V
X
Y
W
Y
Z
V
Y
Z
V
W
Z
V
W
Y
W
X
Z
V
X
Z
V
W
4
CALL LEXPERK Routine
453
454
CALL LEXPERK Routine
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
4
Y
Y
Y
Y
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
Chapter 4
X
Z
Z
Z
V
V
V
W
W
W
X
X
X
Y
Y
Y
Z
V
W
X
W
X
Y
V
X
Y
V
W
Y
V
W
X
Example 2: Using CALL LEXPERK with Macros
The following is an example of the
CALL LEXPERK routine that is used with macros. The output includes values for the
%SYSINFO macro.
%macro test;
%let x1=ant;
%let x2=baboon;
%let x3=baboon;
%let x4=hippopotamus;
%let x5=zebra;
%let k=2;
%let nperk=%sysfunc(perm(5,&k));
%do j=1 %to &nperk;
%syscall lexperk(j, k, x1, x2, x3, x4, x5);
%let jfmt=%qsysfunc(putn(&j,5.));
%let pad=%qsysfunc(repeat(%str(),20-%length(&x1 &x2)));
%put &jfmt: &x1 &x2 &pad sysinfo=&sysinfo;
%if &sysinfo<0 %then %let j=%eval(&nperk+1);
%end;
%mend;
%test
SAS writes the following output to the log:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
ant baboon sysinfo=1
ant hippopotamus sysinfo=2
ant zebra sysinfo=2
baboon ant sysinfo=1
baboon baboon sysinfo=2
baboon hippopotamus sysinfo=2
baboon zebra sysinfo=2
hippopotamus ant sysinfo=1
hippopotamus baboon sysinfo=2
hippopotamus zebra sysinfo=2
zebra ant sysinfo=1
zebra baboon sysinfo=2
zebra hippopotamus sysinfo=2
zebra hippopotamus sysinfo=-1
Functions and CALL Routines
4
CALL LEXPERM Routine
455
See Also
Functions and CALL Routines:
“CALL ALLPERM Routine” on page 424
“LEXPERM Function” on page 859
“CALL RANPERK Routine” on page 488
“CALL RANPERM Routine” on page 490
CALL LEXPERM Routine
Generates all distinct permutations of the non-missing values of several variables in lexicographic
order.
Category: Combinatorial
When invoked by the %SYSCALL macro statement, CALL LEXPERM
removes the quotation marks from its arguments. For more information, see “Using
CALL Routines and the %SYSCALL Macro Statement” on page 303.
Interaction:
Syntax
CALL LEXPERM(count, variable-1 <, …, variable-N>);
Arguments
count
specifies a numeric variable that has an integer value that ranges from 1 to the
number of permutations.
variable
specifies either all numeric variables, or all character variables that have the same
length. The values of these variables are permuted by LEXPERM.
Requirement: Initialize these variables before you call the LEXPERM routine.
Details
Determine the Number of Distinct Permutations
These variables are defined for use in
the equation that follows:
N
specifies the number of variables that are being permuted—that is,
the number of arguments minus one.
M
specifies the number of missing values among the variables that are
being permuted.
d
specifies the number of distinct non-missing values among the
arguments.
Ni
for i=1 through i=d, Ni specifies the number of instances of the ith
distinct value.
456
CALL LEXPERM Routine
4
Chapter 4
The number of distinct permutations of non-missing values of the arguments is
expressed as follows:
P
::: + Nd )!
= (N1 +N N!N2 +!:::N
! <= N !
1
2
d
CALL LEXPERM Processing
Use the CALL LEXPERM routine in a loop where the
argument count accepts each integral value from 1 to P. You do not need to compute P
provided you exit the loop when CALL LEXPERM returns a value that is less than zero.
For 1=count<P, the following actions occur:
3 The argument types and lengths are checked for consistency.
3 The M missing values are assigned to the last M arguments.
3 The N-M non-missing values are assigned in ascending order to the first N-M
arguments following count.
3 CALL LEXPERM returns 1.
For 1<count<=P, the following actions occur:
3 The next distinct permutation of the non-missing values is generated in
lexicographic order.
3 If variable-1 through variable-I did not change, but variable-J did change, where
J=I+1, then CALL LEXPERM returns J.
For count>P, CALL LEXPERM returns –1.
If the CALL LEXPERM routine is executed with the first argument out of sequence,
the results might not be useful. In particular, if you initialize the variables and then
immediately execute CALL LEXPERM with a first argument of K, you will not get the
Kth permutation (except when K is 1). To get the Kth permutation, you must execute
CALL LEXPERM K times, with the first argument accepting values from 1 through K
in that exact order.
Using the CALL LEXPERM Routine with Macros
You can call the LEXPERM routine
when you use the %SYSCALL macro. In this case, the variable arguments are not
required to be the same length, but they must be the same type. If %SYSCALL
identifies an argument as numeric, then %SYSCALL reformats the returned value.
If an error occurs during the execution of the CALL LEXPERM routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than –100.
If there are no errors, then &SYSERR is set to zero, and &SYSINFO is set to one of
the following values:
3 1 if 1=count<P
3 1 if 1<count<=P and the value of variable-1 changed
3 J if 1<count<=P and variable-1 through variable-I did not change, but variable-J
did change, where J=I+1
3 –1 if count>P
Comparisons
SAS provides three functions or CALL routines for generating all permutations:
3 ALLPERM generates all possible permutations of the values, missing or
non-missing, of several variables. Each permutation is formed from the previous
permutation by interchanging two consecutive values.
Functions and CALL Routines
4
CALL LEXPERM Routine
457
3 LEXPERM generates all distinct permutations of the non-missing values of
several variables. The permutations are generated in lexicographic order.
3 LEXPERK generates all distinct permutations of K of the non-missing values of N
variables. The permutations are generated in lexicographic order.
ALLPERM is the fastest of these functions and CALL routines. LEXPERK is the
slowest.
Examples
Example 1: Using CALL LEXPERM in a DATA Step
The following example uses the
DATA step to generate all distinct permutations of the non-missing values of several
variables in lexicographic order.
data _null_;
array x[4] $3 (’ant’ ’bee’ ’cat’ ’dog’);
n=dim(x);
nfact=fact(n);
do i=1 to nfact;
call lexperm(i, of x[*]);
put i 5. +2 x[*];
end;
run;
SAS writes the following output to the log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ant
ant
ant
ant
ant
ant
bee
bee
bee
bee
bee
bee
cat
cat
cat
cat
cat
cat
dog
dog
dog
dog
dog
dog
bee
bee
cat
cat
dog
dog
ant
ant
cat
cat
dog
dog
ant
ant
bee
bee
dog
dog
ant
ant
bee
bee
cat
cat
cat
dog
bee
dog
bee
cat
cat
dog
ant
dog
ant
cat
bee
dog
ant
dog
ant
bee
bee
cat
ant
cat
ant
bee
dog
cat
dog
bee
cat
bee
dog
cat
dog
ant
cat
ant
dog
bee
dog
ant
bee
ant
cat
bee
cat
ant
bee
ant
Example 2: Using CALL LEXPERM with Macros
The following is an example of the
CALL LEXPERM routine that is used with macros. The output includes values for the
%SYSINFO macro.
%macro test;
%let x1=ant;
458
CALL LOGISTIC Routine
4
Chapter 4
%let x2=baboon;
%let x3=baboon;
%let x4=hippopotamus;
%let n=4;
%let nperm=%sysfunc(perm(4));
%do j=1 %to &nperm;
%syscall lexperm(j,x1,x2,x3,x4);
%let jfmt=%qsysfunc(putn(&j,5.));
%put &jfmt: &x1 &x2 &x3 &x4 sysinfo=&sysinfo;
%if &sysinfo<0 %then %let j=%eval(&nperm+1);
%end;
%mend;
%test;
SAS writes the following output to the log:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
ant baboon baboon hippopotamus
ant baboon hippopotamus baboon
ant hippopotamus baboon baboon
baboon ant baboon hippopotamus
baboon ant hippopotamus baboon
baboon baboon ant hippopotamus
baboon baboon hippopotamus ant
baboon hippopotamus ant baboon
baboon hippopotamus baboon ant
hippopotamus ant baboon baboon
hippopotamus baboon ant baboon
hippopotamus baboon baboon ant
hippopotamus baboon baboon ant
sysinfo=1
sysinfo=3
sysinfo=2
sysinfo=1
sysinfo=3
sysinfo=2
sysinfo=3
sysinfo=2
sysinfo=3
sysinfo=1
sysinfo=2
sysinfo=3
sysinfo=-1
See Also
Functions and CALL Routines:
“LEXPERM Function” on page 859
“CALL ALLPERM Routine” on page 424
“LEXPERK Function” on page 856
“CALL RANPERK Routine” on page 488
“CALL RANPERM Routine” on page 490
CALL LOGISTIC Routine
Applies the logistic function to each argument.
Category:
Mathematical
Syntax
CALL LOGISTIC(argument<, argument, ...>)
Functions and CALL Routines
4
CALL MISSING Routine
459
Arguments
argument
is a numeric variable.
Restriction The CALL LOGISTIC routine only accepts variables as valid
arguments. Do not use a constant or a SAS expression because the CALL routine
is unable to update these arguments.
Details
The CALL LOGISTIC routine replaces each argument by the logistic value of that
argument. For example xj is replaced by
exj
1 + exj
If any argument contains a missing value, then CALL LOGISTIC returns missing
values for all the arguments.
Examples
The following SAS statements produce these results.
SAS Statements
x=0.5;
y=-0.5;
call logistic(x,y);
put x= y=;
Results
x=0.6224593312 y=0.3775406688
CALL MISSING Routine
Assigns missing values to the specified character or numeric variables.
Category: Character
Syntax
CALL MISSING(varname1< , varname2, ...>);
Arguments
varname
specifies the name of SAS character or numeric variables.
460
CALL MODULE Routine
4
Chapter 4
Details
The CALL MISSING routine assigns an ordinary numeric missing value (.) to each
numeric variable in the argument list.
The CALL MISSING routine assigns a character missing value (a blank) to each
character variable in the argument list. If the current length of the character variable
equals the maximum length, the current length is not changed. Otherwise, the current
length is set to 1.
You can mix character and numeric variables in the argument list.
Comparison
The MISSING function checks whether the argument has a missing value but does not
change the value of the argument.
Examples
SAS Statements
Results
prod=’shoes’;
invty=7498;
sales=23759;
call missing(sales);
put prod= invty= sales=;
prod=shoes invty=7498 sales=.
prod=’shoes’;
invty=7498;
sales=23759;
call missing(prod,invty);
put prod= invty= sales=;
prod= invty=. sales=23759
prod=’shoes’;
invty=7498;
sales=23759;
call missing(of _all_);
put prod= invty= sales=;
prod= invty=. sales=.
See Also
Function:
“MISSING Function” on page 890
“How to Set Variable Values to Missing in a Data Step” in SAS Language Reference:
Concepts
CALL MODULE Routine
Calls an external routine without any return code.
Category:
External Routines
Functions and CALL Routines
4
CALL MODULE Routine
461
Syntax
CALL MODULE(<cntl-string,>module-name< ,argument-1, ..., argument-n>);
Arguments
cntl-string
is an optional control string whose first character must be an asterisk (*), followed by
any combination of the following characters:
I
prints the hexadecimal representations of all arguments to the
CALL MODULE routine. You can use this option to help diagnose
problems caused by incorrect arguments or attribute tables. If
you specify the I option, the E option is implied.
E
prints detailed error messages. Without the E option (or the I
option, which supersedes it), the only error message that the
CALL MODULE routine generates is “Invalid argument to
function,” which is usually not enough information to determine
the cause of the error. The E option is useful for a production
environment, while the I option is preferable for a development or
debugging environment.
H
provides brief help information about the syntax of the CALL
MODULE routine, the attribute file format, and suggested SAS
formats and informats.
module-name
is the name of the external module to use.
argument
is one or more arguments to pass to the requested routine.
CAUTION:
Be sure to use the correct arguments and attributes. If you use incorrect arguments or
attributes, you can cause the SAS System, and possibly your operating system, to
fail. 4
Details
The CALL MODULE routine executes a routine module-name that resides in an
external library with the specified arguments.
CALL MODULE builds a parameter list using the information in the arguments and
a routine description and argument attribute table that you define in a separate file.
The attribute table is a sequential text file that contains descriptions of the routines
that you can invoke with the CALL MODULE routine. The purpose of the table is to
define how CALL MODULE should interpret its supplied arguments when it builds a
parameter list to pass to the external routine. The attribute table should contain a
description for each external routine that you intend to call, and descriptions of each
argument associated with that routine.
Before you invoke CALL MODULE, you must define the fileref of SASCBTBL to
point to the external file that contains the attribute table. You can name the file
whatever you want when you create it. This way, you can use SAS variables and
formats as arguments to CALL MODULE and ensure that these arguments are
properly converted before being passed to the external routine. If you do not define this
fileref, CALL MODULE calls the requested routine without altering the arguments.
462
CALL MODULE Routine
4
Chapter 4
CAUTION:
Using the CALL MODULE routine without a defined attribute table can cause the SAS
System to fail or force you to reset your computer. You need to use an attribute table for
all external functions that you want to invoke. 4
Comparisons
The two CALL routines and four functions share identical syntax:
3 The MODULEN and MODULEC functions return a number and a character,
respectively, while the routine CALL MODULE does not return a value.
3 The CALL MODULEI routine and the functions MODULEIC and MODULEIN
permit vector and matrix arguments. Their return values are scalar. You can
invoke CALL MODULEI, MODULEIC, and MODULEIN only from the IML
procedure.
Examples
Example 1: Using the CALL MODULE Routine
This example calls the xyz routine. Use
the following attribute table:
routine xyz minarg=2 maxarg=2;
arg 1 input num byvalue format=ib4.;
arg 2 output char format=$char10.;
The following is the sample SAS code that calls the xyz function:
data _null_;
call module(’xyz’,1,x);
run;
Example 2: Using the MODULEIN Function in the IML Procedure
This example invokes
the changi routine from the TRYMOD.DLL module on a Windows platform. Use the
following attribute table:
routine changi module=trymod returns=long;
arg 1 input num format=ib4. byvalue;
arg 2 update num format=ib4.;
The following PROC IML code calls the changi function:
proc iml;
x1=J(4,5,0);
do i=1 to 4;
do j=1 to 5;
x1[i,j]=i*10+j+3;
end;
end;
y1=x1;
x2=x1;
y2=y1;
rc=modulein(’*i’,’changi’,6,x2);
Functions and CALL Routines
4
CALL POKE Routine
463
Example 3: Using the MODULEN Function
This example calls the Beep routine, which
is part of the Win32 API in the KERNEL32 Dynamic Link Library on a Windows
platform. Use the following attribute table:
routine Beep
minarg=2
maxarg=2
stackpop=called
callseq=byvalue
module=kernel32;
arg 1 num format=pib4.;
arg 2 num format=pib4.;
Assume that you name the attribute table file ’myatttbl.dat’. The following is the
sample SAS code that calls the Beep function:
filename sascbtbl ’myatttbl.dat’;
data _null_;
rc=modulen("*e","Beep",1380,1000);
run;
The previous code causes the computer speaker to beep.
See Also
Functions and CALL Routines:
“MODULEC Function” on page 894
“MODULEN Function” on page 894
CALL POKE Routine
Writes a value directly into memory on a 32-bit platform.
Category: Special
Restriction:
Use on 32-bit platforms only.
Syntax
CALL POKE(source,pointer,< length>,< floating-point>);
Arguments
source
specifies a constant, variable, or expression that contains a value to write into
memory.
pointer
specifies a numeric expression that contains the virtual address of the data that the
CALL POKE routine alters.
464
4
CALL POKELONG Routine
Chapter 4
length
specifies a numeric constant, variable, or expression that contains the number of
bytes to write from the source to the address that is indicated by pointer. If you omit
length, the action that the CALL POKE routine takes depends on whether source is a
character value or a numeric value:
3 If source is a character value, the CALL POKE routine copies the entire value of
source to the specified memory location.
3 If source is a numeric value, the CALL POKE routine converts source into a long
integer and writes into memory the number of bytes that constitute a pointer.
Operating Environment Information:
long, depending on the situation. 4
Under z/OS, pointers are 3 or 4 bytes
floating-point
specifies that the value of source is stored as a floating-point number. The value of
floating-point can be any number.
Tip: If you do not use the floating-point argument, then source is stored as an
integer value.
Details
CAUTION:
The CALL POKE routine is intended only for experienced programmers in specific cases. If
you plan to use this routine, use extreme care both in your programming and in your
typing. Writing directly into memory can cause devastating problems. This routine
bypasses the normal safeguards that prevent you from destroying a vital element in
your SAS session or in another piece of software that is active at the time. 4
If you do not have access to the memory location that you specify, the CALL POKE
routine returns an "Invalid argument" error.
You cannot use the CALL POKE routine on 64-bit platforms. If you attempt to use it,
SAS writes a message to the log stating that this restriction applies. If you have legacy
applications that use CALL POKE, change the applications and use CALL POKELONG
instead. You can use CALL POKELONG on both 32–bit and 64–bit platforms.
If you use the fourth argument, then a floating-point number is assumed to be the
value that is stored. If you do not use the fourth argument, then an integer value is
assumed to be stored.
See Also
Functions and CALL Routines:
“ADDR Function” on page 361
“CALL POKELONG Routine” on page 464
“PEEK Function” on page 958
“PEEKC Function” on page 959
CALL POKELONG Routine
Writes a value directly into memory on 32-bit and 64-bit platforms.
Category:
Special
Functions and CALL Routines
4
CALL PRXCHANGE Routine
465
Syntax
CALL POKELONG(source,pointer< ,length>,< floating-point>)
Arguments
source
specifies a character constant, variable, or expression that contains a value to write
into memory.
pointer
specifies a character string that contains the virtual address of the data that the
CALL POKELONG routine alters.
length
specifies a numeric SAS expression that contains the number of bytes to write from
the source to the address that is indicated by the pointer. If you omit length, the
CALL POKELONG routine copies the entire value of source to the specified memory
location.
floating-point
specifies that the value of source is stored as a floating-point number. The value of
floating-point can be any number.
Tip: If you do not use the floating-point argument, then source is stored as an
integer value.
Details
CAUTION:
The CALL POKELONG routine is intended only for experienced programmers in specific
cases. If you plan to use this routine, use extreme care both in your programming
and in your typing. Writing directly into memory can cause devastating problems. It
bypasses the normal safeguards that prevent you from destroying a vital element in
your SAS session or in another piece of software that is active at the time. 4
If you do not have access to the memory location that you specify, the CALL
POKELONG routine returns an "Invalid argument" error.
If you use the fourth argument, then a floating-point number is assumed to be the
value that is stored. If you do not use the fourth argument, then an integer value is
assumed to be stored.
See Also
Functions and CALL Routines:
“CALL POKE Routine” on page 463
CALL PRXCHANGE Routine
Performs a pattern-matching replacement.
466
CALL PRXCHANGE Routine
4
Chapter 4
Character String Matching
Use with the PRXPARSE function.
Interaction: When invoked by the %SYSCALL macro statement, CALL PRXCHANGE
removes the quotation marks from its arguments. For more information, see “Using
CALL Routines and the %SYSCALL Macro Statement” on page 303.
Category:
Restriction:
Syntax
CALL PRXCHANGE (regular-expression-id, times, old-string <, new-string <,
result-length <, truncation-value <, number-of-changes>>>>);
Arguments
regular-expression-id
specifies a numeric variable with a value that is a pattern identifier that is returned
from the PRXPARSE function.
times
is a numeric constant, variable, or expression that specifies the number of times to
search for a match and replace a matching pattern.
Tip: If the value of times is -1, then all matching patterns are replaced.
old-string
specifies the character expression on which to perform a search and replace.
Tip: All changes are made to old-string if you do not use the new-string argument.
new-string
specifies a character variable in which to place the results of the change to old-string.
Tip: If you use the new-string argument in the call to the PRXCHANGE routine,
then old-string is not modified.
result-length
is a numeric variable with a return value that is the number of characters that are
copied into the result.
Tip: Trailing blanks in the value of old-string are not copied to new-string, and are
therefore not included as part of the length in result-length.
truncation-value
is a numeric variable with a returned value that is either 0 or 1, depending on the
result of the change operation:
0
if the entire replacement result is not longer than the length of
new-string.
1
if the entire replacement result is longer than the length of
new-string.
number-of-changes
is a numeric variable with a returned value that is the total number of replacements
that were made. If the result is truncated when it is placed into new-string, the
value of number-of-changes is not changed.
Details
The CALL PRXCHANGE routine matches and replaces a pattern. If the value of times
is -1, the replacement is performed as many times as possible.
Functions and CALL Routines
4
CALL PRXCHANGE Routine
467
For more information about pattern matching, see “Pattern Matching Using Perl
Regular Expressions (PRX)” on page 323.
Comparisons
The CALL PRXCHANGE routine is similar to the PRXCHANGE function except that
the CALL routine returns the value of the pattern matching replacement as one of its
parameters instead of as a return argument.
The Perl regular expression (PRX) functions and CALL routines work together to
manipulate strings that match patterns. To see a list and short description of these
functions and CALL routines, see the Character String Matching category in “Functions
and CALL Routines by Category” on page 335.
Examples
The following example replaces all occurrences of cat, rat, or bat with the value
TREE.
data _null_;
/* Use a pattern to replace all occurrences of cat,
/* rat, or bat with the value TREE.
length text $ 46;
RegularExpressionId = prxparse(’s/[crb]at/tree/’);
text = ’The woods have a bat, cat, bat, and a rat!’;
/* Use CALL PRXCHANGE to perform the search and replace.
/* Because the argument times has a value of -1, the
/* replacement is performed as many times as possible.
call prxchange(RegularExpressionId, -1, text);
put text;
run;
SAS writes the following line to the log:
The woods have a tree, tree, tree, and a tree!
See Also
Functions and CALL routines:
“CALL PRXDEBUG Routine” on page 468
“CALL PRXFREE Routine” on page 470
“CALL PRXNEXT Routine” on page 471
“CALL PRXPOSN Routine” on page 473
“CALL PRXSUBSTR Routine” on page 476
“PRXCHANGE Function” on page 994
“PRXPAREN Function” on page 1003
“PRXMATCH Function” on page 999
“PRXPARSE Function” on page 1005
“PRXPOSN Function” on page 1007
*/
*/
*/
*/
*/
468
CALL PRXDEBUG Routine
4
Chapter 4
CALL PRXDEBUG Routine
Enables Perl regular expressions in a DATA step to send debugging output to the SAS log.
Category:
Character String Matching
Restriction: Use with the CALL PRXCHANGE, CALL PRXFREE, CALL PRXNEXT,
CALL PRXPOSN, CALL PRXSUBSTR, PRXPARSE, PRXPAREN, and PRXMATCH
functions and CALL routines. The PRXPARSE function is not DBCS compatible.
Syntax
CALL PRXDEBUG (on-off);
Arguments
on-off
specifies a numeric constant, variable, or expression. If the value of on-off is positive
and non-zero, then debugging is turned on. If the value of on-off is zero, then
debugging is turned off.
Details
The CALL PRXDEBUG routine provides information about how a Perl regular
expression is compiled, and about which steps are taken when a pattern is matched to a
character value.
You can turn debugging on and off multiple times in your program if you want to see
debugging output for particular Perl regular expression function calls.
For more information about pattern matching, see “Pattern Matching Using Perl
Regular Expressions (PRX)” on page 323.
Comparisons
The Perl regular expression (PRX) functions and CALL routines work together to
manipulate strings that match patterns. To see a list and short description of these
functions and CALL routines, see the Character String Matching category in “Functions
and CALL Routines by Category” on page 335.
Examples
The following example produces debugging output.
data _null_;
/* Turn the debugging option on. */
call prxdebug(1);
putlog ’PRXPARSE: ’;
re = prxparse(’/[bc]d(ef*g)+h[ij]k$/’);
putlog ’PRXMATCH: ’;
pos = prxmatch(re, ’abcdefg_gh_’);
Functions and CALL Routines
4
CALL PRXDEBUG Routine
469
/* Turn the debugging option off. */
call prxdebug(0);
run;
The following lines are written to the SAS log.
Output 4.13
SAS Log Results from CALL PRXDEBUG
PRXPARSE:
Compiling REx ’[bc]d(ef*g)+h[ij]k$’ u
size 41 first at 1 v
rarest char g at 0 y
rarest char d at 0
1: ANYOF[bc](10) w
10: EXACT <d>(12)
12: CURLYX[0] {1,32767}(26)
14:
OPEN1(16)
16:
EXACT <e>(18)
18:
STAR(21)
19:
EXACT <f>(0)
21:
EXACT <g>(23)
23:
CLOSE1(25)
25:
WHILEM[1/1](0)
26: NOTHING(27)
27: EXACT <h>(29)
29: ANYOF[ij](38)
38: EXACT <k>(40)
40: EOL(41)
41: END(0)
anchored ’de’ at 1 floating ’gh’ at 3..2147483647 (checking floating)
stclass ’ANYOF[bc]’ minlen 7 U
x
x
PRXMATCH:
Guessing start of match, REx ’[bc]d(ef*g)+h[ij]k$’ against ’abcdefg_gh_’...
Did not find floating substr ’gh’...
Match rejected by optimizer
The following items correspond to the lines that are numbered in the SAS log that is
shown above.
u This line shows the precompiled form of the Perl regular expression.
v Size specifies a value in arbitrary units of the compiled form of the Perl regular
expression. 41 is the label ID of the first node that performs a match.
w This line begins a list of program nodes in compiled form for regular expressions.
x These two lines provide optimizer information. In the example above, the
optimizer found that the match should contain the substring de at offset 1, and
the substring gh at an offset between 3 and infinity. To rule out a pattern match
quickly, Perl checks substring gh before it checks substring de.
The optimizer might use the information that the match begins at the first ID
(v), with a character class (y), and cannot be shorter than seven characters (U).
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 465
“CALL PRXFREE Routine” on page 470
“CALL PRXNEXT Routine” on page 471
470
CALL PRXFREE Routine
4
Chapter 4
“CALL PRXPOSN Routine” on page 473
“CALL PRXSUBSTR Routine” on page 476
“CALL PRXCHANGE Routine” on page 465
“PRXCHANGE Function” on page 994
“PRXPAREN Function” on page 1003
“PRXMATCH Function” on page 999
“PRXPARSE Function” on page 1005
“PRXPOSN Function” on page 1007
CALL PRXFREE Routine
Frees memory that was allocated for a Perl regular expression.
Character String Matching
Category:
Restriction:
Use with the PRXPARSE function.
Syntax
CALL PRXFREE (regular-expression-id);
Arguments
regular-expression-id
specifies a numeric variable with a value that is the identification number that is
returned by the PRXPARSE function. regular-expression-id is set to missing if the
call to the PRXFREE routine occurs without error.
Details
The CALL PRXFREE routine frees unneeded resources that were allocated for a Perl
regular expression.
For more information about pattern matching, see “Pattern Matching Using Perl
Regular Expressions (PRX)” on page 323.
Comparisons
The Perl regular expression (PRX) functions and CALL routines work together to
manipulate strings that match patterns. To see a list and short description of these
functions and CALL routines, see the Character String Matching category in “Functions
and CALL Routines by Category” on page 335.
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 465
Functions and CALL Routines
4
CALL PRXNEXT Routine
471
“CALL PRXDEBUG Routine” on page 468
“CALL PRXNEXT Routine” on page 471
“CALL PRXPOSN Routine” on page 473
“CALL PRXSUBSTR Routine” on page 476
“CALL PRXCHANGE Routine” on page 465
“PRXCHANGE Function” on page 994
“PRXPAREN Function” on page 1003
“PRXPAREN Function” on page 1003
“PRXPARSE Function” on page 1005
“PRXPOSN Function” on page 1007
CALL PRXNEXT Routine
Returns the position and length of a substring that matches a pattern, and iterates over multiple
matches within one string.
Category: Character String Matching
Use with the PRXPARSE function.
When invoked by the %SYSCALL macro statement, CALL PRXNEXT
removes the quotation marks from arguments. For more information, see “Using CALL
Routines and the %SYSCALL Macro Statement” on page 303.
Restriction:
Interaction:
Syntax
CALL PRXNEXT (regular-expression-id, start, stop, source, position, length);
Arguments
regular-expression-id
specifies a numeric variable with a value that is the identification number that is
returned by the PRXPARSE function.
start
is a numeric variable that specifies the position at which to start the pattern
matching in source. If the match is successful, CALL PRXNEXT returns a value of
position + MAX(1, length). If the match is not successful, the value of start is not
changed.
stop
is a numeric constant, variable, or expression that specifies the last character to use
in source. If stop is -1, then the last character is the last non-blank character in
source.
source
specifies a character constant, variable, or expression that you want to search.
position
is a numeric variable with a returned value that is the position in source at which
the pattern begins. If no match is found, CALL PRXNEXT returns zero.
472
CALL PRXNEXT Routine
4
Chapter 4
length
is a numeric variable with a returned value that is the length of the string that is
matched by the pattern. If no match is found, CALL PRXNEXT returns zero.
Details
The CALL PRXNEXT routine searches the variable source with a pattern. It returns
the position and length of a pattern match that is located between the start and the
stop positions in source. Because the value of the start parameter is updated to be the
position of the next character that follows a match, CALL PRXNEXT enables you to
search a string for a pattern multiple times in succession.
For more information about pattern matching, see “Pattern Matching Using Perl
Regular Expressions (PRX)” on page 323.
Comparisons
The Perl regular expression (PRX) functions and CALL routines work together to
manipulate strings that match patterns. To see a list and short description of these
functions and CALL routines, see the Character String Matching category in “Functions
and CALL Routines by Category” on page 335.
Examples
The following example finds all instances of cat, rat, or bat in a text string.
data _null_;
ExpressionID = prxparse(’/[crb]at/’);
text = ’The woods have a bat, cat, and a rat!’;
start = 1;
stop = length(text);
/* Use PRXNEXT to find the first instance of the pattern, */
/* then use DO WHILE to find all further instances.
*/
/* PRXNEXT changes the start parameter so that searching */
/* begins again after the last match.
*/
call prxnext(ExpressionID, start, stop, text, position, length);
do while (position > 0);
found = substr(text, position, length);
put found= position= length=;
call prxnext(ExpressionID, start, stop, text, position, length);
end;
run;
The following lines are written to the SAS log:
found=bat position=18 length=3
found=cat position=23 length=3
found=rat position=34 length=3
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 465
“CALL PRXDEBUG Routine” on page 468
Functions and CALL Routines
4
CALL PRXPOSN Routine
473
“CALL PRXFREE Routine” on page 470
“CALL PRXPOSN Routine” on page 473
“CALL PRXSUBSTR Routine” on page 476
“CALL PRXCHANGE Routine” on page 465
“PRXCHANGE Function” on page 994
“PRXPAREN Function” on page 1003
“PRXMATCH Function” on page 999
“PRXPARSE Function” on page 1005
“PRXPOSN Function” on page 1007
CALL PRXPOSN Routine
Returns the start position and length for a capture buffer.
Category: Character String Matching
Restriction:
Use with the PRXPARSE function.
Syntax
CALL PRXPOSN (regular-expression-id, capture-buffer, start <, length>);
Arguments
regular-expression-id
specifies a numeric variable with a value that is a pattern identifier that is returned
by the PRXPARSE function.
capture-buffer
is a numeric constant, variable, or expression with a value that identifies the capture
buffer from which to retrieve the start position and length:
3 If the value of capture-buffer is zero, CALL PRXPOSN returns the start position
and length of the entire match.
3 If the value of capture-buffer is between 1 and the number of open parentheses,
CALL PRXPOSN returns the start position and length for that capture buffer.
3 If the value of capture-buffer is greater than the number of open parentheses,
CALL PRXPOSN returns missing values for the start position and length.
start
is a numeric variable with a returned value that is the position at which the capture
buffer is found:
3 If the value of capture-buffer is not found, CALL PRXPOSN returns a zero value
for the start position.
3 If the value of capture-buffer is greater than the number of open parentheses in
the pattern, CALL PRXPOSN returns a missing value for the start position.
length
is a numeric variable with a returned value that is the pattern length of the previous
pattern match:
474
CALL PRXPOSN Routine
4
Chapter 4
3 If the pattern match is not found, CALL PRXPOSN returns a zero value for the
length.
3 If the value of capture-buffer is greater than the number of open parentheses in
the pattern, CALL PRXPOSN returns a missing value for length.
Details
The CALL PRXPOSN routine uses the results of PRXMATCH, PRXSUBSTR,
PRXCHANGE, or PRXNEXT to return a capture buffer. A match must be found by one
of these functions for the CALL PRXPOSN routine to return meaningful information.
A capture buffer is part of a match, enclosed in parentheses, that is specified in a
regular expression. CALL PRXPOSN does not return the text for the capture buffer
directly. It requires a call to the SUBSTR function to return the text.
For more information about pattern matching, see “Pattern Matching Using Perl
Regular Expressions (PRX)” on page 323.
Comparisons
The CALL PRXPOSN routine is similar to the PRXPOSN function, except that CALL
PRXPOSN returns the position and length of the capture buffer rather than the capture
buffer itself.
The Perl regular expression (PRX) functions and CALL routines work together to
manipulate strings that match patterns. To see a list and short description of these
functions and CALL routines, see the Character String Matching category in “Functions
and CALL Routines by Category” on page 335.
Examples
Example 1: Finding Submatches within a Match
The following example searches a
regular expression and calls the PRXPOSN routine to find the position and length of
three submatches.
data _null_;
patternID = prxparse(’/(\d\d):(\d\d)(am|pm)/’);
text = ’The time is 09:56am.’;
if prxmatch(patternID, text) then do;
call prxposn(patternID, 1, position, length);
hour = substr(text, position, length);
call prxposn(patternID, 2, position, length);
minute = substr(text, position, length);
call prxposn(patternID, 3, position, length);
ampm = substr(text, position, length);
put hour= minute= ampm=;
put text=;
end;
run;
SAS writes the following lines to the log:
hour=09 minute=56 ampm=am
text=The time is 09:56am.
Example 2: Parsing Time Data
results to the SAS log.
The following example parses time data and writes the
Functions and CALL Routines
data _null_;
if _N_ = 1 then
do;
retain patternID;
pattern = "/(\d+):(\d\d)(?:\.(\d+))?/";
patternID = prxparse(pattern);
end;
array match[3] $ 8;
input minsec $80.;
position = prxmatch(patternID, minsec);
if position ^= 0 then
do;
do i = 1 to prxparen(patternID);
call prxposn(patternID, i, start, length);
if start ^= 0 then
match[i] = substr(minsec, start, length);
end;
put match[1] "minutes, " match[2] "seconds" @;
if ^missing(match[3]) then
put ", " match[3] "milliseconds";
end;
datalines;
14:56.456
45:32
;
SAS writes the following lines to the log:
14 minutes, 56 seconds, 456 milliseconds
45 minutes, 32 seconds
See Also
Functions and CALL routines:
“CALL
“CALL
“CALL
“CALL
PRXCHANGE Routine” on page 465
PRXDEBUG Routine” on page 468
PRXFREE Routine” on page 470
PRXNEXT Routine” on page 471
“CALL PRXSUBSTR Routine” on page 476
“CALL PRXCHANGE Routine” on page 465
“PRXCHANGE Function” on page 994
“PRXPAREN Function” on page 1003
“PRXMATCH Function” on page 999
“PRXPARSE Function” on page 1005
“PRXPOSN Function” on page 1007
4
CALL PRXPOSN Routine
475
476
CALL PRXSUBSTR Routine
4
Chapter 4
CALL PRXSUBSTR Routine
Returns the position and length of a substring that matches a pattern.
Category:
Restriction:
Character String Matching
Use with the PRXPARSE function.
When invoked by the %SYSCALL macro statement, CALL PRXSUBSTR
removes the quotation marks from its arguments. For more information, see “Using
CALL Routines and the %SYSCALL Macro Statement” on page 303.
Interaction:
Syntax
CALL PRXSUBSTR (regular-expression-id, source, position <, length>);
Arguments
regular-expression-id
specifies a numeric variable with a value that is an identification number that is
returned by the PRXPARSE function.
source
specifies a character constant, variable, or expression that you want to search.
position
is a numeric variable with a returned value that is the position in source where the
pattern begins. If no match is found, CALL PRXSUBSTR returns zero.
length
is a numeric variable with a returned value that is the length of the substring that is
matched by the pattern. If no match is found, CALL PRXSUBSTR returns zero.
Details
The CALL PRXSUBSTR routine searches the variable source with the pattern from
PRXPARSE, returns the position of the start of the string, and if specified, returns the
length of the string that is matched. By default, when a pattern matches more than one
character that begins at a specific position, CALL PRXSUBSTR selects the longest
match.
For more information about pattern matching, see “Pattern Matching Using Perl
Regular Expressions (PRX)” on page 323.
Comparisons
CALL PRXSUBSTR performs the same matching as PRXMATCH, but CALL
PRXSUBSTR additionally enables you to use the length argument to receive more
information about the match.
The Perl regular expression (PRX) functions and CALL routines work together to
manipulate strings that match patterns. To see a list and short description of these
functions and CALL routines, see the Character String Matching category in “Functions
and CALL Routines by Category” on page 335.
Functions and CALL Routines
4
CALL PRXSUBSTR Routine
Examples
Example 1: Finding the Position and Length of a Substring
The following example
searches a string for a substring, and returns its position and length in the string.
data _null_;
/* Use PRXPARSE to compile the Perl regular expression. */
patternID = prxparse(’/world/’);
/* Use PRXSUBSTR to find the position and length of the string. */
call prxsubstr(patternID, ’Hello world!’, position, length);
put position= length=;
run;
The following line is written to the SAS log:
position=7 length=5
Example 2: Finding a Match in a Substring
The following example searches for
addresses that contain avenue, drive, or road, and extracts the text that was found.
data _null_;
if _N_ = 1 then
do;
retain ExpressionID;
/* The i option specifies a case insensitive search. */
pattern = "/ave|avenue|dr|drive|rd|road/i";
ExpressionID = prxparse(pattern);
end;
input street $80.;
call prxsubstr(ExpressionID, street, position, length);
if position ^= 0 then
do;
match = substr(street, position, length);
put match:$QUOTE. "found in " street:$QUOTE.;
end;
datalines;
153 First Street
6789 64th Ave
4 Moritz Road
7493 Wilkes Place
;
run;
The following lines are written to the SAS log:
"Ave" found in "6789 64th Ave"
"Road" found in "4 Moritz Road"
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 465
477
478
4
CALL RANBIN Routine
Chapter 4
“CALL PRXDEBUG Routine” on page 468
“CALL PRXFREE Routine” on page 470
“CALL PRXNEXT Routine” on page 471
“CALL PRXPOSN Routine” on page 473
“PRXCHANGE Function” on page 994
“PRXPAREN Function” on page 1003
“PRXMATCH Function” on page 999
“PRXPARSE Function” on page 1005
“PRXPOSN Function” on page 1007
CALL RANBIN Routine
Returns a random variate from a binomial distribution.
Category:
Random Number
Syntax
CALL RANBIN(seed,n,p,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANBIN is
executed.
31
Range: seed < 2 - 1
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
n
is an integer number of independent Bernoulli trials.
Range: n > 0
p
is a numeric probability of success parameter.
Range: 0<p<1
x
is a numeric SAS variable. A new value for the random variate x is returned each
time CALL RANBIN is executed.
Details
The CALL RANBIN routine updates seed and returns a variate x that is generated from
a binomial distribution with mean np and variance np(1–p). If n 50, np 5, or
n(1–p) 5, SAS uses an inverse transform method applied to a RANUNI uniform
variate. If n>50, np>5, and n(1–p)>5, SAS uses the normal approximation to the
Functions and CALL Routines
4
CALL RANBIN Routine
479
binomial distribution. In that case, the Box-Muller transformation of RANUNI uniform
variates is used.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANBIN routine gives greater control of the seed and random number
streams than does the RANBIN function.
Examples
The following example uses the CALL RANBIN routine:
options pageno=1 nodate ls=80 ps=64;
data u1 (keep = x);
seed = 104;
do i = 1 to 5;
call ranbin(seed, 2000, 0.2 ,x);
output;
end;
call symputx(’seed’, seed);
run;
data u2 (keep = x);
seed = &seed;
do i = 1 to 5;
call ranbin(seed, 2000, 0.2 ,x);
output;
end;
run;
data all;
set u1 u2;
z = ranbin(104, 2000, 0.2);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
480
4
CALL RANCAU Routine
Output 4.14
Chapter 4
Output from the CALL RANBIN Routine
The SAS System
Obs
1
2
3
4
5
6
7
8
9
10
Separate
Streams
423
418
403
394
429
369
413
417
400
383
1
Single
Stream
423
418
403
394
429
369
413
417
400
383
See Also
Functions:
“RAND Function” on page 1022
“RANBIN Function” on page 1020
CALL RANCAU Routine
Returns a random variate from a Cauchy distribution.
Category:
Random Number
Syntax
CALL RANCAU(seed,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANCAU is
executed.
Range:
Note:
31
seed < 2 - 1
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
See:
x
is a numeric SAS variable. A new value for the random variate x is returned each
time CALL RANCAU is executed.
Functions and CALL Routines
4
CALL RANCAU Routine
481
Details
The CALL RANCAU routine updates seed and returns a variate x that is generated
from a Cauchy distribution that has a location parameter of 0 and scale parameter of 1.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
An acceptance-rejection procedure applied to RANUNI uniform variates is used. If u
2
2
and v are independent uniform (−1/2, 1/2) variables and u +v ≤ 1/4, then u/v is a
Cauchy variate.
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANCAU routine gives greater control of the seed and random number
streams than does the RANCAU function.
Examples
options nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
do i=1 to 10;
call rancau(Seed_1,X1);
call rancau(Seed_2,X2);
X3=rancau(Seed_3);
if i=5 then
do;
Seed_2=18;
Seed_3=18;
end;
output;
end;
run;
proc print;
id i;
var Seed_1-Seed_3 X1-X3;
run;
This example uses the CALL RANCAU routine:
options pageno=1 ls=80 ps=64 nodate;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call rancau(seed, X);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
482
CALL RANEXP Routine
4
Chapter 4
do i = 1 to 5;
call rancau(seed, X);
output;
end;
run;
data all;
set u1 u2;
z = rancau(104);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.15
Output from the CALL RANCAU Routine
The SAS System
1
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
-0.6780
0.1712
1.1372
0.1478
16.6536
0.0747
-0.5872
1.4713
0.1792
-0.0473
-0.6780
0.1712
1.1372
0.1478
16.6536
0.0747
-0.5872
1.4713
0.1792
-0.0473
See Also
Functions:
“RAND Function” on page 1022
“RANCAU Function” on page 1021
CALL RANEXP Routine
Returns a random variate from an exponential distribution.
Category:
Random Number
Syntax
CALL RANEXP(seed,x);
Arguments
Functions and CALL Routines
4
CALL RANEXP Routine
483
seed
is the seed value. A new value for seed is returned each time CALL RANEXP is
executed.
31
Range: seed < 2 - 1
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
x
is a numeric variable. A new value for the random variate x is returned each time
CALL RANEXP is executed.
Details
The CALL RANEXP routine updates seed and returns a variate x that is generated
from an exponential distribution that has a parameter of 1.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
The CALL RANEXP routine uses an inverse transform method applied to a RANUNI
uniform variate.
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANEXP routine gives greater control of the seed and random number
streams than does the RANEXP function.
Examples
This example uses the CALL RANEXP routine:
options pageno=1 ls=80 ps=64 nodate;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call ranexp(seed, x);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call ranexp(seed, x);
output;
end;
run;
data all;
set u1 u2;
z = ranexp(104);
run;
484
CALL RANGAM Routine
4
Chapter 4
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.16
Output from the CALL RANEXP Routine
The SAS System
1
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
1.44347
0.11740
0.54175
0.02280
0.16645
0.21711
0.75538
1.21760
1.72273
0.08021
1.44347
0.11740
0.54175
0.02280
0.16645
0.21711
0.75538
1.21760
1.72273
0.08021
See Also
Functions:
“RAND Function” on page 1022
“RANEXP Function” on page 1033
CALL RANGAM Routine
Returns a random variate from a gamma distribution.
Category:
Random Number
Syntax
CALL RANGAM(seed,a,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANGAM is
executed.
31
Range: seed < 2 - 1
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in
Random-Number Functions and CALL Routines” on page 309 for more information
about seed values
Functions and CALL Routines
4
CALL RANGAM Routine
a
is a numeric shape parameter.
Range: a > 0
x
is a numeric variable. A new value for the random variate x is returned each time
CALL RANGAM is executed.
Details
The CALL RANGAM routine updates seed and returns a variate x that is generated
from a gamma distribution with parameter a.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
For a>1, an acceptance-rejection method by Cheng is used (Cheng, 1977; see in
“References” on page 1197). For a 1, an acceptance-rejection method by Fishman is
used (Fishman, 1978; see in “References” on page 1197).
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANGAM routine gives greater control of the seed and random number
streams than does the RANGAM function.
Examples
This example uses the CALL RANGAM routine:
options nodate pageno=1 linesize=80 pagesize=60;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call rangam(seed, x);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call rangam(seed, x);
output;
end;
run;
data all;
set u1 u2;
z = rangam(104);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
485
486
CALL RANNOR Routine
4
Chapter 4
run;
Output 4.17
Output from the CALL RANGAM Routine
The SAS System
Output 4.18
1
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
1.44347
0.11740
0.54175
0.02280
0.16645
0.21711
0.75538
1.21760
1.72273
0.08021
1.44347
0.11740
0.54175
0.02280
0.16645
0.21711
0.75538
1.21760
1.72273
0.08021
The RANGAM Example
The SAS System
i
Seed_1
1
2
3
4
5
6
7
8
9
10
1404437564
1326029789
1988843719
50049159
802575599
100573943
1986749826
52428589
1216356463
805366679
Seed_2
1404437564
1326029789
1988843719
50049159
18
991271755
1437043694
959908645
1225034217
425626811
1
Seed_3
X1
45
45
45
45
18
18
18
18
18
18
1.30569
1.87514
1.71597
1.59304
0.43342
1.11812
0.68415
1.62296
2.26455
2.16723
X2
1.30569
1.87514
1.71597
1.59304
0.43342
1.32646
0.88806
2.46091
4.06596
6.94703
X3
1.30569
1.87514
1.71597
1.59304
0.43342
1.11812
0.68415
1.62296
2.26455
2.16723
Changing Seed_2 for the CALL RANGAM statement, when I=5, forces the stream of
the variates for X2 to deviate from the stream of the variates for X1. Changing Seed_3
on the RANGAM function, however, has no effect.
See Also
Functions:
“RAND Function” on page 1022
“RANGAM Function” on page 1034
CALL RANNOR Routine
Returns a random variate from a normal distribution.
Category:
Random Number
Functions and CALL Routines
4
CALL RANNOR Routine
487
Syntax
CALL RANNOR(seed,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANNOR is
executed.
31
Range: seed < 2 - 1
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
x
is a numeric variable. A new value for the random variate x is returned each time
CALL RANNOR is executed.
Details
The CALL RANNOR routine updates seed and returns a variate x that is generated
from a normal distribution, with mean 0 and variance 1.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
The CALL RANNOR routine uses the Box-Muller transformation of RANUNI
uniform variates.
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANNOR routine gives greater control of the seed and random number
streams than does the RANNOR function.
Examples
This example uses the CALL RANNOR routine:
options pageno=1 ls=80 ps=64 nodate;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call rannor(seed, X);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
488
4
CALL RANPERK Routine
Chapter 4
seed = &seed;
do i = 1 to 5;
call rannor(seed, X);
output;
end;
run;
data all;
set u1 u2;
z = rannor(104);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.19
Output from the CALL RANNOR Routine
The SAS System
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
1.30390
1.03049
0.19491
-0.34987
1.64273
-1.75842
0.75080
0.94375
0.02436
-0.97256
1.30390
1.03049
0.19491
-0.34987
1.64273
-1.75842
0.75080
0.94375
0.02436
-0.97256
1
See Also
Functions:
“RAND Function” on page 1022
“RANNOR Function” on page 1037
CALL RANPERK Routine
Randomly permutes the values of the arguments, and returns a permutation of k out of n values.
Category:
Combinatorial
Syntax
CALL RANPERK(seed, k, variable-1<, variable–2, ...>);
Functions and CALL Routines
4
CALL RANPERK Routine
489
Arguments
seed
is a numeric variable that contains the random number seed. For more information
about seeds, see “Seed Values” on page 305.
k
is the number of values that you want to have in the random permutation.
variable
specifies all numeric variables, or all character variables that have the same length.
K values of these variables are randomly permuted.
Details
Using CALL RANPERK with Macros
You can call the RANPERK routine when you use
the %SYSCALL macro. In this case, the variable arguments are not required to be the
same type or length. If %SYSCALL identifies an argument as numeric, then
%SYSCALL reformats the returned value.
If an error occurs during the execution of the CALL RANPERK routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than -100.
If there are no errors, then &SYSERR and &SYSINFO are set to zero.
Examples
Example 1: Using CALL RANPERK in a DATA Step
The following example shows how to
generate random permutations of given values by using the CALL RANPERK routine.
data _null_;
array x x1-x5 (1 2 3 4 5);
seed = 1234567890123;
do n=1 to 10;
call ranperk(seed, 3, of x1-x5);
put seed= @20 ’ x= ’ x1-x3;
end;
run;
Output 4.20
Log Output from Using the CALL RANPERK Routine in a DATA Step
seed=1332351321
seed=829042065
seed=767738639
seed=1280236105
seed=670350431
seed=1956939964
seed=353939815
seed=1996660805
seed=1835940555
seed=910897519
x=
x=
x=
x=
x=
x=
x=
x=
x=
x=
5
4
5
3
4
3
4
3
5
5
4
1
1
2
3
1
2
4
1
1
2
3
2
5
5
2
1
5
4
2
Example 2: Using CALL RANPERK with a Macro
The following is an example of the
CALL RANPERK routine that is used with macros.
490
4
CALL RANPERM Routine
Chapter 4
%macro test;
%let x1=ant;
%let x2=-.1234;
%let x3=1e10;
%let x4=hippopotamus;
%let x5=zebra;
%let k=3;
%let seed = 12345;
%do j=1 %to 10;
%syscall ranperk(seed, k, x1, x2, x3, x4, x5);
%put j=&j
&x1 &x2 &x3;
%end;
%mend;
%test;
Output 4.21
j=1
j=2
j=3
j=4
j=5
j=6
j=7
j=8
j=9
j=10
Output from Using the CALL RANPERK Routine with a Macro
-0.1234 hippopotamus zebra
hippopotamus -0.1234 10000000000
hippopotamus ant zebra
-0.1234 zebra ant
-0.1234 ant hippopotamus
10000000000 hippopotamus ant
10000000000 hippopotamus ant
ant 10000000000 -0.1234
zebra -0.1234 10000000000
zebra hippopotamus 10000000000
See Also
Functions and CALL Routines:
“RAND Function” on page 1022
“CALL ALLPERM Routine” on page 424
“CALL RANPERM Routine” on page 490
CALL RANPERM Routine
Randomly permutes the values of the arguments.
Category:
Combinatorial
Syntax
CALL RANPERM(seed, variable-1<, variable–2, ...>);
Arguments
seed
Functions and CALL Routines
4
CALL RANPERM Routine
491
is a numeric variable that contains the random number seed. For more information
about seeds, see “Seed Values” on page 305.
variable
specifies all numeric variables or all character variables that have the same length.
The values of these variables are randomly permuted.
Details
Using CALL RANPERM with Macros
You can call the RANPERM routine when you use
the %SYSCALL macro. In this case, the variable arguments are not required to be the
same type or length. If %SYSCALL identifies an argument as numeric, then
%SYSCALL reformats the returned value.
If an error occurs during the execution of the CALL RANPERM routine, then both of
the following values are set:
3 &SYSERR is assigned a value that is greater than 4.
3 &SYSINFO is assigned a value that is less than -100.
If there are no errors, then &SYSERR and &SYSINFO are set to zero.
Examples
Example 1: Using CALL RANPERM in a DATA Step
The following example generates
random permutations of given values by using the CALL RANPERM routine.
data _null_;
array x x1-x4 (1 2 3 4);
seed = 1234567890123;
do n=1 to 10;
call ranperm(seed, of x1-x4);
put seed= @20 ’ x= ’ x1-x4;
end;
run;
Output 4.22
Output from Using the CALL RANPERM Routine in a DATA Step
seed=1332351321
seed=829042065
seed=767738639
seed=1280236105
seed=670350431
seed=1956939964
seed=353939815
seed=1996660805
seed=1835940555
seed=910897519
x=
x=
x=
x=
x=
x=
x=
x=
x=
x=
1
3
4
1
2
2
4
4
4
3
3
4
2
2
1
4
1
3
3
2
2
2
3
4
4
3
2
1
2
1
4
1
1
3
3
1
3
2
1
4
Example 2: Using CALL RANPERM with a Macro
The following is an example of the
CALL RANPERM routine that is used with the %SYSCALL macro.
%macro test;
%let x1=ant;
%let x2=-.1234;
%let x3=1e10;
%let x4=hippopotamus;
492
CALL RANPOI Routine
4
Chapter 4
%let x5=zebra;
%let seed = 12345;
%do j=1 %to 10;
%syscall ranperm(seed, x1, x2, x3, x4, x5);
%put j=&j
&x1 &x2 &x3;
%end;
%mend;
%test;
Output 4.23
j=1
j=2
j=3
j=4
j=5
j=6
j=7
j=8
j=9
j=10
Output from Using the CALL RANPERM Routine with a Macro
zebra ant hippopotamus
10000000000 ant -0.1234
-0.1234 10000000000 ant
hippopotamus ant zebra
-0.1234 zebra 10000000000
-0.1234 hippopotamus ant
zebra ant -0.1234
-0.1234 hippopotamus ant
ant -0.1234 hippopotamus
-0.1234 zebra 10000000000
See Also
Functions and CALL Routines:
“RAND Function” on page 1022
“CALL ALLPERM Routine” on page 424
“CALL RANPERK Routine” on page 488
CALL RANPOI Routine
Returns a random variate from a Poisson distribution.
Category:
Random Number
Syntax
CALL RANPOI(seed,m,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANPOI is
executed.
Range:
31
seed < 2 - 1
Functions and CALL Routines
4
CALL RANPOI Routine
493
If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
Note:
m
is a numeric mean parameter.
Range: m 0
x
is a numeric variable. A new value for the random variate x is returned each time
CALL RANPOI is executed.
Details
The CALL RANPOI routine updates seed and returns a variate x that is generated from
a Poisson distribution, with mean m.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
For m< 85, an inverse transform method applied to a RANUNI uniform variate is
used (Fishman, 1976; see in “References” on page 1197). For m ≥ 85, the normal
approximation of a Poisson random variable is used. To expedite execution, internal
variables are calculated only on initial calls (that is, with each new m).
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANPOI routine gives greater control of the seed and random number
streams than does the RANPOI function.
Examples
This example uses the CALL RANPOI routine:
options pageno=1 ls=80 ps=64 nodate;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call ranpoi(seed, 2000, x);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call ranpoi(seed, 2000, x);
output;
end;
run;
494
CALL RANTBL Routine
4
Chapter 4
data all;
set u1 u2;
z = ranpoi(104, 2000);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.24
Output from the CALL RANPOI Routine
The SAS System
1
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
2058
2046
2009
1984
2073
1921
2034
2042
2001
1957
2058
2046
2009
1984
2073
1921
2034
2042
2001
1957
See Also
Functions:
“RAND Function” on page 1022
“RANPOI Function” on page 1038
CALL RANTBL Routine
Returns a random variate from a tabled probability distribution.
Category:
Random Number
Syntax
CALL RANTBL(seed,p1,...pi,...pn,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANTBL is
executed.
31
Range: seed < 2 - 1
Functions and CALL Routines
4
CALL RANTBL Routine
495
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
pi
is a numeric SAS value.
Range: 0 pi 1 for 0< i n
x
is a numeric SAS variable. A new value for the random variate x is returned each
time CALL RANTBL is executed.
Details
The CALL RANTBL routine updates seed and returns a variate x generated from the
probability mass function defined by p1 through pn.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
An inverse transform method applied to a RANUNI uniform variate is used. The
CALL RANTBL routine returns these data:
1
2
with probability p1
with probability p2
:
:
:
X
n + 1 with probability 1 0
n
with probability pn
n
i
If, for some index j<n,
X
j
=1
pi
=1
X
n
pi
if
i
=1
pi
1
1
i
RANTBL returns only the indices 1 through j, with the probability of occurrence of
the index j equal to
1
0
X01 i
j
=1
p
i
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANTBL routine gives greater control of the seed and random number
streams than does the RANTBL function.
496
CALL RANTBL Routine
4
Chapter 4
Examples
This example uses the CALL RANTBL routine:
options pageno=1 ls=80 ps=64 nodate;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call rantbl(seed, .02, x);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call rantbl(seed, .02, x);
output;
end;
run;
data all;
set u1 u2;
z = rantbl(104, .02);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.25
Output from the CALL RANTBL Routine
The SAS System
Obs
Separate
Streams
1
2
3
4
5
6
7
8
9
10
2
2
2
2
2
2
2
2
2
2
See Also
Functions:
“RAND Function” on page 1022
“RANTBL Function” on page 1039
1
Single
Stream
2
2
2
2
2
2
2
2
2
2
Functions and CALL Routines
4
CALL RANTRI Routine
497
CALL RANTRI Routine
Returns a random variate from a triangular distribution.
Category: Random Number
Syntax
CALL RANTRI(seed,h,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANTRI is
executed.
31
Range: seed < 2 - 1
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
See: “Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
h
is a numeric SAS value.
Range: 0<h<1
x
is a numeric SAS variable. A new value for the random variate x is returned each
time CALL RANTRI is executed.
Details
The CALL RANTRI routine updates seed and returns a variate x generated from a
triangular distribution on the interval (0,1) with parameter h, which is the modal value
of the distribution.
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
The CALL RANTRI routine uses an inverse transform method applied to a RANUNI
uniform variate.
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANTRI routine gives greater control of the seed and random number
streams than does the RANTRI function.
Examples
This example uses the CALL RANTRI routine:
options pageno=1 ls=80 ps=64 nodate;
498
CALL RANTRI Routine
4
Chapter 4
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call rantri(seed, .5, x);
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call rantri(seed, .5, x);
output;
end;
run;
data all;
set u1 u2;
z = rantri(104, .5);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
Output 4.26
Output from the CALL RANTRI Routine
The SAS System
1
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
0.34359
0.76466
0.54269
0.89384
0.72311
0.68763
0.48468
0.38467
0.29881
0.80369
0.34359
0.76466
0.54269
0.89384
0.72311
0.68763
0.48468
0.38467
0.29881
0.80369
See Also
Functions:
“RAND Function” on page 1022
“RANTRI Function” on page 1040
Functions and CALL Routines
4
CALL RANUNI Routine
499
CALL RANUNI Routine
Returns a random variate from a uniform distribution.
Category: Random Number
Syntax
CALL RANUNI(seed,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANUNI is
executed.
31
Range: seed < 2 - 1
Tip:
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 305 and “Comparison of Seed Values in Random-Number
Functions and CALL Routines” on page 309 for more information about seed values
See:
x
is a numeric variable. A new value for the random variate x is returned each time
CALL RANUNI is executed.
Details
The CALL RANUNI routine updates seed and returns a variate x that is generated
from the uniform distribution on the interval (0,1), using a prime modulus
31
multiplicative generator with modulus 2 –1 and multiplier 397204094 (Fishman and
Moore 1982) (See “References” on page 1197).
By adjusting the seeds, you can force streams of variates to agree or disagree for
some or all of the observations in the same, or in subsequent, DATA steps.
For a discussion and example of an effective use of the random number CALL
routines, see “Starting, Stopping, and Restarting a Stream” on page 316.
Comparisons
The CALL RANUNI routine gives greater control of the seed and random number
streams than does the RANUNI function.
Examples
This example uses the CALL RANUNI routine:
options pageno=1 nodate ls=80 ps=64;
data u1(keep=x);
seed = 104;
do i = 1 to 5;
call ranuni(seed, x);
500
CALL SCAN Routine
4
Chapter 4
output;
end;
call symputx(’seed’, seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call ranuni(seed, x);
output;
end;
run;
data all;
set u1 u2;
z = ranuni(104);
run;
proc print label;
label x = ’Separate Streams’ z = ’Single Stream’;
run;
The following output shows the results:
Output 4.27
Output from the CALL RANUNI Routine
The SAS System
1
Obs
Separate
Streams
Single
Stream
1
2
3
4
5
6
7
8
9
10
0.23611
0.88923
0.58173
0.97746
0.84667
0.80484
0.46983
0.29594
0.17858
0.92292
0.23611
0.88923
0.58173
0.97746
0.84667
0.80484
0.46983
0.29594
0.17858
0.92292
See Also
Functions:
“RAND Function” on page 1022
“RANUNI Function” on page 1041
CALL SCAN Routine
Returns the position and length of the nth word from a character string.
Functions and CALL Routines
4
CALL SCAN Routine
501
Category: Character
When invoked by the %SYSCALL macro statement, CALL SCAN removes
the quotation marks from its arguments. For more information, see “Using CALL
Routines and the %SYSCALL Macro Statement” on page 303.
Interaction:
Syntax
CALL SCAN(<string>, count, position, length <, <charlist> <, < modifier(s)>>>);
Arguments
string
specifies a character constant, variable, or expression.
count
is a non-zero numeric constant, variable, or expression that has an integer value that
specifies the number of the word in the character string that you want the CALL
SCAN routine to select. For example, a value of 1 indicates the first word, a value of
2 indicates the second word, and so on. The following rules apply:
3 If count is positive, then CALL SCAN counts words from left to right in the
character string.
3 If count is negative, then CALL SCAN counts words from right to left in the
character string.
position
specifies a numeric variable in which the position of the word is returned. If count
exceeds the number of words in the string, then the value that is returned in position
is zero. If count is zero or missing, then the value that is returned in position is
missing.
length
specifies a numeric variable in which the length of the word is returned. If count
exceeds the number of words in the string, then the value that is returned in length is
zero. If count is zero or missing, then the value that is returned in length is missing.
charlist
specifies an optional character constant, variable, or expression that initializes a list
of characters. This list determines which characters are used as the delimiters that
separate words. The following rules apply:
3 By default, all characters in charlist are used as delimiters.
3 If you specify the K modifier in the modifier argument, then all characters that
are not in charlist are used as delimiters.
Tip:
You can add more characters to charlist by using other modifiers.
modifier
specifies a character constant, variable, or expression in which each non-blank
character modifies the action of the CALL SCAN routine. Blanks are ignored. You
can use the following characters as modifiers:
a or A
adds alphabetic characters to the list of characters.
b or B
scans backwards, from right to left instead of from left to right,
regardless of the sign of the count argument.
502
CALL SCAN Routine
4
Chapter 4
c or C
adds control characters to the list of characters.
d or D
adds digits to the list of characters.
f or F
adds an underscore and English letters (that is, valid first
characters in a SAS variable name using VALIDVARNAME=V7)
to the list of characters.
g or G
adds graphic characters to the list of characters. Graphic
characters are those that, when printed, produce an image on
paper.
h or H
adds a horizontal tab to the list of characters.
i or I
ignores the case of the characters.
k or K
causes all characters that are not in the list of characters to be
treated as delimiters. That is, if K is specified, then characters
that are in the list of characters are kept in the returned value
rather than being omitted because they are delimiters. If K is not
specified, then all characters that are in the list of characters are
treated as delimiters.
l or L
adds lower case letters to the list of characters.
m or M
specifies that multiple consecutive delimiters, and delimiters at
the beginning or end of the string argument, refer to words that
have a length of zero. If the M modifier is not specified, then
multiple consecutive delimiters are treated as one delimiter, and
delimiters at the beginning or end of the string argument are
ignored.
n or N
adds digits, an underscore, and English letters (that is, the
characters that can appear in a SAS variable name using
VALIDVARNAME=V7) to the list of characters.
o or O
processes the charlist and modifier arguments only once, rather
than every time the CALL SCAN routine is called.
Tip: Using the O modifier in the DATA step can make CALL
SCAN run faster when you call it in a loop where the charlist
and modifier arguments do not change. The O modifier applies
separately to each instance of the CALL SCAN routine in your
SAS code, and does not cause all instances of the CALL SCAN
routine to use the same delimiters and modifiers.
p or P
adds punctuation marks to the list of characters.
q or Q
ignores delimiters that are inside of substrings that are enclosed
in quotation marks. If the value of the string argument contains
unmatched quotation marks, then scanning from left to right will
produce different words than scanning from right to left.
s or S
adds space characters to the list of characters (blank, horizontal
tab, vertical tab, carriage return, line feed, and form feed).
t or T
trims trailing blanks from the string and charlist arguments.
Tip: If you want to remove trailing blanks from just one
character argument instead of both character arguments, then
use the TRIM function instead of the CALL SCAN routine with
the T modifier.
u or U
adds upper case letters to the list of characters.
Functions and CALL Routines
w or W
4
CALL SCAN Routine
503
adds printable (writable) characters to the list of characters.
x or X
adds hexadecimal characters to the list of characters.
Tip: If the modifier argument is a character constant, then enclose it in quotation
marks. Specify multiple modifiers in a single set of quotation marks. A modifier
argument can also be expressed as a character variable or expression.
Details
Definition of ”Delimiter” and “Word”
A delimiter is any of several characters that are
used to separate words. You can specify the delimiters in the charlist and modifier
arguments.
If you specify the Q modifier, then delimiters inside of substrings that are enclosed in
quotation marks are ignored.
In the CALL SCAN routine, “word” refers to a substring that has all of the following
characteristics:
3 is bounded on the left by a delimiter or the beginning of the string
3 is bounded on the right by a delimiter or the end of the string
3 contains no delimiters
A word can have a length of zero if there are delimiters at the beginning or end of
the string, or if the string contains two or more consecutive delimiters. However, the
CALL SCAN routine ignores words that have a length of zero unless you specify the M
modifier.
Using Default Delimiters in ASCII and EBCDIC Environments
If you use the CALL
SCAN routine with only four arguments, then the default delimiters depend on whether
your computer uses ASCII or EBCDIC characters.
3 If your computer uses ASCII characters, then the default delimiters are as follows:
blank ! $ % & ( )* + , - . / ; < ^
In ASCII environments that do not contain the ^ character, the CALL SCAN
routine uses the ~ character instead.
3 If your computer uses EBCDIC characters, then the default delimiters are as
follows:
blank ! $ % & ( )* + , - . / ; < | ¢
If you use the modifier argument without specifying any characters as delimiters,
then the only delimiters that will be used are those that are defined by the modifier
argument. In this case, the lists of default delimiters for ASCII and EBCDIC
environments are not used. In other words, modifiers add to the list of delimiters that
are explicitly specified by the charlist argument. Modifiers do not add to the list of
default modifiers.
Using the CALL SCAN Routine with the M Modifier
If you specify the M modifier, then
the number of words in a string is defined as one plus the number of delimiters in the
string. However, if you specify the Q modifier, delimiters that are inside quotation
marks are ignored.
If you specify the M modifier, the CALL SCAN routine returns a positive position and
a length of zero if one of the following conditions is true:
3 The string begins with a delimiter and you request the first word.
3 The string ends with a delimiter and you request the last word.
3 The string contains two consecutive delimiters and you request the word that is
between the two delimiters.
504
CALL SCAN Routine
4
Chapter 4
In you specify a count that is greater in absolute value than the number of words in
the string, then the CALL SCAN routine returns a position and length of zero.
Using the CALL SCAN Routine without the M Modifier
If you do not specify the M
modifier, then the number of words in a string is defined as the number of maximal
substrings of consecutive non-delimiters. However, if you specify the Q modifier,
delimiters that are inside quotation marks are ignored.
If you do not specify the M modifier, then the CALL SCAN routine does the following:
3 ignores delimiters at the beginning or end of the string
3 treats two or more consecutive delimiters as if they were a single delimiter
If the string contains no characters other than delimiters, or if you specify a count
that is greater in absolute value than the number of words in the string, then the CALL
SCAN routine returns a position and length of zero.
Finding the Word as a Character String
To find the designated word as a character
string after calling the CALL SCAN routine, use the SUBSTRN function with the
string, position, and length arguments:
substrn(string, position, length);
Because CALL SCAN can return a length of zero, using the SUBSTR function can
cause an error.
Using Null Arguments
The CALL SCAN routine allows character arguments to be
null. Null arguments are treated as character strings with a length of zero. Numeric
arguments cannot be null.
Examples
Example 1: Scanning for a Word in a String
The following example shows how you
can use the CALL SCAN routine to find the position and length of a word in a string.
options pageno=1 nodate ls=80 ps=64;
data artists;
input string $60.;
drop string;
do i=1 to 99;
call scan(string, i, position, length);
if not position then leave;
Name=substrn(string, position, length);
output;
end;
datalines;
Picasso Toulouse-Lautrec Turner "Van Gogh" Velazquez
;
proc print data=artists;
run;
Functions and CALL Routines
Output 4.28
4
CALL SCAN Routine
505
SAS Output: Scanning for a Word in a String
The SAS System
Obs
i
position
1
2
3
4
5
6
7
1
2
3
4
5
6
7
1
9
18
26
33
38
44
length
7
8
7
6
4
5
9
1
Name
Picasso
Toulouse
Lautrec
Turner
"Van
Gogh"
Velazquez
Example 2: Finding the First and Last Words in a String
The following example scans
a string for the first and last words. Note the following:
3 A negative count instructs the CALL SCAN routine to scan from right to left.
3 Leading and trailing delimiters are ignored because the M modifier is not used.
3 In the last observation, all characters in the string are delimiters, so no words are
found.
options pageno=1 nodate ls=80 ps=64;
data firstlast;
input String $60.;
call scan(string, 1, First_Pos, First_Length);
First_Word = substrn(string, First_Pos, First_Length);
call scan(string, --1, Last_Pos, Last_Length);
Last_Word = substrn(string, Last_Pos, Last_Length);
datalines4;
Jack and Jill
& Bob & Carol & Ted & Alice &
Leonardo
! $ % & ( ) * + , - . / ;
;;;;
proc print data=firstlast;
var First: Last:;
run;
Output 4.29
Results of Finding the First and Last Words in a String
The SAS System
Obs
1
2
3
4
First_
Pos
1
3
1
0
First_
Length
4
3
8
0
First_
Word
Jack
Bob
Leonardo
1
Last_Pos
Last_
Length
10
23
1
0
4
5
8
0
Last_
Word
Jill
Alice
Leonardo
506
CALL SCAN Routine
4
Chapter 4
Example 3: Finding All Words in a String without Using the M Modifier
The following
example scans a string from left to right until no more words are found. Because the M
modifier is not used, the CALL SCAN routine does not return any words that have a
length of zero. Because blanks are included among the default delimiters, the CALL
SCAN routine returns a position or length of zero only when the count exceeds the
number of words in the string. The loop can be stopped when the returned position is
less than or equal to zero. It is safer to use an inequality comparison to end the loop,
rather than to use a strict equality comparison with zero, in case an error causes the
position to be missing. (In SAS, a missing value is considered to have a lesser value
than any nonmissing value.)
options pageno=1 nodate ls=80 ps=64;
data all;
length word $20;
drop string;
string = ’ The quick brown fox jumps over the lazy dog.
do until(position <= 0);
count+1;
call scan(string, count, position, length);
word = substrn(string, position, length);
output;
end;
run;
’;
proc print data=all noobs;
var count position length word;
run;
Output 4.30
Results of Finding All Words in a String without Using the M Modifier
The SAS System
count
1
2
3
4
5
6
7
8
9
10
position
length
2
6
12
18
22
28
33
37
42
0
3
5
5
3
5
4
3
4
3
0
1
word
The
quick
brown
fox
jumps
over
the
lazy
dog
Example 4: Finding All Words in a String by Using the M and O Modifiers
The
following example shows the results of using the M modifier with a comma as a
delimiter. With the M modifier, leading, trailing, and multiple consecutive delimiters
cause the CALL SCAN routine to return words that have a length of zero.
The O modifier is used for efficiency because the delimiters and modifiers are the
same in every call to the CALL SCAN routine.
options pageno=1 nodate ls=80 ps=64;
data comma;
Functions and CALL Routines
4
CALL SCAN Routine
507
length word $30;
string = ’,leading, trailing,and multiple,,delimiters,,’;
do until(position <= 0);
count + 1;
call scan(string, count, position, length, ’,’, ’mo’);
word = substrn(string, position, length);
output;
end;
run;
proc print data=comma noobs;
var count position length word;
run;
Output 4.31
Results of Finding All Words in a String by Using the M and O Modifiers
The SAS System
count
position
length
1
2
3
4
5
6
7
8
9
1
2
10
21
34
35
46
47
0
0
7
10
12
0
10
0
0
0
1
word
leading
trailing
and multiple
delimiters
Example 5: Using Comma-Separated Values, Substrings in Quotation Marks, and the O
Modifier
The following example uses the CALL SCAN routine with the O modifier
and a comma as a delimiter.
The O modifier is used for efficiency because in each call of the CALL SCAN routine,
the delimiters and modifiers do not change.
options pageno=1 nodate ls=80 ps=64;
data test;
length word word_r $30;
string = ’He said, "She said, ""No!""", not "Yes!"’;
do until(position <= 0);
count + 1;
call scan(string, count, position, length, ’,’, ’oq’);
word = substrn(string, position, length);
output;
end;
run;
proc print data=test noobs;
var count position length word;
run;
508
CALL SCAN Routine
4
Output 4.32
Chapter 4
Results of Comma-Separated Values and Substrings in Quotation Marks
The SAS System
count
position
length
1
2
3
4
1
9
30
0
7
20
11
0
1
word
He said
"She said, ""No!"""
not "Yes!"
Example 6: Finding Substrings of Digits by Using the D and K Modifiers
The following
example finds substrings of digits. The charlist argument is null, and consequently the
list of characters is initially empty. The D modifier adds digits to the list of characters.
The K modifier treats all characters that are not in the list as delimiters. Therefore, all
characters except digits are delimiters.
options pageno=1 nodate ls=80 ps=64;
data digits;
length digits $20;
string = ’Call (800) 555--1234 now!’;
do until(position <= 0);
count+1;
call scan(string, count, position, length, , ’dko’);
digits = substrn(string, position, length);
output;
end;
run;
proc print data=digits noobs;
var count position length digits;
run;
Output 4.33
Results of Finding Substrings of Digits by Using the D and K Modifiers
The SAS System
count
position
1
2
3
4
7
12
16
0
See Also
Function:
“SCAN Function” on page 1060
“FINDW Function” on page 713
“COUNTW Function” on page 598
length
3
3
4
0
1
digits
800
555
1234
Functions and CALL Routines
4
CALL SET Routine
509
CALL SET Routine
Links SAS data set variables to DATA step or macro variables that have the same name and data
type.
Category: Variable Control
Syntax
CALL SET(data-set-id);
Arguments
data-set-id
is the identifier that is assigned by the OPEN function when the data set is opened.
Details
Using SET can significantly reduce the coding that is required for accessing variable
values for modification or verification when you use functions to read or to manipulate a
SAS file. After a CALL SET, whenever a read is performed from the SAS data set, the
values of the corresponding macro or DATA step variables are set to the values of the
matching SAS data set variables. If the variable lengths do not match, the values are
truncated or padded according to need. If you do not use SET, then you must use the
GETVARC and GETVARN functions to move values explicitly between data set
variables and macro or DATA step variables.
As a general rule, use CALL SET immediately following OPEN if you want to link
the data set and the macro and DATA step variables.
Examples
This example uses the CALL SET routine:
3 The following statements automatically set the values of the macro variables
PRICE and STYLE when an observation is fetched:
%macro setvar;
%let dsid=%sysfunc(open(sasuser.houses,i));
/* No leading ampersand with %SYSCALL */
%syscall set(dsid);
%let rc=%sysfunc(fetchobs(&dsid,10));
%let rc=%sysfunc(close(&dsid));
%mend setvar;
%global price style;
%setvar
%put _global_;
3 The %PUT statement writes these lines to the SAS log:
GLOBAL PRICE 127150
GLOBAL STYLE CONDO
510
CALL SLEEP Routine
4
Chapter 4
3 The following statements obtain the values for the first 10 observations in
SASUSER.HOUSES and store them in MYDATA:
data mydata;
/* create variables for assignment */
/*by CALL SET */
length style $8 sqfeet bedrooms baths 8
street $16 price 8;
drop rc dsid;
dsid=open("sasuser.houses","i");
call set (dsid);
do i=1 to 10;
rc=fetchobs(dsid,i);
output;
end;
run;
See Also
Functions:
“FETCH Function” on page 658
“FETCHOBS Function” on page 659
“GETVARC Function” on page 762
“GETVARN Function” on page 763
CALL SLEEP Routine
For a specified period of time, suspends the execution of a program that invokes this CALL routine.
Category:
See:
Special
CALL SLEEP Routine in the documentation for your operating environment.
Syntax
CALL SLEEP(n<, unit>)
Arguments
n
is a numeric constant that specifies the number of units of time for which you want
to suspend execution of a program.
Range:
n≥0
unit
specifies the unit of time, as a power of 10, which is applied to n. For example, 1
corresponds to a second, and .001 corresponds to a millisecond.
Default: .001
Functions and CALL Routines
4
CALL SOFTMAX Routine
511
Details
The CALL SLEEP routine suspends the execution of a program that invokes this call
routine for a period of time that you specify. The program can be a DATA step, macro,
IML, SCL, or anything that can invoke a call routine. The maximum sleep period for
the CALL SLEEP routine is 46 days.
Examples
Example 1: Suspending Execution for a Specified Period of Time
The following
example tells SAS to suspend the execution of the DATA step PAYROLL for 1 minute
and 10 seconds:
data payroll;
call sleep(7000,.01);
...more SAS statements...
run;
Example 2: Suspending Execution Based on a Calculation of Sleep Time
The following
example tells SAS to suspend the execution of the DATA step BUDGET until March 1,
2004, at 3:00 AM. SAS calculates the length of the suspension based on the target date
and the date and time that the DATA step begins to execute.
data budget;
sleeptime=’01mar2004:03:00’dt-datetime();
call sleep(sleeptime,1);
...more SAS statements...;
run;
See Also
Functions:
“SLEEP Function” on page 1075
CALL SOFTMAX Routine
Returns the softmax value.
Category: Mathematical
Syntax
CALL SOFTMAX(argument<,argument,…>);
Arguments
argument
is numeric.
512
CALL SORTC Routine
4
Chapter 4
Restriction: The CALL SOFTMAX routine only accepts variables as valid
arguments. Do not use a constant or a SAS expression because the CALL routine
is unable to update these arguments.
Details
The CALL SOFTMAX routine replaces each argument with the softmax value of that
argument. For example xj is replaced by
exj
P= e
i n
=1
xi
i
If any argument contains a missing value, then CALL SOFTMAX returns missing
values for all the arguments. Upon a successful return, the sum of all the values is
equal to 1.
Examples
The following SAS statements produce these results:
SAS Statements
x=0.5;
y=-0.5;
z=1;
call softmax(x,y,z);
put x= y= z=;
Results
x=0.3314989604 y=0.1219516523 z=0.5465493873
CALL SORTC Routine
Sorts the values of character arguments.
Sort
Interaction: When invoked by the %SYSCALL macro statement, CALL SORTC removes
the quotation marks from its arguments. For more information, see “Using CALL
Routines and the %SYSCALL Macro Statement” on page 303.
Category:
Syntax
CALL SORTC(variable-1<, …, variable-n>)
Arguments
variable
Functions and CALL Routines
4
CALL SORTN Routine
513
specifies a character variable.
Details
The values of variable are sorted in ascending order by the CALL SORTC routine.
Comparisons
The CALL SORTC routine is used with character variables, and the CALL SORTN
routine is used with numeric variables.
Examples
The following example sorts the character variables in the array in ascending order.
data _null_;
array x(8) $10
(’tweedledum’ ’tweedledee’ ’baboon’ ’baby’
’humpty’ ’dumpty’ ’banana’ ’babylon’);
call sortc(of x(*));
put +3 x(*);
run;
SAS writes the following output to the log:
baboon baby babylon banana dumpty humpty tweedledee tweedledum
See Also
Functions and CALL routines:
“CALL SORTN Routine” on page 513
CALL SORTN Routine
Sorts the values of numeric arguments.
Category: Sort
Syntax
CALL SORTN(variable-1<, …, variable-n>)
Arguments
variable
specifies a numeric variable.
Details
The values of variable are sorted in ascending order by the CALL SORTN routine.
514
CALL STDIZE Routine
4
Chapter 4
Comparisons
The CALL SORTN routine is used with numeric variables, and the CALL SORTC
routine is used with character variables.
Examples
The following example sorts the numeric variables in the array in ascending order.
data _null_;
array x(10) (0, ., .a, 1e-12, -1e-8, .z, -37, 123456789, 1e20, 42);
call sortn(of x(*));
put +3 x(*);
run;
SAS writes the following output to the log:
. A Z -37 -1E-8 0 1E-12 42 123456789 1E20
See Also
Functions and CALL routines:
“CALL SORTC Routine” on page 512
CALL STDIZE Routine
Standardizes the values of one or more variables.
Mathematical
When invoked by the %SYSCALL macro statement, CALL STDIZE removes
the quotation marks from its arguments. For more information, see “Using CALL
Routines and the %SYSCALL Macro Statement” on page 303.
Category:
Interaction:
Syntax
CALL STDIZE(< option-1, option-2, …,>variable-1<,variable-2, …>);
Arguments
option
specifies a character expression whose values can be uppercase, lowercase, or mixed
case letters. Leading and trailing blanks are ignored.
Restriction: Use a separate argument for each option because you cannot specify
more than one option in a single argument.
Tip: Character expressions can end with an equal sign that is followed by another
argument that is a numeric constant, variable, or expression.
See Also: PROC STDIZE in SAS/STAT User’s Guide for information about
formulas and other details. The options that are used in CALL STDIZE are the
same as those used in PROC STDIZE.
Functions and CALL Routines
4
CALL STDIZE Routine
515
option includes the following three categories:
standardization-options
specify how to compute the location and scale measures that are used to
standardize the variables. The following standardization options are available:
ABW=
must be followed by an argument that is a numeric expression specifying the
tuning constant.
AGK=
must be followed by an argument that is a numeric expression that specifies the
proportion of pairs to be included in the estimation of the within-cluster
variances.
AHUBER=
must be followed by an argument that is a numeric expression specifying the
tuning constant.
AWAVE=
must be followed by an argument that is a numeric expression specifying the
tuning constant.
EUCLEN
specifies the Euclidean length.
IQR
specifies the interquartile range.
L=
must be followed by an argument that is a numeric expression with a value
greater than or equal to 1 specifying the power to which differences are to be
raised in computing an L(p) or Minkowski metric.
MAD
specifies the median absolute deviation from the median.
MAXABS
specifies the maximum absolute values.
MEAN
specifies the arithmetic mean (average).
MEDIAN
specifies the middle number in a set of data that is ordered according to rank.
MIDRANGE
specifies the midpoint of the range.
RANGE
specifies a range of values.
SPACING=
must be followed by an argument that is a numeric expression that specifies the
proportion of data to be contained in the spacing.
STD
specifies the standard deviation.
SUM
specifies the result that you obtain when you add numbers.
USTD
516
4
CALL STDIZE Routine
Chapter 4
specifies the standard deviation about the origin, based on the uncorrected sum
of squares.
VARDEF-options
specify the divisor to be used in the calculation of variances. VARDEF options can
have the following values:
DF
specifies degrees of freedom.
N
specifies the number of observations.
Default: DF
miscellaneous-options
Miscellaneous options can have the following values:
ADD=
is followed by a numeric argument that specifies a number to add to each value
after standardizing and multiplying by the value from the MULT= option. The
default value is 0.
FUZZ=
is followed by a numeric argument that specifies the relative fuzz factor.
MISSING=
is followed by a numeric argument that specifies a value to be assigned to
variables that have a missing value.
MULT=
is followed by a numeric argument that specifies a number by which to multiply
each value after standardizing. The default value is 1.
NORM
normalizes the scale estimator to be consistent for the standard deviation of a
normal distribution. This option affects only the methods AGK=, IQR, MAD,
and SPACING=.
PSTAT
writes the values of the location and scale measures in the log.
REPLACE
replaces missing values with the value 0 in the standardized data (this value
corresponds to the location measure before standardizing). To replace missing
values by other values, see the MISSING= option.
SNORM
normalizes the scale estimator to have an expectation of approximately 1 for a
standard normal distribution.
Tip: This option affects only the SPACING= method.
variable
is numeric. These values will be standardized according to the method that you use.
Details
The CALL STDIZE routine transforms one or more arguments that are numeric
variables by subtracting a location measure and dividing by a scale measure. You can
use a variety of location and scale measures. The default location option is MEAN, and
the default scale option is STD.
Functions and CALL Routines
4
CALL STDIZE Routine
517
In addition, you can multiply each standardized value by a constant and you can add
a constant. The final output value would be
result
= add + mult 3
(original 0 location) scale
where
result
specifies the final value that is returned for each variable.
add
specifies the constant to add (ADD= option).
mult
specifies the constant to multiply by (MULT= option).
original
specifies the original input value.
location
specifies the location measure.
scale
specifies the scale measure.
You can replace missing values by any constant. If you do not specify the MISSING=
or the REPLACE option, variables that have missing values are not altered. The initial
estimation method for the ABW=, AHUBER=, and AWAVE= methods is MAD.
Percentiles are computed using definition 5. For more information about percentile
calculations, see “SAS Elementary Statistics Procedures” in Base SAS Procedures Guide.
Comparisons
The CALL STDIZE routine is similar to the STDIZE procedure in the SAS/STAT
product. However, the CALL STDIZE routine is primarily useful for standardizing the
rows of a SAS data set, whereas the STDIZE procedure can standardize only the
columns of a SAS data set. For more information, see PROC STDIZE in SAS/STAT
User’s Guide.
Examples
The following SAS statements produce these results.
SAS Statements
Results
retain x 1 y 2 z 3;
call stdize(x,y,z);
put x= y= z=;
x=-1 y=0 z=1
retain w 10 x 11 y 12 z 13;
call stdize(’iqr’,w,x,y,z);
put w= x= y= z=;
w=-0.75 x=-0.25 y=0.25 z=0.75
retain w . x 1 y 2 z 3;
call stdize(’range’,w,x,y,z);
put w= x= y= z=;
w=. x=0 y=0.5 z=1
retain w . x 1 y 2 z 3;
call stdize(’mult=’,10,’missing=’,
-1,’range’,w,x,y,z);
put w= x= y= z=;
w=-1 x=0 y=5 z=10
518
CALL STREAMINIT Routine
4
Chapter 4
CALL STREAMINIT Routine
Specifies a seed value to use for subsequent random number generation by the RAND function.
Category:
Random Number
Syntax
CALL STREAMINIT(seed);
Arguments
seed
is an integer seed value.
<
0
1
seed 231
Tip: If you specify a nonpositive seed, then CALL STREAMINIT is ignored. Any
subsequent random number generation seeds itself from the system clock.
Range:
Details
If you want to create reproducible streams of random numbers, then specify CALL
STREAMINIT before any calls to the RAND random number function. If you call the
RAND function before you specify a seed with the CALL STREAMINIT routine (or if
you specify a nonpositive seed value in the CALL STREAMINIT routine), then the
RAND function uses a call to the system clock to seed itself. For more information
about seed values see “Seed Values” on page 305.
Examples
Example 1: Creating a Reproducible Stream of Random Numbers
The following
example shows how to specify a seed value with CALL STREAMINIT to create a
reproducible stream of random numbers with the RAND function.
options nodate ps=60 ls=80 pageno=1;
data random;
call streaminit(123);
do i=1 to 10;
x1=rand(’cauchy’);
output;
end;
proc print data=random;
id i;
run;
Functions and CALL Routines
Output 4.34
4
CALL SYMPUT Routine
519
Number String Seeded with CALL STREAMINIT
The SAS System
i
x1
1
2
3
4
5
6
7
8
9
10
-0.17593
3.76106
1.23427
0.49095
-0.05094
0.72496
-0.51646
7.61304
0.89784
1.69348
1
See Also
Functions:
“RAND Function” on page 1022
CALL SYMPUT Routine
Assigns DATA step information to a macro variable.
Category: Macro
Syntax
CALL SYMPUT(argument-1,argument-2);
Arguments
argument-1
specifies a character expression that identifies the macro variable that is assigned a
value. If the macro variable does not exist, the routine creates it.
argument-2
specifies a character constant, variable, or expression that contains the value that is
assigned.
Details
The CALL SYMPUT routine either creates a macro variable whose value is information
from the DATA step or assigns a DATA step value to an existing macro variable. CALL
SYMPUT is fully documented in “SYMPUT Routine” in SAS Macro Language:
Reference.
See Also
520
CALL SYMPUTX Routine
4
Chapter 4
Function:
“SYMGET Function” on page 1098
CALL SYMPUTX Routine
Assigns a value to a macro variable, and removes both leading and trailing blanks.
Category:
Macro
Syntax
CALL SYMPUTX(macro-variable, value <,symbol-table>);
Arguments
macro-variable
can be one of the following:
3 a character string that is a SAS name, enclosed in quotation marks.
3 the name of a character variable whose values are SAS names.
3 a character expression that produces a macro variable name. This form is
useful for creating a series of macro variables.
a character constant, variable, or expression. Leading and trailing blanks are
removed from the value of name, and the result is then used as the name of the
macro variable.
value
specifies a character or numeric constant, variable, or expression. If value is numeric,
SAS converts the value to a character string using the BEST. format and does not
issue a note to the SAS log. Leading and trailing blanks are removed, and the
resulting character string is assigned to the macro variable.
symbol-table
specifies a character constant, variable, or expression. The value of symbol-table is
not case sensitive. The first non-blank character in symbol-table specifies the symbol
table in which to store the macro variable. The following values are valid as the first
non-blank character in symbol-table:
G
specifies that the macro variable is stored in the global symbol
table, even if the local symbol table exists.
L
specifies that the macro variable is stored in the most local
symbol table that exists, which will be the global symbol table, if
used outside a macro.
F
specifies that if the macro variable exists in any symbol table,
CALL SYMPUTX uses the version in the most local symbol table
in which it exists. If the macro variable does not exist, CALL
SYMPUTX stores the variable in the most local symbol table.
Note: If you omit symbol-table, or if symbol-table is blank, CALL SYMPUTX stores
the macro variable in the same symbol table as does the CALL SYMPUT routine. 4
Functions and CALL Routines
4
CALL SYSTEM Routine
521
Comparisons
CALL SYMPUTX is similar to CALL SYMPUT except that
3 CALL SYMPUTX does not write a note to the SAS log when the second argument
is numeric. CALL SYMPUT, however, writes a note to the log stating that numeric
values were converted to character values.
3 CALL SYMPUTX uses a field width of up to 32 characters when it converts a
numeric second argument to a character value. CALL SYMPUT uses a field width
of up to 12 characters.
3 CALL SYMPUTX left-justifies both arguments and trims trailing blanks. CALL
SYMPUT does not left-justify the arguments, and trims trailing blanks from the
first argument only. Leading blanks in the value of name cause an error.
3 CALL SYMPUTX enables you to specify the symbol table in which to store the
macro variable, whereas CALL SYMPUT does not.
Examples
The following example shows the results of using CALL SYMPUTX.
data _null_;
call symputx(’ items ’, ’
leading and trailing blanks removed
’lplace’);
call symputx(’ x
’, 123.456);
run;
’,
%put items=!&items!;
%put x=!&x!;
The following lines are written to the SAS log:
----+----1----+----2----+----3----+----4----+----5
items=!leading and trailing blanks removed!
x=!123.456!
See Also
Functions and CALL Routines:
SYMGET Function“SYMGET Function” on page 1098
CALL SYMPUT“CALL SYMPUT Routine” on page 519
CALL SYSTEM Routine
Submits an operating environment command for execution.
Category: Special
When invoked by the %SYSCALL macro statement, CALL SYSTEM removes
quotation marks from its arguments. For more information, see “Using CALL Routines
and the %SYSCALL Macro Statement” on page 303.
See: CALL SYSTEM Routine in the documentation for your operating environment.
Interaction:
522
CALL TANH Routine
4
Chapter 4
Syntax
CALL SYSTEM(command);
Arguments
command
specifies any of the following: a system command that is enclosed in quotation marks
(character string), an expression whose value is a system command, or the name of a
character variable whose value is a system command that is executed.
Operating Environment Information: See the SAS documentation for your operating
environment for information about what you can specify. 4
Restriction: The length of the command cannot be greater than 1024 characters,
including trailing blanks.
Comparisons
The behavior of the CALL SYSTEM routine is similar to that of the X command, the X
statement, and the SYSTEM function. It is useful in certain situations because it can
be conditionally executed, it accepts an expression as an argument, and it is executed at
run time.
See Also
Function:
“SYSTEM Function” on page 1106
CALL TANH Routine
Returns the hyperbolic tangent.
Category:
Mathematical
Syntax
CALL TANH(argument<, argument,...>);
Arguments
argument
is numeric.
Restriction: The CALL TANH routine only accepts variables as valid arguments.
Do not use a constant or a SAS expression, because the CALL routine is unable to
update these arguments.
Functions and CALL Routines
4
CALL VNAME Routine
523
Details
The subroutine TANH replaces each argument by the tanh of that argument. For
example xj is replaced by
tanh (xj ) =
exj 0 e0xj
exj + e0xj
If any argument contains a missing value, then CALL TANH returns missing values
for all the arguments.
Examples
The following SAS statements produce these results:
SAS Statements
x=0.5;
y=-0.5;
call tanh(x,y);
put x= y=;
Results
x=0.4621171573 y=-0.462117157
See Also
Function:
“TANH Function” on page 1108
CALL VNAME Routine
Assigns a variable name as the value of a specified variable.
Category: Variable Control
Syntax
CALL VNAME(variable-1,variable-2);
Arguments
variable-1
specifies any SAS variable.
variable-2
specifies any SAS character variable. Because SAS variable names can contain up to
32 characters, the length of variable-2 should be at least 32.
524
CALL VNEXT Routine
4
Chapter 4
Details
The CALL VNAME routine assigns the name of the variable-1 variable as the value of
the variable-2 variable.
Examples
This example uses the CALL VNAME routine with array references to return the
names of all variables in the data set OLD:
data new(keep=name);
set old;
/* all character variables in old */
array abc{*} _character_;
/* all numeric variables in old */
array def{*} _numeric_;
/* name is not in either array */
length name $32;
do i=1 to dim(abc);
/* get name of character variable */
call vname(abc{i},name);
/* write name to an observation */
output;
end;
do j=1 to dim(def);
/* get name of numeric variable */
call vname(def{j},name);
/* write name to an observation */
output;
end;
stop;
run;
See Also
Functions:
“VNAME Function” on page 1163
“VNAMEX Function” on page 1164
CALL VNEXT Routine
Returns the name, type, and length of a variable that is used in a DATA step.
Category:
Variable Information
Syntax
CALL VNEXT(varname <,vartype < , varlength>>);
Functions and CALL Routines
4
CALL VNEXT Routine
525
Arguments
varname
is a character variable that is updated by the CALL VNEXT routine. The following
rules apply:
3 If the input value of varname is blank, the value that is returned in varname is
the name of the first variable in the DATA step’s list of variables.
3 If the CALL VNEXT routine is executed for the first time in the DATA step, the
value that is returned in varname is the name of the first variable in the DATA
step’s list of variables.
If neither of the above conditions exists, the input value of varname is ignored. Each
time the CALL VNEXT routine is executed, the value that is returned in varname is
the name of the next variable in the list.
After the names of all the variables in the DATA step are returned, the value that
is returned in varname is blank.
vartype
is a character variable whose input value is ignored. The value that is returned is
“N” or “C.” The following rules apply:
3 If the value that is returned in varname is the name of a numeric variable, the
value that is returned in vartype is “N.”
3 If the value that is returned in varname is the name of a character variable, the
value that is returned in vartype is “C.”
3 If the value that is returned in varname is blank, the value that is returned in
vartype is also blank.
varlength
is a numeric variable. The input value of varlength is ignored.
The value that is returned is the length of the variable whose name is returned in
varname. If the value that is returned in varname is blank, the value that is
returned in varlength is zero.
Details
The variable names that are returned by the CALL VNEXT routine include automatic
variables such as _N_ and _ERROR_. If the DATA step contains a BY statement, the
variable names that are returned by CALL VNEXT include the FIRST.variable and
LAST.variable names. CALL VNEXT also returns the names of the variables that are
used as arguments to CALL VNEXT.
Note: The order in which variable names are returned by CALL VNEXT can vary in
different releases of SAS and in different operating environments. 4
Examples
The following example shows the results from using the CALL VNEXT routine.
data test;
x=1;
y=’abc’;
z=.;
length z 5;
run;
526
CAT Function
4
Chapter 4
data attributes;
set test;
by x;
input a b $ c;
length name $32 type $3;
name=’ ’;
length=666;
do i=1 to 99 until(name=’ ’);
call vnext(name,type,length);
put i= name @40 type= length=;
end;
this_is_a_long_variable_name=0;
datalines;
1 q 3
;
Output 4.35
Partial SAS Log Output for the CALL VNEXT Routine
i=1 x
i=2 y
i=3 z
i=4 FIRST.x
i=5 LAST.x
i=6 a
i=7 b
i=8 c
i=9 name
i=10 type
i=11 length
i=12 i
i=13 this_is_a_long_variable_name
i=14 _ERROR_
i=15 _N_
i=16
type=N
type=C
type=N
type=N
type=N
type=N
type=C
type=N
type=C
type=C
type=N
type=N
type=N
type=N
type=N
type=
length=8
length=3
length=5
length=8
length=8
length=8
length=8
length=8
length=32
length=3
length=8
length=8
length=8
length=8
length=8
length=0
CAT Function
Does not remove leading or trailing blanks, and returns a concatenated character string.
Character
“I18N Level 2” on page 305
Tip: DBCS equivalent function is KSTRCAT in SAS National Language Support (NLS):
Reference Guide.
Category:
Restriction:
Syntax
CAT(item-1 <, …, item-n>)
Arguments
item
Functions and CALL Routines
4
CAT Function
527
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string by using the BESTw.
format. In this case, leading blanks are removed and SAS does not write a note to
the log.
Details
Length of Returned Variable
In a DATA step, if the CAT function returns a value to a variable that has not
previously been assigned a length, then that variable is given a length of 200 bytes. If
the concatenation operator (||) returns a value to a variable that has not previously
been assigned a length, then that variable is given a length that is the sum of the
lengths of the values which are being concatenated.
Length of Returned Variable: Special Cases
The CAT function returns a value to a
variable, or returns a value in a temporary buffer. The value that is returned from the
CAT function has the following length:
3 up to 200 characters in WHERE clauses and in PROC SQL
3 up to 32767 characters in the DATA step except in WHERE clauses
3 up to 65534 characters when CAT is called from the macro processor
If CAT returns a value in a temporary buffer, the length of the buffer depends on the
calling environment, and the value in the buffer can be truncated after CAT finishes
processing. In this case, SAS does not write a message about the truncation to the log.
If the length of the variable or the buffer is not large enough to contain the result of
the concatenation, SAS does the following:
3 changes the result to a blank value in the DATA step, and in PROC SQL
3 writes a warning message to the log stating that the result was either truncated or
set to a blank value, depending on the calling environment
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation
3 sets _ERROR_ to 1 in the DATA step
The CAT function removes leading and trailing blanks from numeric arguments after
it formats the numeric value with the BESTw. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
results that are produced by certain combinations of the concatenation operator (||)
and the TRIM and LEFT functions. However, the default length for the CAT, CATS,
CATT, and CATX functions is different from the length that is obtained when you use
the concatenation operator. For more information, see “Length of Returned Variable” on
page 527.
Using the CAT, CATS, CATT, and CATX functions is faster than using TRIM and
LEFT, and you can use them with the OF syntax for variable lists in calling
environments that support variable lists.
The following table shows equivalents of the CAT, CATS, CATT, and CATX functions.
The variables X1 through X4 specify character variables, and SP specifies a delimiter,
such as a blank or comma.
528
CATQ Function
4
Chapter 4
Function
Equivalent Code
CAT(OF X1-X4)
X1||X2||X3||X4
CATS(OF X1-X4)
TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4))
CATT(OF X1-X4)
TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4)
CATX(SP, OF X1-X4)
TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4))
Examples
The following example shows how the CAT function concatenates strings.
data _null_;
x=’ The 2002 Olym’;
y=’pic Arts Festi’;
z=’ val included works by D
a=’ale Chihuly.’;
result=cat(x,y,z,a);
put result $char.;
run;
’;
SAS writes the following line to the log:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
The 2002 Olympic Arts Festi val included works by D ale Chihuly.
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATT Routine” on page 430
“CALL CATX Routine” on page 432
“CATQ Function” on page 528
“CATS Function” on page 532
“CATT Function” on page 534
“CATX Function” on page 537
CATQ Function
Concatenates character or numeric values by using a delimiter to separate items and by adding
quotation marks to strings that contain the delimiter.
Category:
Character
Functions and CALL Routines
4
CATQ Function
529
Syntax
CATQ(modifiers< , delimiter>, item-1 <, …, item-n>)
Arguments
modifier
specifies a character constant, variable, or expression in which each non-blank
character modifies the action of the CATQ function. Blanks are ignored. You can use
the following characters as modifiers:
1 or ’
uses single quotation marks when CATQ adds quotation marks to
a string.
2 or ”
uses double quotation marks when CATQ adds quotation marks
to a string.
a or A
adds quotation marks to all of the item arguments.
b or B
adds quotation marks to item arguments that have leading or
trailing blanks that are not removed by the S or T modifiers.
c or C
uses a comma as a delimiter.
d or D
indicates that you have specified the delimiter argument.
h or H
uses a horizontal tab as the delimiter.
m or M
inserts a delimiter for every item argument after the first. If you
do not use the M modifier, then CATQ does not insert delimiters
for item arguments that have a length of zero after processing
that is specified by other modifiers. The M modifier can cause
delimiters to appear at the beginning or end of the result and can
cause multiple consecutive delimiters to appear in the result.
n or N
converts item arguments to name literals when the value does not
conform to the usual syntactic conventions for a SAS name. A
name literal is a string in quotation marks that is followed by the
letter “n” without any intervening blanks. To use name literals in
SAS statements, you must specify the SAS option,
VALIDVARNAME=ANY.
q or Q
adds quotation marks to item arguments that already contain
quotation marks.
s or S
strips leading and trailing blanks from subsequently processed
arguments:
3 To strip leading and trailing blanks from the delimiter
argument, specify the S modifier before the D modifier.
3 To strip leading and trailing blanks from the item arguments
but not from the delimiter argument, specify the S modifier
after the D modifier.
t or T
trims trailing blanks from subsequently processed arguments:
3 To trim trailing blanks from the delimiter argument, specify
the T modifier before the D modifier.
3 To trim trailing blanks from the item arguments but not
from the delimiter argument, specify the T modifier after the
D modifier.
530
CATQ Function
4
Chapter 4
x or X
converts item arguments to hexadecimal literals when the value
contains nonprintable characters.
If modifier is a constant, enclose it in quotation marks. You can also express
modifier as a variable name or an expression.
Tip:
The A, B, N, Q, S, T, and X modifiers operate internally to the CATQ function.
If an item argument is a variable, then the value of that variable is not changed
by CATQ unless the result is assigned to that variable.
Tip:
delimiter
specifies a character constant, variable, or expression that is used as a delimiter
between concatenated strings. If you specify this argument, then you must also
specify the D modifier.
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string by using the BESTw.
format. In this case, leading blanks are removed and SAS does not write a note to
the log.
Details
Length of Returned Variable
The CATQ function returns a value to a variable or if
CATQ is called inside an expression, CATQ returns a value to a temporary buffer. The
value that is returned has the following length:
3 up to 200 characters in WHERE clauses and in PROC SQL
3 up to 32767 characters in the DATA step except in WHERE clauses
3 up to 65534 characters when CATQ is called from the macro processor
If the length of the variable or the buffer is not large enough to contain the result of
the concatenation, then SAS does the following steps:
3 changes the result to a blank value in the DATA step and in PROC SQL
3 writes a warning message to the log stating that the result was either truncated or
set to a blank value, depending on the calling environment
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation
3 sets _ERROR_ to 1 in the DATA step
If CATQ returns a value in a temporary buffer, then the length of the buffer depends
on the calling environment, and the value in the buffer can be truncated after CATQ
finishes processing. In this case, SAS does not write a message about the truncation to
the log.
The Basics
If you do not use the C, D, or H modifiers, then CATQ uses a blank as a
delimiter.
If you specify neither a quotation mark in modifier nor the 1 or 2 modifiers, then
CATQ decides independently for each item argument which type of quotation mark to
use, if quotation marks are required. The following rules apply:
3 CATQ uses single quotation marks for strings that contain an ampersand (&) or
percent (%) sign, or that contain more double quotation marks than single
quotation marks.
3 CATQ uses double quotation marks for all other strings.
The CATQ function initializes the result to a length of zero and then performs the
following actions for each item argument:
Functions and CALL Routines
4
CATQ Function
531
1 If item is not a character string, then CATQ converts item to a character string by
using the BESTw. format and removes leading blanks.
2 If you used the S modifier, then CATQ removes leading blanks from the string.
3 If you used the S or T modifiers, then CATQ removes trailing blanks from the
string.
4 CATQ determines whether to add quotation marks based on the following
conditions:
3 If you use the X modifier and the string contains control characters, then the
string is converted to a hexadecimal literal.
3 If you use the N modifier, then the string is converted to a name literal if
either of the following conditions is true:
3 The first character in the string is not an underscore or an English letter.
3 The string contains any character that is not a digit, underscore, or
English letter.
3 If you did not use the X or the N modifiers, then CATQ adds quotation marks
to the string if any of the following conditions is true:
3 You used the A modifier.
3 You used the B modifier and the string contains leading or trailing
blanks that were not removed by the S or T modifiers.
3 You used the Q modifier and the string contains quotation marks.
3 The string contains a substring that equals the delimiter with leading
and trailing blanks omitted.
5 For the second and subsequent item arguments, CATQ appends the delimiter to
the result if either of the following conditions is true:
3 You used the M modifier.
3 The string has a length greater than zero after it has been processed by the
preceding steps.
6 CATQ appends the string to the result.
Comparisons
The CATX function is similar to the CATQ function except that CATX does not add
quotation marks.
Examples
The following example shows how the CATQ function concatenates strings.
options ls=110;
data _null_;
result1=CATQ(’ ’,
’noblanks’,
’one blank’,
12345,
’ lots of blanks
result2=CATQ(’CS’,
’Period (.)
’Ampersand (&)
’Comma (,)
’);
’,
’,
’,
532
CATS Function
4
Chapter 4
’Double quotation marks (") ’,
’
Leading Blanks’);
result3=CATQ(’BCQT’,
’Period (.)
’,
’Ampersand (&)
’,
’Comma (,)
’,
’Double quotation marks (") ’,
’
Leading Blanks’);
result4=CATQ(’ADT’,
’#=#’,
’Period (.)
’,
’Ampersand (&)
’,
’Comma (,)
’,
’Double quotation marks (") ’,
’
Leading Blanks’);
result5=CATQ(’N’,
’ABC_123
’,
’123
’,
’ABC 123’);
put (result1-result5) (=/);
run;
SAS writes the following output to the log.
result1=noblanks "one blank" 12345 "
lots of blanks
"
result2=Period (.),Ampersand (&),"Comma (,)",Double quotation marks ("),Leading Blanks
result3=Period (.),Ampersand (&),"Comma (,)",’Double quotation marks (")’,"
Leading Blanks"
result4="Period (.)"#=#’Ampersand (&)’#=#"Comma (,)"#=#’Double quotation marks (")’#=#"
Leading Blanks"
result5=ABC_123 "123"n "ABC 123"n
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATT Routine” on page 430
“CALL CATX Routine” on page 432
“CAT Function” on page 526
“CATS Function” on page 532
“CATT Function” on page 534
“CATX Function” on page 537
CATS Function
Removes leading and trailing blanks, and returns a concatenated character string.
Category:
Restriction:
Character
“I18N Level 0” on page 304
Functions and CALL Routines
4
CATS Function
533
Syntax
CATS(item-1 <, …, item-n>)
Arguments
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string by using the BESTw.
format. In this case, SAS does not write a note to the log.
Details
Length of Returned Variable
In a DATA step, if the CATS function returns a value to a variable that has not
previously been assigned a length, then that variable is given a length of 200 bytes. If
the concatenation operator (||) returns a value to a variable that has not previously
been assigned a length, then that variable is given a length that is the sum of the
lengths of the values which are being concatenated.
Length of Returned Variable: Special Cases
The CATS function returns a value to a
variable, or returns a value in a temporary buffer. The value that is returned from the
CATS function has the following length:
3 up to 200 characters in WHERE clauses and in PROC SQL
3 up to 32767 characters in the DATA step except in WHERE clauses
3 up to 65534 characters when CATS is called from the macro processor
If CATS returns a value in a temporary buffer, the length of the buffer depends on the
calling environment, and the value in the buffer can be truncated after CATS finishes
processing. In this case, SAS does not write a message about the truncation to the log.
If the length of the variable or the buffer is not large enough to contain the result of
the concatenation, SAS does the following:
3 changes the result to a blank value in the DATA step, and in PROC SQL
3 writes a warning message to the log stating that the result was either truncated or
set to a blank value, depending on the calling environment
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation
3 sets _ERROR_ to 1 in the DATA step
The CATS function removes leading and trailing blanks from numeric arguments
after it formats the numeric value with the BESTw. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
results that are produced by certain combinations of the concatenation operator (||)
and the TRIM and LEFT functions. However, the default length for the CAT, CATS,
CATT, and CATX functions is different from the length that is obtained when you use
the concatenation operator. For more information, see “Length of Returned Variable” on
page 533.
Using the CAT, CATS, CATT, and CATX functions is faster than using TRIM and
LEFT, and you can use them with the OF syntax for variable lists in calling
environments that support variable lists.
534
CATT Function
4
Chapter 4
The following table shows equivalents of the CAT, CATS, CATT, and CATX functions.
The variables X1 through X4 specify character variables, and SP specifies a delimiter,
such as a blank or comma.
Function
Equivalent Code
CAT(OF X1-X4)
X1||X2||X3||X4
CATS(OF X1-X4)
TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4))
CATT(OF X1-X4)
TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4)
CATX(SP, OF X1-X4)
TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4))
Examples
The following example shows how the CATS function concatenates strings.
data _null_;
x=’ The
Olym’;
y=’pic Arts Festi’;
z=’ val includes works by D
a=’ale Chihuly.’;
result=cats(x,y,z,a);
put result $char.;
run;
’;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4----+----5----+----6
The
Olympic Arts Festival includes works by Dale Chihuly.
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATT Routine” on page 430
“CALL CATX Routine” on page 432
“CAT Function” on page 526
“CATQ Function” on page 528
“CATT Function” on page 534
“CATX Function” on page 537
CATT Function
Removes trailing blanks, and returns a concatenated character string.
Functions and CALL Routines
4
CATT Function
535
Category: Character
Restriction:
“I18N Level 0” on page 304
Syntax
CATT(item-1 < , … item-n>)
Arguments
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string by using the BESTw.
format. In this case, leading blanks are removed and SAS does not write a note to
the log.
Details
Length of Returned Variable
In a DATA step, if the CATT function returns a value to a variable that has not
previously been assigned a length, then that variable is given a length of 200 bytes. If
the concatenation operator (||) returns a value to a variable that has not previously
been assigned a length, then that variable is given a length that is the sum of the
lengths of the values which are being concatenated.
Length of Returned Variable: Special Cases
The CATT function returns a value to a
variable, or returns a value in a temporary buffer. The value that is returned from the
CATT function has the following length:
3 up to 200 characters in WHERE clauses and in PROC SQL
3 up to 32767 characters in the DATA step except in WHERE clauses
3 up to 65534 characters when CATT is called from the macro processor
If CATT returns a value in a temporary buffer, the length of the buffer depends on the
calling environment, and the value in the buffer can be truncated after CATT finishes
processing. In this case, SAS does not write a message about the truncation to the log.
If the length of the variable or the buffer is not large enough to contain the result of
the concatenation, SAS does the following:
3 changes the result to a blank value in the DATA step, and in PROC SQL
3 writes a warning message to the log stating that the result was either truncated or
set to a blank value, depending on the calling environment
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation
3 sets _ERROR_ to 1 in the DATA step
The CATT function removes leading and trailing blanks from numeric arguments
after it formats the numeric value with the BESTw. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
results that are produced by certain combinations of the concatenation operator (||)
536
CATT Function
4
Chapter 4
and the TRIM and LEFT functions. However, the default length for the CAT, CATS,
CATT, and CATX functions is different from the length that is obtained when you use
the concatenation operator. For more information, see “Length of Returned Variable” on
page 535.
Using the CAT, CATS, CATT, and CATX functions is faster than using TRIM and
LEFT, and you can use them with the OF syntax for variable lists in calling
environments that support variable lists.
The following table shows equivalents of the CAT, CATS, CATT, and CATX functions.
The variables X1 through X4 specify character variables, and SP specifies a delimiter,
such as a blank or comma.
Function
Equivalent Code
CAT(OF X1-X4)
X1||X2||X3||X4
CATS(OF X1-X4)
TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4))
CATT(OF X1-X4)
TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4)
CATX(SP, OF X1-X4)
TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4))
Examples
The following example shows how the CATT function concatenates strings.
data _null_;
x=’ The
Olym’;
y=’pic Arts Festi’;
z=’ val includes works by D
a=’ale Chihuly.’;
result=catt(x,y,z,a);
put result $char.;
run;
’;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
The
Olympic Arts Festi val includes works by Dale Chihuly.
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATT Routine” on page 430
“CALL CATX Routine” on page 432
“CAT Function” on page 526
“CATQ Function” on page 528
“CATS Function” on page 532
“CATX Function” on page 537
Functions and CALL Routines
4
CATX Function
537
CATX Function
Removes leading and trailing blanks, inserts delimiters, and returns a concatenated character
string.
Category: Character
Restriction:
“I18N Level 0” on page 304
Syntax
CATX(delimiter, item-1 <, … item-n>)
Arguments
delimiter
specifies a character string that is used as a delimiter between concatenated items.
item
specifies a constant, variable, or expression, either character or numeric. If item is
numeric, then its value is converted to a character string by using the BESTw.
format. In this case, SAS does not write a note to the log. For more information, see
“The Basics” on page 537.
Details
The Basics
The CATX function first copies item-1 to the result, omitting leading and trailing
blanks. Then for each subsequent argument item-i, i=2, …, n, if item-i contains at least
one non-blank character, then CATX appends delimiter and item-i to the result, omitting
leading and trailing blanks from item-i. CATX does not insert the delimiter at the
beginning or end of the result. Blank items do not produce delimiters at the beginning
or end of the result, nor do blank items produce multiple consecutive delimiters.
Length of Returned Variable
In a DATA step, if the CATX function returns a value to a variable that has not
previously been assigned a length, then that variable is given a length of 200 bytes. If
the concatenation operator (||) returns a value to a variable that has not previously
been assigned a length, then that variable is given a length that is the sum of the
lengths of the values which are being concatenated.
Length of Returned Variable: Special Cases
The CATX function returns a value to a
variable, or returns a value in a temporary buffer. The value that is returned from the
CATX function has the following length:
3 up to 200 characters in WHERE clauses and in PROC SQL
3 up to 32767 characters in the DATA step except in WHERE clauses
3 up to 65534 characters when CATX is called from the macro processor
If CATX returns a value in a temporary buffer, the length of the buffer depends on the
calling environment, and the value in the buffer can be truncated after CATX finishes
processing. In this case, SAS does not write a message about the truncation to the log.
538
CATX Function
4
Chapter 4
If the length of the variable or the buffer is not large enough to contain the result of
the concatenation, SAS does the following:
3 changes the result to a blank value in the DATA step, and in PROC SQL
3 writes a warning message to the log stating that the result was either truncated or
set to a blank value, depending on the calling environment
3 writes a note to the log that shows the location of the function call and lists the
argument that caused the truncation
3 sets _ERROR_ to 1 in the DATA step
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
results that are produced by certain combinations of the concatenation operator (||)
and the TRIM and LEFT functions. However, the default length for the CAT, CATS,
CATT, and CATX functions is different from the length that is obtained when you use
the concatenation operator. For more information, see “Length of Returned Variable” on
page 537.
Using the CAT, CATS, CATT, and CATX functions is faster than using TRIM and
LEFT, and you can use them with the OF syntax for variable lists in calling
environments that support variable lists.
Note: In the case of variables that have missing values, the concatenation produces
different results. See Example 2 on page 539. 4
The following table shows equivalents of the CAT, CATS, CATT, and CATX functions.
The variables X1 through X4 specify character variables, and SP specifies a delimiter,
such as a blank or comma.
Function
Equivalent Code
CAT(OF X1-X4)
X1||X2||X3||X4
CATS(OF X1-X4)
TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||
TRIM(LEFT(X4))
CATT(OF X1-X4)
TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4)
CATX(SP, OF X1-X4)
TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4))
Examples
Example 1: Concatenating Strings That Have No Missing Values
The following example shows how the CATX function concatenates strings the have no
missing values.
data _null_;
separator=’%%$%%’;
x=’The Olympic ’;
y=’
Arts Festival ’;
z=’
includes works by ’;
a=’Dale Chihuly.’;
result=catx(separator,x,y,z,a);
put result $char.;
Functions and CALL Routines
4
CATX Function
539
run;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
The Olympic%%$%%Arts Festival%%$%%includes works by%%$%%Dale Chihuly.
Example 2: Concatenating Strings That Have Missing Values
The following example shows how the CATX function concatenates strings that contain
missing values.
options nodate nostimer ls=78 ps=60;
data one;
length x1--x4 $1;
input x1--x4;
datalines;
A B C D
E . F G
H . . J
;
run;
data two;
set one;
SP=’^’;
test1=catx(sp, of x1--x4);
test2=trim(left(x1)) || sp || trim(left(x2)) || sp || trim(left(x3)) || sp ||
trim(left(x4));
run;
proc print data=two;
run;
SAS creates the following output:
Output 4.36
Using CATX with Missing Values
The SAS System
Obs
1
2
3
x1
x2
A
E
H
x3
B
x4
C
SP
test1
D
F
See Also
Functions and CALL Routines:
“CALL CATS Routine” on page 428
“CALL CATT Routine” on page 430
“CALL CATX Routine” on page 432
“CAT Function” on page 526
“CATQ Function” on page 528
“CATS Function” on page 532
1
^
G
^
J
A^B^C^D
E^F^G
^
H^J
test2
A^B^C^D
E^ ^F^G
H^ ^ ^J
540
CDF Function
4
Chapter 4
“CATT Function” on page 534
CDF Function
Returns a value from a cumulative probability distribution.
Category:
Probability
Syntax
CDF (distribution,quantile<,parm-1, … ,parm-k>)
Arguments
distribution
is a character constant, variable, or expression that identifies the distribution. Valid
distributions are as follows:
Distribution
Argument
Bernoulli
BERNOULLI
Beta
BETA
Binomial
BINOMIAL
Cauchy
CAUCHY
Chi-Square
CHISQUARE
Exponential
EXPONENTIAL
F
F
Gamma
GAMMA
Geometric
GEOMETRIC
Hypergeometric
HYPERGEOMETRIC
Laplace
LAPLACE
Logistic
LOGISTIC
Lognormal
LOGNORMAL
Negative binomial
NEGBINOMIAL
Normal
NORMAL|GAUSS
Normal mixture
NORMALMIX
Pareto
PARETO
Poisson
POISSON
T
T
Uniform
UNIFORM
Functions and CALL Routines
Distribution
Argument
Wald (inverse Gaussian)
WALD|IGAUSS
Weibull
WEIBULL
4
CDF Function
541
Note: Except for T, F, and NORMALMIX, you can minimally identify any
distribution by its first four characters. 4
quantile
is a numeric constant, variable, or expression that specifies the value of the random
variable.
parm-1, … ,parm-k
are optional constants, variables, or expressions that specify shape, location, or scale
parameters appropriate for the specific distribution.
See: “Details” on page 541 for complete information about these parameters
Details
The CDF function computes the left cumulative distribution function from various
continuous and discrete probability distributions.
Note: The QUANTILE function returns the quantile from a distribution that you
specify. The QUANTILE function is the inverse of the CDF function. For more
information, see “QUANTILE Function” on page 1017 . 4
Bernoulli Distribution
CDF(’BERNOULLI’,x,p)
where
x
is a numeric random variable.
p
is a numeric probability of success.
Range: 0 ≤ p ≤ 1
The CDF function for the Bernoulli distribution returns the probability that an
observation from a Bernoulli distribution, with probability of success equal to p, is less
than or equal to x. The equation follows:
00
1
CDF BERN ; x; p =
Note:
0
(0
1
1
0p
x<0
0x<1
x1
There are no location or scale parameters for this distribution.
Beta Distribution
CDF(’BETA’,x,a,b< ,l,r>)
where
x
is a numeric random variable.
4
542
CDF Function
4
Chapter 4
a
is a numeric shape parameter.
Range: a > 0
b
is a numeric shape parameter.
Range: b > 0
l
is the numeric left location parameter.
Default: 0
r
is the right location parameter.
Default: 1
Range: r > l
The CDF function for the beta distribution returns the probability that an
observation from a beta distribution, with shape parameters a and b, is less than or
equal to v. The following equation describes the CDF function of the beta distribution:
00
1
CDF BET A ; x; a; b; l; r =
0
8
0
>
<
Rx (v0l)a01 (r0v)b01
1
dv
a+b01
(a;b)
(r 0l )
>
:
l
1
xl
l<xr
x>r
where
(a; b) = 00((aa) +0 (bb))
and
0 ( a) =
Z1
xa01 e0x dx
0
Binomial Distribution
CDF(’BINOMIAL’,m,p,n)
where
m
is an integer random variable that counts the number of successes.
Range: m = 0, 1, ...
p
is a numeric probability of success.
Range:
0≤p≤1
n
is an integer parameter that counts the number of independent Bernoulli trials.
Functions and CALL Routines
4
CDF Function
543
Range: n = 0, 1, ...
The CDF function for the binomial distribution returns the probability that an
observation from a binomial distribution, with parameters p and n, is less than or equal
to m. The equation follows:
00
8
0
>
< P
m N 1
CDF BINOM ; m; p; n = >
0
:
Note:
1
j=0 j
pj (1 0 p)n0j
m<0
0mn
m>n
There are no location or scale parameters for the binomial distribution.
4
Cauchy Distribution
CDF(’CAUCHY’,x<, , >)
where
x
is a numeric random variable.
is a numeric location parameter.
Default: 0
is a numeric scale parameter.
Default: 1
Range: > 0
The CDF function for the Cauchy distribution returns the probability that an
observation from a Cauchy distribution, with the location parameter and the scale
parameter , is less than or equal to x. The equation follows:
00
1
CDF CAUCH Y ; x; ; =
0
1
1
+ tan01
2 x0
Chi-Square Distribution
CDF(’CHISQUARE’,x,df <,nc>)
where
x
is a numeric random variable.
df
is a numeric degrees of freedom parameter.
Range: df > 0
nc
is an optional numeric non-centrality parameter.
Range: nc ≥ 0
The CDF function for the chi-square distribution returns the probability that an
observation from a chi-square distribution, with df degrees of freedom and
non-centrality parameter nc, is less than or equal to x. This function accepts
544
CDF Function
4
Chapter 4
non-integer degrees of freedom. If nc is omitted or equal to zero, the value returned is
from the central chi-square distribution. In the following equation, let $\nu$ = df and
let $\lambda$ = nc. The following equation describes the CDF function of the
chi-square distribution:
(0
P
x<0
j
1
()
0
CDF CHISQ ; x; ; =
e j! Pc (x; + 2j ) x 0
00
1
0
j
2
=0
2
where Pc(.,.) denotes the probability from the central chi-square distribution:
Pc (x; a) = Pg x2 ; a2
and where Pg(y,b) is the probability from the gamma distribution given by
Pg (y; b) = 1
0 ( b)
Zy
0
e0v vb01dv
Exponential Distribution
CDF(’EXPONENTIAL’,x < , >)
where
x
is a numeric random variable.
is a scale parameter.
Default: 1
Range:
>0
The CDF function for the exponential distribution returns the probability that an
observation from an exponential distribution, with the scale parameter , is less than or
equal to x. The equation follows:
00
1
CDF EXP O ; x; 0
=
n
0
1
0 e0 x
x<0
x0
F Distribution
CDF(’F’,x,ndf,ddf <,nc>)
where
x
is a numeric random variable.
ndf
is a numeric numerator degrees of freedom parameter.
Range: ndf > 0
Functions and CALL Routines
4
CDF Function
545
ddf
is a numeric denominator degrees of freedom parameter.
Range: ddf > 0
nc
is a numeric non-centrality parameter.
Range: nc ≥ 0
The CDF function for the F distribution returns the probability that an observation
from an F distribution, with ndf numerator degrees of freedom, ddf denominator
degrees of freedom, and non-centrality parameter nc, is less than or equal to x. This
function accepts non-integer degrees of freedom for ndf and ddf. If nc is omitted or
equal to zero, the value returned is from a central F distribution. In the following
equation, let $\nu_1$ = ndf, let $\nu_2$ = ddf, and let $\lambda$ = nc. The following
equation describes the CDF function of the F distribution:
x<0
j
1
()
0
CDF F ; x; v1; v2 ; =
e j! PF (x; v1 + 2j; v2) x 0
00
1
0
(0
P
2
2
j =0
where Pf(f,u1,u2) is the probability from the central F distribution with
ux u u
1
PF (x; u1 ; u2 ) = PB
; 1; 2
u x+u 2 2
1
2
and PB(x,a,b) is the probability from the standard beta distribution.
Note:
There are no location or scale parameters for the F distribution.
4
Gamma Distribution
CDF(’GAMMA’,x,a<, >)
where
x
is a numeric random variable.
a
is a numeric shape parameter.
Range: a > 0
is a numeric scale parameter.
Default: 1
Range: > 0
The CDF function for the gamma distribution returns the probability that an
observation from a gamma distribution, with shape parameter a and scale parameter ,
is less than or equal to x. The equation follows:
0
CDF GAMMA ; x; a; 0
0
1
(0
=
x<0
x
R
v
1
a01 0
a 0(a) v e dv x 0
0
546
CDF Function
4
Chapter 4
Geometric Distribution
CDF(’GEOMETRIC’,m,p)
where
m
is a numeric random variable that denotes the number of failures.
Range: m = 0, 1, ...
p
is a numeric probability of success.
Range: 0 ≤ p ≤ 1
The CDF function for the geometric distribution returns the probability that an
observation from a geometric distribution, with parameter p, is less than or equal to m.
The equation follows:
00
1
CDF GEOM ; m; p =
Note:
0
0
1
m<0
0 (1 0 p)fm+1g m 0
There are no location or scale parameters for this distribution.
4
Hypergeometric Distribution
CDF(’HYPER’,x,N,R,n< ,o>)
where
x
is an integer random variable.
N
is an integer population size parameter.
Range: N = 1, 2, ...
R
is an integer number of items in the category of interest.
Range: R = 0, 1, ..., N
n
is an integer sample size parameter.
Range: n = 1, 2, ..., N
o
is an optional numeric odds ratio parameter.
Range: o > 0
The CDF function for the hypergeometric distribution returns the probability that an
observation from an extended hypergeometric distribution, with population size N,
number of items R, sample size n, and odds ratio o, is less than or equal to x. If o is
omitted or equal to 1, the value returned is from the usual hypergeometric distribution.
The equation follows:
Functions and CALL Routines
00
0
:
547
x < max (0; R + n 0 N )
R N 0 R oi
i n0i
i =0
min
(R;n)
P
>
R
N
0
R
j
>
>
>
n0j o
>
> j=max(0;R+n0N ) j
x
P
CDF Function
1
CDF 8HY P ER ; x; N; R; n; o =
0
>
>
>
>
>
>
<
4
max (0; R + n 0 N ) x min (R; n)
x > min (R; n)
1
Laplace Distribution
CDF(’LAPLACE’,x<,, >)
where
x
is a numeric random variable.
is a numeric location parameter.
Default: 0
is a numeric scale parameter.
Default: 1
Range: > 0
The CDF function for the Laplace distribution returns the probability that an
observation from the Laplace distribution, with the location parameter and the scale
parameter , is less than or equal to x. The equation follows:
CDF
00
LAP LACE 0 ; x; ; 1
0
=
8
(x
)
>
>
< 1e 2
(x
)
>
0 >
:
1
1
e
2
0
0
x<
x
Logistic Distribution
CDF(’LOGISTIC’,x<,,>)
where
x
is a numeric random variable.
is a numeric location parameter
Default: 0
is a numeric scale parameter.
Default: 1
Range: > 0
The CDF function for the logistic distribution returns the probability that an
observation from a logistic distribution, with a location parameter and a scale
parameter , is less than or equal to x. The equation follows:
548
CDF Function
4
Chapter 4
00
1
1
CDF LOGIST IC ; x; ; =
0
1 + e0
x 0
Lognormal Distribution
CDF(’LOGNORMAL’,x<, , >)
where
x
is a numeric random variable.
specifies a numeric log scale parameter. (exp() is a scale parameter.)
Default: 0
specifies a numeric shape parameter.
Default: 1
Range:
>0
The CDF function for the lognormal distribution returns the probability that an
observation from a lognormal distribution, with the log scale parameter and the shape
parameter , is less than or equal to x. The equation follows:
00
1
CDF LOGN 0 ; x; ; =
8
<0
: p2
1
logR(x)
01
exp
0 v0
(
)
2 2
2
x0
dv
x>0
Negative Binomial Distribution
CDF(’NEGBINOMIAL’,m,p,n)
where
m
is a positive integer random variable that counts the number of failures.
Range: m = 0, 1, ...
p
is a numeric probability of success.
Range: 0 ≤ p ≤ 1
n
is a numeric value that counts the number of successes.
Range: n > 0
The CDF function for the negative binomial distribution returns the probability that
an observation from a negative binomial distribution, with probability of success p and
number of successes n, is less than or equal to m. The equation follows:
8
0
1 <0 P
m
n+j 1
CDF 0 N EGB 0 ; m; p; n = pn
(1
:
n 1
j =0
0
0
0 p)
j
m<0
m
0
Functions and CALL Routines
4
CDF Function
549
Note: There are no location or scale parameters for the negative binomial
distribution. 4
Normal Distribution
CDF(’NORMAL’,x<,, >)
where
x
is a numeric random variable.
is a numeric location parameter.
Default: 0
is a numeric scale parameter.
Default: 1
Range: > 0
The CDF function for the normal distribution returns the probability that an
observation from the normal distribution, with the location parameter and the scale
parameter , is less than or equal to x. The equation follows:
CDF
00
N ORM AL0 ; x; ; 1
= p1
2
Zx
01
0 (v 202)
exp
2
!
dv
Normal Mixture Distribution
CDF(’NORMALMIX’,x,n,p,m,s)
where
x
is a numeric random variable.
n
is the integer number of mixtures.
Range: n = 1, 2, ...
p
is the n proportions, p1 ; p2 ; . . . ; pn , where
=1
i
.
m1;m2; . . . ;m .
is the n standard deviations s1 ;s2 ; . . . ;s .
is the n means
s
n
i
Range: p = 0, 1, ...
m
P= p = 1
i
n
n
Range:
s>0
The CDF function for the normal mixture distribution returns the probability that an
observation from a mixture of normal distribution is less than or equal to x. The
equation follows:
550
CDF Function
4
Chapter 4
00
1
CDF NORMALMIX ; x; n; p; m; s =
0
i=n
X
00
p CDF NORMAL ; x; m ; s
i
=1
0
i
1
i
i
Note: There are no location or scale parameters for the normal mixture
distribution. 4
Pareto Distribution
CDF(’PARETO’,x,a< ,k>)
where
x
is a numeric random variable.
a
is a numeric shape parameter.
Range: a > 0
k
is a numeric scale parameter.
Default: 1
Range: k > 0
The CDF function for the Pareto distribution returns the probability that an
observation from a Pareto distribution, with the shape parameter a and the scale
parameter k, is less than or equal to x. The equation follows:
00
1
CDF P ARET O ; x; a; k =
0
0
1
0
x<k
xk
0 k 1a
x
Poisson Distribution
CDF(’POISSON’,n,m)
where
n
is an integer random variable.
Range: n = 0, 1, ...
m
is a numeric mean parameter.
Range: m > 0
The CDF function for the Poisson distribution returns the probability that an
observation from a Poisson distribution, with mean m, is less than or equal to n. The
equation follows:
00
1
CDF P OISSON ; n; m
0
(
=
0
n
P
=0
i
Note:
exp (0m) m
i
i!
n<0
n0
There are no location or scale parameters for the Poisson distribution.
4
Functions and CALL Routines
4
CDF Function
551
T Distribution
CDF(’T’,t,df<,nc>)
where
t
is a numeric random variable.
df
is a numeric degrees of freedom parameter.
Range: df > 0
nc
is an optional numeric non-centrality parameter.
The CDF function for the T distribution returns the probability that an observation
from a T distribution, with degrees of freedom df and non-centrality parameter nc, is
less than or equal to x. This function accepts non-integer degrees of freedom. If nc is
omitted or equal to zero, the value returned is from the central T distribution. In the
following equation, let $\nu$ = df and let $\delta$ = nc. The equation follows:
00
1
CDF T ; t; v; =
0
1
0 1
1
2( 2 v01) 0 1 v
2
Note:
Z1
x
v01
1 2
e0 2 x p1
ptxv
Z
2
0
01
e0 2 (u0) dudx
2
1
There are no location or scale parameters for the T distribution.
4
Uniform Distribution
CDF(’UNIFORM’,x<,l,r>)
where
x
is a numeric random variable.
l
is the numeric left location parameter.
Default: 0
r
is the numeric right location parameter.
Default: 1
Range: r > l
The CDF function for the uniform distribution returns the probability that an
observation from a uniform distribution, with the left location parameter l and the right
location parameter r, is less than or equal to x. The equation follows:
00
1
CDF UNIFORM ; x; l; r =
Note:
0
(
0
x0l
r0l
1
x<l
lx<r
xr
The default values for l and r are 0 and 1, respectively.
4
552
CDF Function
4
Chapter 4
Wald (Inverse Gaussian) Distribution
CDF(’WALD’,x,d)
CDF(’IGAUSS’,x,d)
where
x
is a numeric random variable.
d
is a numeric shape parameter.
Range: d > 0
The CDF function for the Wald distribution returns the probability that an
observation from a Wald distribution, with shape parameter d, is less than or equal to
x. The equation follows:
00
1
CDF W ALD ; x; d =
0
(
0 8 (x
0 1)
q d
x
+ e2d 8
0
q (x + 1) xd
x0
x>0
where 8(.) denotes the probability from the standard normal distribution.
Note:
There are no location or scale parameters for the Wald distribution.
4
Weibull Distribution
CDF(’WEIBULL’,x,a<, >)
where
x
is a numeric random variable.
a
is a numeric shape parameter.
Range: a > 0
is a numeric scale parameter.
Default: 1
Range: > 0
The CDF function for the Weibull distribution returns the probability that an
observation from a Weibull distribution, with the shape parameter a and the scale
parameter is less than or equal to x. The equation follows:
00
1
CDF W EIBU LL ; x; a; 0
=
n
0
1
x<0
x a
0
(
)
0e x0
Examples
SAS Statements
Results
y=cdf(’BERN’,0,.25);
0.75
y=cdf(’BETA’,0.2,3,4);
0.09888
y=cdf(’BINOM’,4,.5,10);
0.37695
Functions and CALL Routines
SAS Statements
Results
y=cdf(’CAUCHY’,2);
0.85242
y=cdf(’CHISQ’,11.264,11);
0.57858
y=cdf(’EXPO’,1);
0.63212
y=cdf(’F’,3.32,2,3);
0.82639
y=cdf(’GAMMA’,1,3);
0.080301
y=cdf(’HYPER’,2,200,50,10);
0.52367
y=cdf(’LAPLACE’,1);
0.81606
y=cdf(’LOGISTIC’,1);
0.73106
y=cdf(’LOGNORMAL’,1);
0.5
y=cdf(’NEGB’,1,.5,2);
0.5
y=cdf(’NORMAL’,1.96);
0.97500
y=cdf(’NORMALMIX’,2.3,3,.33,.33,.34,
.5,1.5,2.5,.79,1.6,4.3);
0.7181
y=cdf(’PARETO’,1,1);
0
y=cdf(’POISSON’,2,1);
0.91970
y=cdf(’T’,.9,5);
0.79531
y=cdf(’UNIFORM’,0.25);
0.25
y=cdf(’WALD’,1,2);
0.62770
y=cdf(’WEIBULL’,1,2);
0.63212
4
CEIL Function
See Also
Functions:
“LOGCDF Function” on page 870
“LOGPDF Function” on page 871
“LOGSDF Function” on page 873
“PDF Function” on page 945
“SDF Function” on page 1069
“QUANTILE Function” on page 1017
CEIL Function
Returns the smallest integer that is greater than or equal to the argument, fuzzed to avoid
unexpected floating-point results.
Category: Truncation
553
554
CEIL Function
4
Chapter 4
Syntax
CEIL (argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
If the argument is within 1E-12 of an integer, the function returns that integer.
Comparisons
Unlike the CEILZ function, the CEIL function fuzzes the result. If the argument is
within 1E-12 of an integer, the CEIL function fuzzes the result to be equal to that
integer. The CEILZ function does not fuzz the result. Therefore, with the CEILZ
function you might get unexpected results.
Examples
The following SAS statements produce these results.
SAS Statements
Results
var1=2.1;
a=ceil(var1);
put a;
3
b=ceil(-2.4);
put b;
-2
c=ceil(1+1.e-11);
put c;
2
d=ceil(-1+1.e-11);
put d;
0
e=ceil(1+1.e-13);
put e;
1
f=ceil(223.456);
put f;
224
g=ceil(763);
put g;
763
h=ceil(-223.456);
put h;
-223
See Also
Functions:
“CEILZ Function” on page 555
Functions and CALL Routines
4
CEILZ Function
CEILZ Function
Returns the smallest integer that is greater than or equal to the argument, using zero fuzzing.
Category: Truncation
Syntax
CEILZ (argument)
Arguments
argument
is a numeric constant, variable, or expression.
Comparisons
Unlike the CEIL function, the CEILZ function uses zero fuzzing. If the argument is
within 1E-12 of an integer, the CEIL function fuzzes the result to be equal to that
integer. The CEILZ function does not fuzz the result. Therefore, with the CEILZ
function you might get unexpected results.
Examples
The following SAS statements produce these results.
SAS Statements
Results
a=ceilz(2.1);
put a;
3
b=ceilz(-2.4);
put b;
−2
c=ceilz(1+1.e-11);
put c;
2
d=ceilz(-1+1.e-11);
put d;
0
e=ceilz(1+1.e-13);
put e;
2
f=ceilz(223.456);
put f;
224
g=ceilz(763);
put g;
763
h=ceilz(-223.456);
put h;
-223
See Also
555
556
CEXIST Function
4
Chapter 4
Functions:
“CEIL Function” on page 553
“FLOOR Function” on page 725
“FLOORZ Function” on page 726
“INT Function” on page 796
“INTZ Function” on page 827
“ROUND Function” on page 1049
“ROUNDE Function” on page 1056
“ROUNDZ Function” on page 1057
CEXIST Function
Verifies the existence of a SAS catalog or SAS catalog entry.
Category:
SAS File I/O
Syntax
CEXIST(entry< ,’U’>)
Arguments
entry
is a character constant, variable, or expression that specifies a SAS catalog, or the
name of an entry in a catalog. If the entry value is a one- or two-level name, then it
is assumed to be the name of a catalog. Use a three- or four-level name to test for the
existence of an entry within a catalog.
’U’
tests whether the catalog can be opened for updating.
Details
CEXIST returns 1 if the SAS catalog or catalog entry exists, or 0 if the SAS catalog or
catalog entry does not exist.
Examples
Example 1: Verifying the Existence of an Entry in a Catalog
This example verifies the
existence of the entry X.PROGRAM in LIB.CAT1:
data _null_;
if cexist("lib.cat1.x.program") then
put "Entry X.PROGRAM exists";
run;
Example 2: Determining if a Catalog Can Be Opened for Update
This example tests
whether the catalog LIB.CAT1 exists and can be opened for update. If the catalog does
Functions and CALL Routines
4
CHAR Function
557
not exist, a message is written to the SAS log. Note that in a macro statement you do
not enclose character strings in quotation marks.
%if %sysfunc(cexist(lib.cat1,u)) %then
%put The catalog LIB.CAT1 exists and can be opened for update.;
%else
%put %sysfunc(sysmsg());
See Also
Functions:
“EXIST Function” on page 648
CHAR Function
Returns a single character from a specified position in a character string.
Category: Character
Syntax
CHAR(string, position)
Arguments
string
specifies a character constant, variable, or expression.
position
is an integer that specifies the position of the character to be returned.
Details
In a DATA step, the default length of the target variable for the CHAR function is 1.
If position has a missing value, then CHAR returns a string with a length of 0.
Otherwise, CHAR returns a string with a length of 1.
If position is less than or equal to 0, or greater than the length of the string, then
CHAR returns a blank. Otherwise, CHAR returns the character at the specified
position in the string.
Comparisons
The CHAR function returns the same result as SUBPAD(string, position, 1). While the
results are the same, the default length of the target variable is different.
Examples
The following example shows the results of using the CHAR function.
558
CHOOSEC Function
4
Chapter 4
options pageno=1 ps=64 ls=80 nodate;
data test;
retain string "abc";
do position = -1 to 4;
result=char(string, position);
output;
end;
run;
proc print noobs data=test;
run;
Output 4.37
Output from the CHAR Function
The SAS System
string
position
abc
abc
abc
abc
abc
abc
-1
0
1
2
3
4
1
result
a
b
c
See Also
Functions:
“FIRST Function” on page 724
CHOOSEC Function
Returns a character value that represents the results of choosing from a list of arguments.
Character
Restriction: “I18N Level 2” on page 305
Category:
Syntax
CHOOSEC (index-expression, selection-1 <,…selection-n>)
Arguments
index-expression
specifies a numeric constant, variable, or expression.
selection
Functions and CALL Routines
4
CHOOSEN Function
559
specifies a character constant, variable, or expression. The value of this argument is
returned by the CHOOSEC function.
Details
Length of Returned Variable
In a DATA step, if the CHOOSEC function returns a
value to a variable that has not previously been assigned a length, then that variable is
given a length of 200 bytes.
The Basics
The CHOOSEC function uses the value of index-expression to select from
the arguments that follow. For example, if index-expression is three, CHOOSEC returns
the value of selection-3. If the first argument is negative, the function counts backwards
from the list of arguments, and returns that value.
Comparisons
The CHOOSEC function is similar to the CHOOSEN function except that CHOOSEC
returns a character value while CHOOSEN returns a numeric value.
Examples
The following example shows how CHOOSEC chooses from a series of values:
data _null_;
Fruit=choosec(1,’apple’,’orange’,’pear’,’fig’);
Color=choosec(3,’red’,’blue’,’green’,’yellow’);
Planet=choosec(2,’Mars’,’Mercury’,’Uranus’);
Sport=choosec(-3,’soccer’,’baseball’,’gymnastics’,’skiing’);
put Fruit= Color= Planet= Sport=;
run;
SAS writes the following line to the log:
Fruit=apple Color=green Planet=Mercury Sport=baseball
See Also
Functions:
“CHOOSEN Function” on page 559
CHOOSEN Function
Returns a numeric value that represents the results of choosing from a list of arguments.
Category: Character
Restriction:
“I18N Level 2” on page 305
Syntax
CHOOSEN (index-expression, selection-1 < ,…selection-n>)
560
CINV Function
4
Chapter 4
Arguments
index-expression
specifies a numeric constant, variable, or expression.
selection
specifies a numeric constant, variable, or expression. The value of this argument is
returned by the CHOOSEN function.
Details
The CHOOSEN function uses the value of index-expression to select from the
arguments that follow. For example, if index-expression is 3, CHOOSEN returns the
value of selection-3. If the first argument is negative, the function counts backwards
from the list of arguments, and returns that value.
Comparisons
The CHOOSEN function is similar to the CHOOSEC function except that CHOOSEN
returns a numeric value while CHOOSEC returns a character value.
Examples
The following example shows how CHOOSEN chooses from a series of values:
data _null_;
ItemNumber=choosen(5,100,50,3784,498,679);
Rank=choosen(-2,1,2,3,4,5);
Score=choosen(3,193,627,33,290,5);
Value=choosen(-5,-37,82985,-991,3,1014,-325,3,54,-618);
put ItemNumber= Rank= Score= Value=;
run;
SAS writes the following line to the log:
ItemNumber=679 Rank=4 Score=33 Value=1014
See Also
Functions:
“CHOOSEC Function” on page 558
CINV Function
Returns a quantile from the chi-square distribution.
Category:
Quantile
Syntax
CINV (p,df< ,nc>)
Functions and CALL Routines
4
CINV Function
561
Arguments
p
is a numeric probability.
Range: 0 ≤ p < 1
df
is a numeric degrees of freedom parameter.
Range: df > 0
nc
is a numeric noncentrality parameter.
Range: nc ≥ 0
Details
th
The CINV function returns the p quantile from the chi-square distribution with
degrees of freedom df and a noncentrality parameter nc. The probability that an
observation from a chi-square distribution is less than or equal to the returned quantile
is p. This function accepts a noninteger degrees of freedom parameter df.
If the optional parameter nc is not specified or has the value 0, the quantile from the
central chi-square distribution is returned. The noncentrality parameter nc is defined
2
such that if X is a normal random variable with mean and variance 1, X has a
2
noncentral chi-square distribution with df=1 and nc = .
CAUTION:
For large values of nc, the algorithm could fail. In that case, a missing value is returned.
4
Note:
CINV is the inverse of the PROBCHI function.
4
Examples
th
The first statement following shows how to find the 95 percentile from a central
chi-square distribution with 3 degrees of freedom. The second statement shows how to
th
find the 95 percentile from a noncentral chi-square distribution with 3.5 degrees of
freedom and a noncentrality parameter equal to 4.5.
SAS Statements
Results
q1=cinv(.95,3);
7.8147279033
a2=cinv(.95,3.5,4.5);
7.504582117
See Also
Functions:
“QUANTILE Function” on page 1017
562
CLOSE Function
4
Chapter 4
CLOSE Function
Closes a SAS data set.
Category:
SAS File I/O
Syntax
CLOSE(data-set-id)
Arguments
data-set-id
is a numeric variable that specifies the data set identifier that the OPEN function
returns.
Details
CLOSE returns zero if the operation was successful, or returns a non-zero value if it
was not successful. Close all SAS data sets as soon as they are no longer needed by the
application.
Note: All data sets opened within a DATA step are closed automatically at the end
of the DATA step. 4
Examples
This example uses OPEN to open the SAS data set PAYROLL. If the data set opens
successfully, indicated by a positive value for the variable PAYID, the example uses
CLOSE to close the data set.
%let payid=%sysfunc(open(payroll,is));
macro statements
%if &payid > 0 %then
%let rc=%sysfunc(close(&payid));
See Also
Function:
“OPEN Function” on page 939
CMISS Function
Counts the number of missing arguments.
Category:
Descriptive Statistics
Functions and CALL Routines
4
CNONCT Function
563
Syntax
CMISS(argument-1 <, argument-2,…>)
Arguments
argument
specifies a constant, variable, or expression. Argument can be either a character
value or a numeric value.
Details
A character expression is counted as missing if it evaluates to a string that contains all
blanks or has a length of zero.
A numeric expression is counted as missing if it evaluates to a numeric missing
value: ., ._, .A, … , .Z.
Comparisons
The CMISS function does not convert any argument. The NMISS function converts all
arguments to numeric values.
See Also
Functions:
“NMISS Function” on page 908
“MISSING Function” on page 890
CNONCT Function
Returns the noncentrality parameter from a chi-square distribution.
Category: Mathematical
Syntax
CNONCT(x,df,prob)
Arguments
x
is a numeric random variable.
Range: x ≥ 0
df
is a numeric degrees of freedom parameter.
564
CNONCT Function
4
Chapter 4
Range:
df > 0
prob
is a probability.
Range: 0 < prob < 1
Details
The CNONCT function returns the nonnegative noncentrality parameter from a
noncentral chi-square distribution whose parameters are x, df, and nc. If prob is greater
than the probability from the central chi-square distribution with the parameters x and
df, a root to this problem does not exist. In this case a missing value is returned. A
Newton-type algorithm is used to find a nonnegative root nc of the equation
Pc (xjdf; nc) 0 prob = 0
where
Pc (xjdf; nc) = e
0nc
2
X1
j
0 nc 1j
=0
2
Pg
j!
x df
2
j
2
+
j
where Pg (xja) is the probability from the gamma distribution given by
Pg (xja)
=
1
0 ( a)
Zx
01 e0t dt
a
t
0
If the algorithm fails to converge to a fixed point, a missing value is returned.
Examples
data work;
x=2;
df=4;
do nc=1 to 3 by .5;
prob=probchi(x,df,nc);
ncc=cnonct(x,df,prob);
output;
end;
run;
proc print;
run;
Functions and CALL Routines
Output 4.38
Distribution
4
COALESCE Function
Computations of the Noncentrality Parameters from the Chi-squared
OBS
x
df
nc
1
2
3
4
5
2
2
2
2
2
4
4
4
4
4
1.0
1.5
2.0
2.5
3.0
prob
0.18611
0.15592
0.13048
0.10907
0.09109
ncc
1.0
1.5
2.0
2.5
3.0
COALESCE Function
Returns the first non-missing value from a list of numeric arguments.
Category:
Mathematical
Syntax
COALESCE(argument-1<..., argument-n>)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The Basics
COALESCE accepts one or more numeric arguments. The COALESCE
function checks the value of each argument in the order in which they are listed and
returns the first non-missing value. If only one value is listed, then the COALESCE
function returns the value of that argument. If all the values of all arguments are
missing, then the COALESCE function returns a missing value.
Comparisons
The COALESCE function searches numeric arguments, whereas the COALESCEC
function searches character arguments.
Examples
SAS Statements
Results
x = COALESCE(42, .);
42
y = COALESCE(.A, .B, .C);
.
z = COALESCE(., 7, ., ., 42);
7
565
566
COALESCEC Function
4
Chapter 4
See Also
Function:
“COALESCEC Function” on page 566
COALESCEC Function
Returns the first non-missing value from a list of character arguments.
Category:
Restriction:
Character
“I18N Level 2” on page 305
Syntax
COALESCEC(argument-1< ..., argument-n>)
Arguments
argument
specifies a character constant, variable, or expression.
Details
Length of Returned Variable
In a DATA step, if the COALESCEC function returns a
value to a variable that has not previously been assigned a length, then that variable is
given a length of 200 bytes.
The Basics
COALESCEC accepts one or more character arguments. The
COALESCEC function checks the value of each argument in the order in which they
are listed and returns the first non-missing value. If only one value is listed, then the
COALESCEC function returns the value of that argument. A character value is
considered missing if it has a length of zero or if all the characters are blank. If all the
values of all arguments are missing, then the COALESCEC function returns a string
with a length of zero.
Comparisons
The COALESCEC function searches character arguments, whereas the COALESCE
function searches numeric arguments.
Examples
SAS Statements
Results
COALESCEC(’’, ’Hello’)
Hello
COALESCEC (’’, ’Goodbye’, ’Hello’)
Goodbye
Functions and CALL Routines
4
COLLATE Function
567
See Also
Function:
“COALESCE Function” on page 565
COLLATE Function
Returns a character string in ASCII or EBCDIC collating sequence.
Category: Character
Restriction:
See:
“I18N Level 0” on page 304
COLLATE Function in the documentation for your operating environment.
Syntax
COLLATE (start-position<,end-position>) | (start-position<,,length>)
Arguments
start-position
specifies the numeric position in the collating sequence of the first character to be
returned.
Interaction: If you specify only start-position, COLLATE returns consecutive
characters from that position to the end of the collating sequence or up to 255
characters, whichever comes first.
end-position
specifies the numeric position in the collating sequence of the last character to be
returned.
The maximum end-position for the EBCDIC collating sequence is 255. For ASCII
collating sequences, the characters that correspond to end-position values between 0
and 127 represent the standard character set. Other ASCII characters that
correspond to end-position values between 128 and 255 are available on certain
ASCII operating environments, but the information that those characters represent
varies with the operating environment.
Tip:
end-position must be larger than start-position
If you specify end-position, COLLATE returns all character values in the
collating sequence between start-position and end-position, inclusive.
Tip:
If you omit end-position and use length, mark the end-position place with a
comma.
Tip:
length
specifies the number of characters in the collating sequence.
Default: 200
Tip:
If you omit end-position, use length to specify the length of the result explicitly.
568
COMB Function
4
Chapter 4
Details
Length of Returned Variable
In a DATA step, if the COLLATE function returns a
value to a variable that has not previously been assigned a length, then that variable is
given a length of 200 bytes.
The Basics
If you specify both end-position and length, COLLATE ignores length. If
you request a string longer than the remainder of the sequence, COLLATE returns a
string through the end of the sequence.
Examples
The following SAS statements produce these results.
SAS Statements
Results
ASCII
----+----1----+-----2--
x=collate(48,,10);
y=collate(48,57);
put @1 x @14 y;
0123456789
0123456789
0123456789
0123456789
EBCDIC
x=collate(240,,10);
y=collate(240,249);
put @1 x @14 y;
See Also
Functions:
“BYTE Function” on page 418
“RANK Function” on page 1036
COMB Function
Computes the number of combinations of n elements taken r at a time.
Category:
Combinatorial
Syntax
COMB(n, r)
Arguments
n
Functions and CALL Routines
4
COMPARE Function
569
is a nonnegative integer that represents the total number of elements from which the
sample is chosen.
r
is a nonnegative integer that represents the number of chosen elements.
Restriction: r ≤ n
Details
The mathematical representation of the COMB function is given by the following
equation:
COMB (n; r) =
n r
=
n!
r ! (n 0 r )!
with n ≥ 0, r ≥ 0, and n≥ r.
If the expression cannot be computed, a missing value is returned. For moderately
large values, it is sometimes not possible to compute the COMB function.
Examples
SAS Statements
Results
x=comb(5,1);
5
See Also
Functions:
“FACT Function” on page 651
“PERM Function” on page 964
“LCOMB Function” on page 845
COMPARE Function
Returns the position of the leftmost character by which two strings differ, or returns 0 if there is no
difference.
Category: Character
“I18N Level 0” on page 304
Tip: DBCS equivalent function is KCOMPARE in SAS National Language Support
(NLS): Reference Guide. See also “DBCS Compatibility” on page 570.
Restriction:
Syntax
COMPARE(string–1, string–2<,modifiers>)
570
COMPARE Function
4
Chapter 4
Arguments
string–1
specifies a character constant, variable, or expression.
string–2
specifies a character constant, variable, or expression.
modifier
specifies a character string that can modify the action of the COMPARE function.
You can use one or more of the following characters as a valid modifier:
i or I
ignores the case in string–1 and string–2.
l or L
removes leading blanks in string–1 and string–2 before comparing
the values.
n or N
removes quotation marks from any argument that is a name
literal and ignores the case of string–1 and string–2.
Tip: A name literal is a name token that is expressed as a string
within quotation marks, followed by the uppercase or lowercase
letter n. Name literals enable you to use special characters
(including blanks) that are not otherwise allowed in SAS data
set or variable names. For COMPARE to recognize a string as
a name literal, the first character must be a quotation mark.
: (colon)
truncates the longer of string–1 or string–2 to the length of the
shorter string, or to one, whichever is greater. If you do not
specify this modifier, the shorter string is padded with blanks to
the same length as the longer string.
Tip: COMPARE ignores blanks that are used as modifiers.
Details
The Basics
The order in which the modifiers appear in the COMPARE function is
relevant.
3 “LN” first removes leading blanks from each string, and then removes quotation
marks from name literals.
3 “NL” first removes quotation marks from name literals, and then removes leading
blanks from each string.
In the COMPARE function, if string–1 and string–2 do not differ, COMPARE returns
a value of zero. If the arguments differ, then the following apply:
3 The sign of the result is negative if string–1 precedes string–2 in a sort sequence,
and positive if string–1 follows string–2 in a sort sequence.
3 The magnitude of the result is equal to the position of the leftmost character at
which the strings differ.
DBCS Compatibility
The DBCS equivalent function is KCOMPARE, which is documented in SAS National
Language Support (NLS): Reference Guide. There are minor differences between the
COMPARE and KCOMPARE functions. While both functions accept varying numbers of
arguments, usage of the third argument is not compatible. The following example
shows the differences in the syntax:
COMPARE(string-1, string-2 <, modifiers>)
Functions and CALL Routines
4
COMPARE Function
571
KCOMPARE(string-1 <, position <, count>>, string-2)
Examples
Example 1: Understanding the Order of Comparisons When Comparing Two Strings
The
following example compares two strings by using the COMPARE function.
options pageno=1 nodate ls=80 ps=60;
data test;
infile datalines missover;
input string1 $char8. string2 $char8. modifiers $char8.;
result=compare(string1, string2, modifiers);
datalines;
1234567812345678
123
abc
abc
abx
xyz
abcdef
aBc
abc
aBc
AbC
i
abc abc
abc abc
l
abc
abx
abc
abx l
ABC
’abc’n
ABC
’abc’n n
’$12’n $12
n
’$12’n $12
nl
’$12’n $12
ln
;
proc print data=test;
run;
The following output shows the results.
Output 4.39
Results of Comparing Two Strings by Using the COMPARE Function
The SAS System
Obs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
string1
string2
12345678
123
abc
xyz
aBc
aBc
abc
abc
abc
abc
ABC
ABC
’$12’n
’$12’n
’$12’n
12345678
abc
abx
abcdef
abc
AbC
abc
abc
abx
abx
’abc’n
’abc’n
$12
$12
$12
1
modifiers
i
l
l
n
n
nl
ln
result
0
-1
-3
1
-2
0
-1
0
2
-3
1
0
-1
1
0
572
COMPBL Function
4
Chapter 4
Example 2: Truncating Strings Using the COMPARE Function
The following example
uses the : (colon) modifier to truncate strings.
options pageno=1 nodate ls=80 pagesize=60;
data test2;
pad1=compare(’abc’,’abc
’);
pad2=compare(’abc’,’abcdef
’);
truncate1=compare(’abc’,’abcdef’,’:’);
truncate2=compare(’abcdef’,’abc’,’:’);
blank=compare(’’,’abc’,
’:’);
run;
proc print data=test2 noobs;
run;
The following output shows the results.
Output 4.40
Results of Using the Truncation Modifier
The SAS System
pad1
0
pad2
truncate1
truncate2
-4
0
0
See Also
Functions and CALL Routines:
“COMPGED Function” on page 573
“COMPLEV Function” on page 578
“CALL COMPCOST Routine” on page 434
COMPBL Function
Removes multiple blanks from a character string.
Category:
Restriction:
Character
“I18N Level 0” on page 304
Syntax
COMPBL(source)
Arguments
source
1
blank
-1
Functions and CALL Routines
4
COMPGED Function
573
specifies a character constant, variable, or expression to compress.
Details
Length of Returned Variable
In a DATA step, if the COMPBL function returns a
value to a variable that has not previously been assigned a length, then the length of
that variable defaults to the length of the first argument.
The Basics
The COMPBL function removes multiple blanks in a character string by
translating each occurrence of two or more consecutive blanks into a single blank.
Comparisons
The COMPRESS function removes every occurrence of the specific character from a
string. If you specify a blank as the character to remove from the source string, the
COMPRESS function removes all blanks from the source string, while the COMPBL
function compresses multiple blanks to a single blank and has no effect on a single
blank.
Examples
The following SAS statements produce these results.
SAS Statements
Results
----+----1----+-----2--
string=’Hey
Diddle Diddle’;
string=compbl(string);
put string;
Hey Diddle Diddle
string=’125
E Main St’;
length address $10;
address=compbl(string);
put address;
125 E Main
See Also
Function:
“COMPRESS Function” on page 582
COMPGED Function
Returns the generalized edit distance between two strings.
Category: Character
Restriction:
“I18N Level 0” on page 304
574
COMPGED Function
4
Chapter 4
Syntax
COMPGED(string-1, string-2 <,cutoff> <,modifiers>)
Arguments
string–1
specifies a character constant, variable, or expression.
string-2
specifies a character constant, variable, or expression.
cutoff
is a numeric constant, variable, or expression. If the actual generalized edit distance
is greater than the value of cutoff, the value that is returned is equal to the value of
cutoff.
Tip: Using a small value of cutoff improves the efficiency of COMPGED if the
values of string–1 and string–2 are long.
modifiers
specifies a character string that can modify the action of the COMPGED function.
You can use one or more of the following characters as a valid modifier:
i or I
ignores the case in string–1 and string–2.
l or L
removes leading blanks in string–1 and string–2 before comparing
the values.
n or N
removes quotation marks from any argument that is an n-literal
and ignores the case of string–1 and string–2.
: (colon)
truncates the longer of string–1 or string–2 to the length of the
shorter string, or to one, whichever is greater.
Tip: COMPGED ignores blanks that are used as modifiers.
Details
The Order in Which Modifiers Appear
The order in which the modifiers appear in the
COMPGED function is relevant.
3 “LN” first removes leading blanks from each string and then removes quotation
marks from n-literals.
3 “NL” first removes quotation marks from n-literals and then removes leading
blanks from each string.
Definition of Generalized Edit Distance
Generalized edit distance is a generalization
of Levenshtein edit distance, which is a measure of dissimilarity between two strings.
The Levenshtein edit distance is the number of deletions, insertions, or replacements of
single characters that are required to transform string-1 into string-2.
Computing the Generalized Edit Distance
The COMPGED function returns the
generalized edit distance between string-1 and string-2. The generalized edit distance is
the minimum-cost sequence of operations for constructing string-1 from string-2.
The algorithm for computing the sum of the costs involves a pointer that points to a
character in string-2 (the input string). An output string is constructed by a sequence of
operations that might advance the pointer, add one or more characters to the output
string, or both. Initially, the pointer points to the first character in the input string, and
the output string is empty.
Functions and CALL Routines
4
COMPGED Function
The operations and their costs are described in the following table.
Operation
Default Cost in
Units
APPEND
50
When the output string is longer than the
input string, add any one character to the
end of the output string without moving
the pointer.
BLANK
10
Do any of the following:
Description of Operation
3
3
3
Add one space character to the end
of the output string without moving
the pointer.
When the character at the pointer
is a space character, advance the
pointer by one position without
changing the output string.
When the character at the pointer
is a space character, add one space
character to the end of the output
string, and advance the pointer by
one position.
If the cost for BLANK is set to zero by the
COMPCOST function, the COMPGED
function removes all space characters from
both strings before doing the comparison.
DELETE
100
Advance the pointer by one position
without changing the output string.
DOUBLE
20
Add the character at the pointer to the
end of the output string without moving
the pointer.
FDELETE
200
When the output string is empty, advance
the pointer by one position without
changing the output string.
FINSERT
200
When the pointer is in position one, add
any one character to the end of the output
string without moving the pointer.
FREPLACE
200
When the pointer is in position one and
the output string is empty, add any one
character to the end of the output string,
and advance the pointer by one position.
INSERT
100
Add any one character to the end of the
output string without moving the pointer.
MATCH
0
Copy the character at the pointer from
the input string to the end of the output
string, and advance the pointer by one
position.
575
576
COMPGED Function
4
Chapter 4
Operation
Default Cost in
Units
Description of Operation
PUNCTUATION
30
Do any of the following:
3
3
3
Add one punctuation character to
the end of the output string without
moving the pointer.
When the character at the pointer
is a punctuation character, advance
the pointer by one position without
changing the output string.
When the character at the pointer
is a punctuation character, add one
punctuation character to the end of
the output string, and advance the
pointer by one position.
If the cost for PUNCTUATION is set to
zero by the COMPCOST function, the
COMPGED function removes all
punctuation characters from both strings
before doing the comparison.
REPLACE
100
Add any one character to the end of the
output string, and advance the pointer by
one position.
SINGLE
20
When the character at the pointer is the
same as the character that follows in the
input string, advance the pointer by one
position without changing the output
string.
SWAP
20
Copy the character that follows the
pointer from the input string to the output
string. Then copy the character at the
pointer from the input string to the output
string. Advance the pointer two positions.
TRUNCATE
10
When the output string is shorter than
the input string, advance the pointer by
one position without changing the output
string.
To set the cost of the string operations, you can use the CALL COMPCOST routine or
use default costs. If you use the default costs, the values that are returned by
COMPGED are approximately 100 times greater than the values that are returned by
COMPLEV.
Examples of Errors
The rationale for determining the generalized edit distance is
based on the number and types of typographical errors that can occur. COMPGED
assigns a cost to each error and determines the minimum sum of these costs that could
be incurred. Some types of errors can be more serious than others. For example,
inserting an extra letter at the beginning of a string might be more serious than
omitting a letter from the end of a string. For another example, if you type a word or
Functions and CALL Routines
4
COMPGED Function
577
phrase that exists in string-2 and introduce a typographical error, you might produce
string-1 instead of string-2.
Making the Generalized Edit Distance Symmetric
Generalized edit distance is not
necessarily symmetric. That is, the value that is returned by COMPGED(string1,
string2) is not always equal to the value that is returned by COMPGED(string2,
string1). To make the generalized edit distance symmetric, use the CALL COMPCOST
routine to assign equal costs to the operations within each of the following pairs:
3 INSERT, DELETE
3 FINSERT, FDELETE
3 APPEND, TRUNCATE
3 DOUBLE, SINGLE
Comparisons
You can compute the Levenshtein edit distance by using the COMPLEV function. You
can compute the generalized edit distance by using the CALL COMPCOST routine and
the COMPGED function. Computing generalized edit distance requires considerably
more computer time than does computing Levenshtein edit distance. But generalized
edit distance usually provides a more useful measure than Levenshtein edit distance for
applications such as fuzzy file merging and text mining.
Examples
The following example uses the default costs to calculate the generalized edit
distance.
options nodate pageno=1 linesize=70 pagesize=60;
data test;
infile datalines missover;
input String1 $char8. +1 String2 $char8. +1 Operation $40.;
GED=compged(string1, string2);
datalines;
baboon
baboon
match
baXboon baboon
insert
baoon
baboon
delete
baXoon
baboon
replace
baboonX baboon
append
baboo
baboon
truncate
babboon baboon
double
babon
baboon
single
baobon
baboon
swap
bab oon baboon
blank
bab,oon baboon
punctuation
bXaoon
baboon
insert+delete
bXaYoon baboon
insert+replace
bXoon
baboon
delete+replace
Xbaboon baboon
finsert
aboon
baboon
trick question: swap+delete
Xaboon
baboon
freplace
axoon
baboon
fdelete+replace
axoo
baboon
fdelete+replace+truncate
axon
baboon
fdelete+replace+single
baby
baboon
replace+truncate*2
578
COMPLEV Function
4
Chapter 4
balloon
;
baboon
replace+insert
proc print data=test label;
label GED=’Generalized Edit Distance’;
var String1 String2 GED Operation;
run;
The following output shows the results.
Output 4.41
Generalized Edit Distance Based on Operation
The SAS System
Obs
String1
String2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
baboon
baXboon
baoon
baXoon
baboonX
baboo
babboon
babon
baobon
bab oon
bab,oon
bXaoon
bXaYoon
bXoon
Xbaboon
aboon
Xaboon
axoon
axoo
axon
baby
balloon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
baboon
Generalized
Edit
Distance
0
100
100
100
50
10
20
20
20
10
30
200
200
200
200
200
200
300
310
320
120
200
Operation
match
insert
delete
replace
append
truncate
double
single
swap
blank
punctuation
insert+delete
insert+replace
delete+replace
finsert
trick question: swap+delete
freplace
fdelete+replace
fdelete+replace+truncate
fdelete+replace+single
replace+truncate*2
replace+insert
See Also
Functions:
“COMPARE Function” on page 569
“CALL COMPCOST Routine” on page 434
“COMPLEV Function” on page 578
COMPLEV Function
Returns the Levenshtein edit distance between two strings.
Category:
Restriction:
Character
“I18N Level 0” on page 304
1
Functions and CALL Routines
4
COMPLEV Function
579
Syntax
COMPLEV(string-1, string-2 <,cutoff> <,modifiers>)
Arguments
string–1
specifies a character constant, variable, or expression.
string–2
specifies a character constant, variable, or expression.
cutoff
specifies a numeric constant, variable, or expression. If the actual Levenshtein edit
distance is greater than the value of cutoff, the value that is returned is equal to the
value of cutoff.
Using a small value of cutoff improves the efficiency of COMPLEV if the values
of string–1 and string–2 are long.
Tip:
modifiers
specifies a character string that can modify the action of the COMPLEV function.
You can use one or more of the following characters as a valid modifier:
i or I
ignores the case in string–1 and string–2.
l or L
removes leading blanks in string–1 and string–2 before comparing
the values.
n or N
removes quotation marks from any argument that is an n-literal
and ignores the case of string–1 and string–2.
: (colon)
truncates the longer of string–1 or string–2 to the length of the
shorter string, or to one, whichever is greater.
TIP: COMPLEV ignores blanks that are used as modifiers.
Details
The order in which the modifiers appear in the COMPLEV function is relevant.
3 “LN” first removes leading blanks from each string and then removes quotation
marks from n-literals.
3 “NL” first removes quotation marks from n-literals and then removes leading
blanks from each string.
The COMPLEV function ignores trailing blanks.
COMPLEV returns the Levenshtein edit distance between string-1 and string-2.
Levenshtein edit distance is the number of insertions, deletions, or replacements of
single characters that are required to convert one string to the other. Levenshtein edit
distance is symmetric. That is, COMPLEV(string-1,string-2) is the same as
COMPLEV(string-2,string-1).
Comparisons
The Levenshtein edit distance that is computed by COMPLEV is a special case of the
generalized edit distance that is computed by COMPGED.
COMPLEV executes much more quickly than COMPGED.
580
COMPLEV Function
4
Chapter 4
Examples
The following example compares two strings by computing the Levenshtein edit
distance.
options pageno=1 nodate ls=80 ps=60;
data test;
infile datalines missover;
input string1 $char8. string2 $char8. modifiers $char8.;
result=complev(string1, string2, modifiers);
datalines;
1234567812345678
abc
abxc
ac
abc
aXc
abc
aXbZc
abc
aXYZc
abc
WaXbYcZ abc
XYZ
abcdef
aBc
abc
aBc
AbC
i
abc
abc
abc
abc
l
AxC
’abc’n
AxC
’abc’n
n
;
proc print data=test;
run;
The following output shows the results.
Output 4.42
Results of Comparing Two Strings by Computing the Levenshtein Edit Distance
The SAS System
Obs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string1
string2
12345678
abc
ac
aXc
aXbZc
aXYZc
WaXbYcZ
XYZ
aBc
aBc
abc
abc
AxC
AxC
12345678
abxc
abc
abc
abc
abc
abc
abcdef
abc
AbC
abc
abc
’abc’n
’abc’n
See Also
Functions and CALL Routines:
1
modifiers
i
l
n
result
0
1
1
1
2
3
4
6
1
0
2
0
6
1
Functions and CALL Routines
4
COMPOUND Function
581
“COMPARE Function” on page 569
“COMPGED Function” on page 573
“CALL COMPCOST Routine” on page 434
COMPOUND Function
Returns compound interest parameters.
Category: Financial
Syntax
COMPOUND(a,f,r,n)
Arguments
a
is numeric, and specifies the initial amount.
Range: a ≥ 0
f
is numeric, and specifies the future amount (at the end of n periods).
Range: f ≥ 0
r
is numeric, and specifies the periodic interest rate expressed as a fraction.
Range: r ≥ 0
n
is an integer, and specifies the number of compounding periods.
Range: n ≥ 0
Details
The COMPOUND function returns the missing argument in the list of four arguments
from a compound interest calculation. The arguments are related by the following
equation:
f
= a (1 + r)n
One missing argument must be provided. A compound interest parameter is then
calculated from the remaining three values. No adjustment is made to convert the
results to round numbers.
n
If n=0, then f = a and (1 + r) are equal to 1.
Note:
If you choose r as your missing value, then COMPOUND returns an error.
4
582
COMPRESS Function
4
Chapter 4
Examples
The accumulated value of an investment of $2000 at a nominal annual interest rate
of 9 percent, compounded monthly after 30 months, can be expressed as
future=compound(2000,.,0.09/12,30);
The value returned is 2502.54. The second argument has been set to missing,
indicating that the future amount is to be calculated. The 9 percent nominal annual
rate has been converted to a monthly rate of 0.09/12. The rate argument is the
fractional (not the percentage) interest rate per compounding period.
COMPRESS Function
Returns a character string with specified characters removed from the original string.
Character
Category:
Restriction:
“I18N Level 0” on page 304
Tip: DBCS equivalent function is KCOMPRESS in SAS National Language Support
(NLS): Reference Guide.
Syntax
COMPRESS(< source><, chars>< , modifiers>)
Arguments
source
specifies a character constant, variable, or expression from which specified characters
will be removed.
chars
specifies a character constant, variable, or expression that initializes a list of
characters.
By default, the characters in this list are removed from the source argument. If
you specify the K modifier in the third argument, then only the characters in this list
are kept in the result.
You can add more characters to this list by using other modifiers in the third
argument.
Tip:
Tip:
Enclose a literal string of characters in quotation marks.
modifier
specifies a character constant, variable, or expression in which each non-blank
character modifies the action of the COMPRESS function. Blanks are ignored. The
following characters can be used as modifiers:
a or A
adds alphabetic characters to the list of characters.
c or C
adds control characters to the list of characters.
Functions and CALL Routines
4
COMPRESS Function
583
d or D
adds digits to the list of characters.
f or F
adds the underscore character and English letters to the list of
characters.
g or G
adds graphic characters to the list of characters.
h or H
adds a horizontal tab to the list of characters.
i or I
ignores the case of the characters to be kept or removed.
k or K
keeps the characters in the list instead of removing them.
l or L
adds lowercase letters to the list of characters.
n or N
adds digits, the underscore character, and English letters to the
list of characters.
o or O
processes the second and third arguments once rather than every
time the COMPRESS function is called. Using the O modifier in
the DATA step (excluding WHERE clauses), or in the SQL
procedure, can make COMPRESS run much faster when you call
it in a loop where the second and third arguments do not change.
p or P
adds punctuation marks to the list of characters.
s or S
adds space characters (blank, horizontal tab, vertical tab, carriage
return, line feed, and form feed) to the list of characters.
t or T
trims trailing blanks from the first and second arguments.
u or U
adds uppercase letters to the list of characters.
w or W
adds printable characters to the list of characters.
x or X
adds hexadecimal characters to the list of characters.
If the modifier is a constant, enclose it in quotation marks. Specify multiple
constants in a single set of quotation marks. Modifier can also be expressed as a
variable or an expression.
Tip:
Details
Length of Returned Variable
In a DATA step, if the COMPRESS function returns a
value to a variable that has not previously been assigned a length, then that variable is
given the length of the first argument.
The Basics
The COMPRESS function allows null arguments. A null argument is
treated as a string that has a length of zero.
Based on the number of arguments, the COMPRESS functions works as follows:
584
COMPRESS Function
4
Chapter 4
Number of Arguments
Result
only the first argument, source
The argument has all blanks removed. If the
argument is completely blank, then the result is
a string with a length of zero. If you assign the
result to a character variable with a fixed
length, then the value of that variable will be
padded with blanks to fill its defined length.
the first two arguments, source and chars
All characters that appear in the second
argument are removed from the result.
three arguments, source, chars, and modifier(s)
The K modifier (specified in the third argument)
determines whether the characters in the second
argument are kept or removed from the result.
The COMPRESS function compiles a list of characters to keep or remove, comprising
the characters in the second argument plus any types of characters that are specified by
the modifiers. For example, the D modifier specifies digits. Both of the following
function calls remove digits from the result:
COMPRESS(source, "1234567890");
COMPRESS(source, , "d");
To remove digits and plus or minus signs, you can use either of the following function
calls:
COMPRESS(source, "1234567890+-");
COMPRESS(source, "+-", "d");
Examples
Example 1: Compressing Blanks
SAS Statements
Results
----+----1
a=’AB C D ’;
b=compress(a);
put b;
ABCD
Example 2: Compressing Lowercase Letters
SAS Statements
Results
----+----1----+----2----+----3
x=’123-4567-8901 B 234-5678-9012 c’;
y=compress(x,’ABCD’,’l’);
put y;
123-4567-8901 234-5678-9012
Functions and CALL Routines
Example 3: Compressing Space Characters
SAS Statements
Results
----+----1
x=’1
2
3
4
y=compress(x,,’s’);
put y;
5’;
12345
Example 4: Keeping Characters in the List
SAS Statements
Results
----+----1
x=’Math A English B Physics A’;
y=compress(x,’ABCD’,’k’);
put y;
ABA
Example 5: Compressing a String and Returning a Length of 0
SAS Statements
Results
----+----1
x=’ ’;
l=lengthn(compress(x));
put l;
See Also
Functions:
“COMPBL Function” on page 572
“LEFT Function” on page 846
“TRIM Function” on page 1119
CONSTANT Function
Computes machine and mathematical constants.
Category: Mathematical
0
4
CONSTANT Function
585
586
CONSTANT Function
4
Chapter 4
Syntax
CONSTANT(constant<, parameter>)
Arguments
constant
is a character constant, variable, or expression that identifies the constant to be
returned. Valid constants are as follows:
Description
Constant
The natural base
’E’
Euler constant
’EULER’
Pi
’PI’
Exact integer
’EXACTINT’ <,nbytes>
The largest double-precision number
’BIG’
The log with respect to base of BIG
’LOGBIG’ <,base>
The square root of BIG
’SQRTBIG’
The smallest double-precision number
’SMALL’
The log with respect to base of SMALL
’LOGSMALL’ <,base>
The square root of SMALL
’SQRTSMALL’
Machine precision constant
’MACEPS’
The log with respect to base of MACEPS
’LOGMACEPS’ <,base>
The square root of MACEPS
’SQRTMACEPS’
parameter
is an optional numeric parameter. Some of the constants specified in constant have
an optional argument that alters the functionality of the CONSTANT function.
Details
CAUTION:
In some operating environments, the run-time library might have limitations that prevent
the use of the full range of floating-point numbers that the hardware provides. In such
cases, the CONSTANT function attempts to return values that are compatible with
the limitations of the run-time library.
For example, if the run-time library cannot compute
EXP(LOG(CONSTANT(’BIG’))), then CONSTANT(’LOGBIG’) will not return the same
value as LOG(CONSTANT(’BIG’)), but will return a value such that
EXP(CONSTANT(’LOGBIG’)) can be computed. 4
The natural base
CONSTANT(’E’)
The natural base is described by the following equation:
Functions and CALL Routines
1
!
lim (1 +
x 0
x) x
4
CONSTANT Function
587
:
2 71828182 8459045
Euler constant
CONSTANT(’EULER’)
Euler’s constant is described by the following equation:
8j =n
<X
0
n !1 :
j =1
1
lim
j
log (
9
=
n
;
)
0:577215664901532860
Pi
CONSTANT(’PI’)
Pi is the ratio between the circumference and the diameter of a circle. Many
expressions exist for computing this constant. One such expression for the series is
described by the following equation:
=1
X
0 j
j
4
j
=0
j
(
1)
2
+1
3:1415926 53589793 23846
Exact integer
CONSTANT(’EXACTINT’ <, nbytes>)
where
nbytes
is a numeric value that is the number of bytes.
Range: 2 ≤ nbytes ≤ 8
Default: 8
The exact integer is the largest integer k such that all integers less than or equal to
k in absolute value have an exact representation in a SAS numeric variable of length
nbytes. This information can be useful to know before you trim a SAS numeric variable
from the default 8 bytes of storage to a lower number of bytes to save storage.
The largest double-precision number
CONSTANT(’BIG’)
This case returns the largest double-precision floating-point number (8-bytes) that is
representable on your computer.
The logarithm of BIG
CONSTANT(’LOGBIG’ <, base>)
where
base
is a numeric value that is the base of the logarithm.
588
CONSTANT Function
4
Chapter 4
Restriction: The base that you specify must be greater than the value of
1+SQRTMACEPS.
Default: the natural base, E.
This case returns the logarithm with respect to base of the largest double-precision
floating-point number (8-bytes) that is representable on your computer.
It is safe to exponentiate the given base raised to a power less than or equal to
CONSTANT(’LOGBIG’, base) by using the power operation (**) without causing any
overflows.
It is safe to exponentiate any floating-point number less than or equal to
CONSTANT(’LOGBIG’) by using the exponential function, EXP, without causing any
overflows.
The square root of BIG
CONSTANT(’SQRTBIG’)
This case returns the square root of the largest double-precision floating-point number
(8-bytes) that is representable on your computer.
It is safe to square any floating-point number less than or equal to
CONSTANT(’SQRTBIG’) without causing any overflows.
The smallest double-precision number
CONSTANT(’SMALL’)
This case returns the smallest double-precision floating-point number (8-bytes) that is
representable on your computer.
The logarithm of SMALL
CONSTANT(’LOGSMALL’ <, base>)
where
base
is a numeric value that is the base of the logarithm.
Restriction: The base that you specify must be greater than the value of
1+SQRTMACEPS.
Default: the natural base, E.
This case returns the logarithm with respect to base of the smallest double-precision
floating-point number (8-bytes) that is representable on your computer.
It is safe to exponentiate the given base raised to a power greater than or equal to
CONSTANT(’LOGSMALL’, base) by using the power operation (**) without causing any
underflows or 0.
It is safe to exponentiate any floating-point number greater than or equal to
CONSTANT(’LOGSMALL’) by using the exponential function, EXP, without causing
any underflows or 0.
The square root of SMALL
CONSTANT(’SQRTSMALL’)
This case returns the square root of the smallest double-precision floating-point number
(8-bytes) that is representable on the computer.
It is safe to square any floating-point number greater than or equal to
CONSTANT(’SQRTBIG’) without causing any underflows or 0.
Machine precision
CONSTANT(’MACEPS’)
Functions and CALL Routines
4
CONVX Function
This case returns the smallest double-precision floating-point number (8-bytes) for some integer j, such that 1 + > 1.
This constant is important in finite precision computations.
= 20j
The logarithm of MACEPS
CONSTANT(’LOGMACEPS’ <, base>)
where
base
is a numeric value that is the base of the logarithm.
Restriction: The base that you specify must be greater than the value of
1+SQRTMACEPS.
Default: the natural base, E.
This case returns the logarithm with respect to base of CONSTANT(’MACEPS’).
The square root of MACEPS
CONSTANT(’SQRTMACEPS’)
This case returns the square root of CONSTANT(’MACEPS’).
CONVX Function
Returns the convexity for an enumerated cash flow.
Category: Financial
Syntax
CONVX(y,f,c(1), ... ,c(k))
Arguments
y
specifies the effective per-period yield-to-maturity, expressed as a fraction.
Range:
0<y<1
f
specifies the frequency of cash flows per period.
Range: f >
0
c(1), ... ,c(k)
specifies a list of cash flows.
Details
The CONVX function returns the value
589
590
CONVXP Function
4
Chapter 4
K k k
X
C=
f ) (1+c(ky)) kf
2 f2
P
(1
+
y
)
k=1
(
+
where
P
=
K c (k )
X
k
k=1 (1 + y ) f
Examples
data _null_;
c=convx(1/20,1,.33,.44,.55,.49,.50,.22,.4,.8,.01,.36,.2,.4);
put c;
run;
The value returned is 42.3778.
CONVXP Function
Returns the convexity for a periodic cash flow stream, such as a bond.
Category:
Financial
Syntax
CONVXP(A,c,n,K,k0,y)
Arguments
A
specifies the par value.
Range:
A>0
c
specifies the nominal per-period coupon rate, expressed as a fraction.
Range:
0
c<1
n
specifies the number of coupons per period.
Range:
n > 0 and is an integer
K
specifies the number of remaining coupons.
Range:
0 and is an integer
K>
Functions and CALL Routines
4
COS Function
591
k0
specifies the time from the present date to the first coupon date, expressed in terms
of the number of periods.
Range:
0
< k0 n1
y
specifies the nominal per-period yield-to-maturity, expressed as a fraction.
Range:
y>0
Details
The CONVXP function returns the value
0P
K
c(k)
tk (tk + 1)
B
1+
( )
1 B
C = 2 B k=1
0
1
2
n @
P 1 + ny
y tk
n
1
C
C
C
A
where
tk = nk0 + k 0 1
c (k ) = nc A f or k
c (K ) = 1 + nc A
0
1 = 1; . . . ; K 0 1
and where
P
=
K
X
k=1
01 c+(ky)1t
n
k
Examples
In the following example, the CONVXP function returns the convexity of a bond that
has a face value of 1000, an annual coupon rate of 0.01, 4 coupons per year, and 14
remaining coupons. The time from settlement date to next coupon date is 0.165, and
the annual yield-to-maturity is 0.08.
data _null_;
y=convxp(1000,.01,4,14,.33/2,.08);
put y;
run;
The value that is returned is 11.729001987.
COS Function
Returns the cosine.
592
COSH Function
4
Chapter 4
Category:
Trigonometric
Syntax
COS (argument)
Arguments
argument
specifies a numeric constant, variable, or expression and is expressed in radians. If
the magnitude of argument is so great that mod(argument,pi) is accurate to less
than about three decimal places, COS returns a missing value.
Examples
SAS Statements
Results
x=cos(0.5);
0.8775825619
x=cos(0);
1
x=cos(3.14159/3);
0.500000766
COSH Function
Returns the hyperbolic cosine.
Category:
Hyperbolic
Syntax
COSH(argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The COSH function returns the hyperbolic cosine of the argument, given by
0 argument
e
+ e0argument
1
=2
Functions and CALL Routines
4
COUNT Function
593
Examples
SAS Statements
Results
x=cosh(0);
1
x=cosh(-5.0);
74.209948525
x=cosh(0.5);
1.1276259652
COUNT Function
Counts the number of times that a specified substring appears within a character string.
Category: Character
Restriction:
“I18N Level 1” on page 304
You can use the KCOUNT function in SAS National Language Support (NLS):
Reference Guide for DBCS processing, but the functionality is different. See “DBCS
Compatibility” on page 594.
Tip:
Syntax
COUNT(string, substring < ,modifiers>)
Arguments
string
specifies a character constant, variable, or expression in which substrings are to be
counted.
Tip:
Enclose a literal string of characters in quotation marks.
substring
is a character constant, variable, or expression that specifies the substring of
characters to count in string.
Tip:
Enclose a literal string of characters in quotation marks.
modifiers
is a character constant, variable, or expression that specifies one or more modifiers.
The following modifiers can be in uppercase or lowercase:
i
ignores character case during the count. If this modifier is not
specified, COUNT only counts character substrings with the same
case as the characters in substring.
t
trims trailing blanks from string and substring.
If the modifier is a constant, enclose it in quotation marks. Specify multiple
constants in a single set of quotation marks. Modifier can also be expressed as a
variable or an expression.
Tip:
594
COUNT Function
4
Chapter 4
Details
The Basics
The COUNT function searches string, from left to right, for the number of
occurrences of the specified substring, and returns that number of occurrences. If the
substring is not found in string, COUNT returns a value of 0.
CAUTION:
If two occurrences of the specified substring overlap in the string, the result is undefined.
For example, COUNT(’boobooboo’, ’booboo’) might return either a 1 or a 2. 4
DBCS Compatibility
You can use the KCOUNT function, which is documented in SAS National Language
Support (NLS): Reference Guide, for DBCS processing, but the functionality is different.
If the value of substring in the COUNT function is longer than two bytes, then the
COUNT function can handle DBCS strings. The following examples show the
differences in syntax:
COUNT(string, substring <,modifiers>
KCOUNT(string)
Comparisons
The COUNT function counts substrings of characters in a character string, whereas the
COUNTC function counts individual characters in a character string.
Examples
The following SAS statements produce these results:
SAS Statements
Results
xyz=’This is a thistle? Yes, this is a thistle.’;
howmanythis=count(xyz,’this’);
put howmanythis;
3
xyz=’This is a thistle? Yes, this is a thistle.’;
howmanyis=count(xyz,’is’);
put howmanyis;
6
howmanythis_i=count(’This is a thistle? Yes, this is a thistle.’
,’this’,’i’);
put howmanythis_i;
4
variable1=’This is a thistle? Yes, this is a thistle.’;
variable2=’is ’;
variable3=’i’;
howmanyis_i=count(variable1,variable2,variable3);
put howmanyis_i;
4
expression1=’This is a thistle? ’||’Yes, this is a thistle.’;
expression2=kscan(’This is’,2)||’
’;
expression3=compress(’i
’||’
t’);
howmanyis_it=count(expression1,expression2,expression3);
put howmanyis_it;
6
See Also
Functions and CALL Routines
4
COUNTC Function
595
Functions:
“COUNTC Function” on page 595
“COUNTW Function” on page 598
“FIND Function” on page 705
“INDEX Function” on page 784
COUNTC Function
Counts the number of characters in a string that appear or do not appear in a list of characters.
Category: Character
Restriction:
“I18N Level 1” on page 304
Syntax
COUNTC(string, charlist <,modifiers>)
Arguments
string
specifies a character constant, variable, or expression in which characters are
counted.
Tip: Enclose a literal string of characters in quotation marks.
charlist
specifies a character constant, variable, or expression that initializes a list of
characters. COUNTC counts characters in this list, provided that you do not specify
the V modifier in the modifier argument. If you specify the V modifier, then all
characters that are not in this list are counted. You can add more characters to the
list by using other modifiers.
Tip: Enclose a literal string of characters in quotation marks.
Tip: If there are no characters in the list after processing the modifiers, COUNTC
returns 0.
modifier
specifies a character constant, variable, or expression in which each non-blank
character modifies the action of the COUNTC function. Blanks are ignored. The
following characters, in uppercase or lowercase, can be used as modifiers:
blank
is ignored.
a or A
adds alphabetic characters to the list of characters.
b or B
scans string from right to left, instead of from left to right.
c or C
adds control characters to the list of characters.
d or D
adds digits to the list of characters.
f or F
adds an underscore and English letters ( that is, the characters
that can begin a SAS variable name using VALIDVARNAME=V7)
to the list of characters.
596
COUNTC Function
4
Chapter 4
g or G
adds graphic characters to the list of characters.
h or H
adds a horizontal tab to the list of characters.
i or I
ignores case.
l or L
adds lowercase letters to the list of characters.
n or N
adds digits, an underscore, and English letters (that is, the
characters that can appear in a SAS variable name using
VALIDVARNAME=V7) to the list of characters.
o or O
processes the charlist and modifier arguments only once, at the
first call to this instance of COUNTC. If you change the value of
charlist or modifier in subsequent calls, the change might be
ignored by COUNTC.
p or P
adds punctuation marks to the list of characters.
s or S
adds space characters to the list of characters (blank, horizontal
tab, vertical tab, carriage return, line feed, and form feed).
t or T
trims trailing blanks from string and chars.
Tip: If you want to remove trailing blanks from only one
character argument instead of both (or all) character
arguments, use the TRIM function instead of the COUNTC
function with the T modifier.
u or U
adds uppercase letters to the list of characters.
v or V
counts characters that do not appear in the list of characters. If
you do not specify this modifier, then COUNTC counts characters
that do appear in the list of characters.
w or W
adds printable characters to the list of characters.
x or X
adds hexadecimal characters to the list of characters.
Tip: If modifier is a constant, enclose it in quotation marks. Specify multiple
constants in a single set of quotation marks.
Details
The COUNTC function allows character arguments to be null. Null arguments are
treated as character strings with a length of zero. If there are no characters in the list
of characters to be counted, COUNTC returns zero.
Comparisons
The COUNTC function counts individual characters in a character string, whereas the
COUNT function counts substrings of characters in a character string.
Examples
The following example uses the COUNTC function with and without modifiers to
count the number of characters in a string.
data test;
string
a
b
b_i
=
=
=
=
’Baboons Eat Bananas
countc(string, ’a’);
countc(string,’b’);
countc(string,’b’,’i’);
’;
Functions and CALL Routines
abc_i
= countc(string,’abc’,’i’);
/* Scan string for characters that are not "a", "b",
/* and "c", ignore case, (and include blanks).
abc_iv = countc(string,’abc’,’iv’);
/* Scan string for characters that are not "a", "b",
/* and "c", ignore case, and trim trailing blanks.
abc_ivt = countc(string,’abc’,’ivt’);
run;
4
COUNTC Function
*/
*/
*/
*/
options pageno=1 ls=80 nodate;
proc print data=test noobs;
run;
Output 4.43
Output from Using the COUNTC Functions with and without Modifiers
The SAS System
string
Baboons Eat Bananas
1
a
b
b_i
abc_i
abc_iv
abc_ivt
5
1
3
8
16
11
See Also
Functions:
“ANYALNUM Function” on page 368
“ANYALPHA Function” on page 370
“ANYCNTRL Function” on page 372
“ANYDIGIT Function” on page 373
“ANYGRAPH Function” on page 377
“ANYLOWER Function” on page 379
“ANYPRINT Function” on page 382
“ANYPUNCT Function” on page 384
“ANYSPACE Function” on page 386
“ANYUPPER Function” on page 388
“ANYXDIGIT Function” on page 389
“NOTALNUM Function” on page 909
“NOTALPHA Function” on page 911
“NOTCNTRL Function” on page 913
“NOTDIGIT Function” on page 914
“NOTGRAPH Function” on page 919
“NOTLOWER Function” on page 921
“NOTPRINT Function” on page 925
“NOTPUNCT Function” on page 926
“NOTSPACE Function” on page 928
“NOTUPPER Function” on page 930
“NOTXDIGIT Function” on page 932
“FINDC Function” on page 707
597
598
COUNTW Function
4
Chapter 4
“INDEXC Function” on page 786
“VERIFY Function” on page 1139
COUNTW Function
Counts the number of words in a character string.
Category:
Character
Syntax
COUNTW(< string><, chars>< , modifiers>)
Arguments
string
specifies a character constant, variable, or expression in which words are counted.
chars
specifies an optional character constant, variable, or expression that initializes a list
of characters. The characters in this list are the delimiters that separate words,
provided that you do not use the K modifier in the modifier argument. If you specify
the K modifier, then all characters that are not in this list are delimiters. You can
add more characters to the list by using other modifiers.
modifier
specifies a character constant, variable, or expression in which each non-blank
character modifies the action of the COUNTW function. The following characters, in
uppercase or lowercase, can be used as modifiers:
blank
is ignored.
a or A
adds alphabetic characters to the list of characters.
b or B
counts from right to left instead of from left to right. Right-to-left
counting makes a difference only when you use the Q modifier
and the string contains unbalanced quotation marks.
c or C
adds control characters to the list of characters.
d or D
adds digits to the list of characters.
f or F
adds an underscore and English letters (that is, the characters
that can begin a SAS variable name using VALIDVARNAME=V7)
to the list of characters.
g or G
adds graphic characters to the list of characters.
h or H
adds a horizontal tab to the list of characters.
i or I
ignores the case of the characters.
k or K
causes all characters that are not in the list of characters to be
treated as delimiters. If K is not specified, then all characters
that are in the list of characters are treated as delimiters.
Functions and CALL Routines
4
COUNTW Function
599
l or L
adds lowercase letters to the list of characters.
m or M
specifies that multiple consecutive delimiters, and delimiters at
the beginning or end of the string argument, refer to words that
have a length of zero. If the M modifier is not specified, then
multiple consecutive delimiters are treated as one delimiter, and
delimiters at the beginning or end of the string argument are
ignored.
n or N
adds digits, an underscore, and English letters (that is, the
characters that can appear after the first character in a SAS
variable name using VALIDVARNAME=V7) to the list of
characters.
o or O
processes the chars and modifier arguments only once, rather
than every time the COUNTW function is called. Using the O
modifier in the DATA step (excluding WHERE clauses), or in the
SQL procedure, can make COUNTW run faster when you call it
in a loop where chars and modifier arguments do not change.
p or P
adds punctuation marks to the list of characters.
q or Q
ignores delimiters that are inside of substrings that are enclosed
in quotation marks. If the value of string contains unmatched
quotation marks, then scanning from left to right will produce
different words than scanning from right to left.
s or S
adds space characters (blank, horizontal tab, vertical tab, carriage
return, line feed, and form feed) to the list of characters.
t or T
trims trailing blanks from the string and chars arguments.
u or U
adds uppercase letters to the list of characters.
w or W
adds printable characters to the list of characters.
x or X
adds hexadecimal characters to the list of characters.
Details
Definition of “Word”
In the COUNTW function, “word” refers to a substring that has
one of the following characteristics:
3 is bounded on the left by a delimiter or the beginning of the string
3 is bounded on the right by a delimiter or the end of the string
3 contains no delimiters, except if you use the Q modifier and the delimiters are
within substrings that have quotation marks
Note: The definition of “word” is the same in both the SCAN function and the
COUNTW.sgml function. 4
Delimiter refers to any of several characters that you can specify to separate words.
Using the COUNTW Function in ASCII and EBCDIC Environments
If you use the
COUNTW function with only two arguments, the default delimiters depend on whether
your computer uses ASCII or EBCDIC characters.
3 If your computer uses ASCII characters, then the default delimiters are as follows:
blank ! $ % & ( )* + , - . / ; < ^ |
In ASCII environments that do not contain the ^ character, the SCAN function
uses the ~ character instead.
600
COUNTW Function
4
Chapter 4
3 If your computer uses EBCDIC characters, then the default delimiters are as
follows:
blank ! $ % & ( )* + , - . / ; <
|¢
Using Null Arguments
The COUNTW function allows character arguments to be null.
Null arguments are treated as character strings with a length of zero. Numeric
arguments cannot be null.
Using the M Modifier
If you do not use the M modifier, then a word must contain at least one character. If
you use the M modifier, then a word can have a length of zero. In this case, the number
of words is one plus the number of delimiters in the string, not counting delimiters
inside of strings that are enclosed in quotation marks when you use the Q modifier.
Examples
The following example shows how to use the COUNTW function with the M and P
modifiers.
options ls=64 pageno=1 nodate;
data test;
length default blanks mp 8;
input string $char60.;
default = countw(string);
blanks = countw(string, ’ ’);
mp = countw(string, ’mp’);
datalines;
The quick brown fox jumps over the lazy dog.
Leading blanks
2+2=4
/unix/path/names/use/slashes
\Windows\Path\Names\Use\Backslashes
;
run;
proc print noobs data=test;
run;
Output 4.44
Output from the COUNTW Function
The SAS System
default blanks mp
9
2
2
5
1
9
2
1
1
1
2
1
1
3
2
string
The quick brown fox jumps over the lazy dog.
Leading blanks
2+2=4
/unix/path/names/use/slashes
\Windows\Path\Names\Use\Backslashes
See Also
Functions and CALL Routines:
“COUNT Function” on page 593
1
Functions and CALL Routines
4
CUROBS Function
601
“COUNTC Function” on page 595
“FINDW Function” on page 713
“SCAN Function” on page 1060
“CALL SCAN Routine” on page 500
CSS Function
Returns the corrected sum of squares.
Category: Descriptive Statistics
Syntax
CSS(argument-1<,...argument-n>)
Arguments
argument
specifies a numeric constant, variable, or expression. At least one nonmissing
argument is required. Otherwise, the function returns a missing value. If you have
more than one argument, the argument list can consist of a variable list, which is
preceded by OF.
Examples
SAS Statements
Results
x1=css(5,9,3,6);
18.75
x2=css(5,8,9,6,.);
10
x3=css(8,9,6,.);
4.6666666667
x4=css(of x1-x3);
101.11574074
CUROBS Function
Returns the observation number of the current observation.
Category: SAS File I/O
Requirement: Use this function only with an uncompressed SAS data set that is accessed
using a native library engine.
602
CV Function
4
Chapter 4
Syntax
CUROBS(data-set-id)
Arguments
data-set-id
is a numeric value that specifies the data set identifier that the OPEN function
returns.
Details
If the engine being used does not support observation numbers, the function returns a
missing value.
With a SAS view, the function returns the relative observation number, that is, the
number of the observation within the SAS view (as opposed to the number of the
observation within any related SAS data set).
Examples
This example uses the FETCHOBS function to fetch the tenth observation in the
data set MYDATA. The value of OBSNUM returned by CUROBS is 10.
%let dsid=%sysfunc(open(mydata,i));
%let rc=%sysfunc(fetchobs(&dsid,10));
%let obsnum=%sysfunc(curobs(&dsid));
See Also
Functions:
“FETCHOBS Function” on page 659
“OPEN Function” on page 939
CV Function
Returns the coefficient of variation.
Category:
Descriptive Statistics
Syntax
CV(argument-1,argument-2< ,...argument-n>)
Arguments
argument
Functions and CALL Routines
4
DACCDB Function
specifies a numeric constant, variable, or expression. At least two arguments are
required. The argument list can consist of a variable list, which is preceded by OF.
Examples
SAS Statements
Results
x1=cv(5,9,3,6);
43.47826087
x2=cv(5,8,9,6,.);
26.082026548
x3=cv(8,9,6,.);
19.924242152
x4=cv(of x1-x3);
40.953539216
DACCDB Function
Returns the accumulated declining balance depreciation.
Category: Financial
Syntax
DACCDB(p,v,y,r)
Arguments
p
is numeric, the period for which the calculation is to be done. For noninteger p
arguments, the depreciation is prorated between the two consecutive time periods
that precede and follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
y
is numeric, the lifetime of the asset.
Range: y > 0
r
is numeric, the rate of depreciation expressed as a decimal.
Range: r > 0
Details
The DACCDB function returns the accumulated depreciation by using a declining
balance method. The formula is
603
604
DACCDBSL Function
4
DACCDB(p
Chapter 4
; v;
y; r
)=
(0
v
int(p) r
10( 0
10 10y
p
r
( )) y
int p
p
0
p >
0
Note that int(p) is the integer part of p. The p and y arguments must be expressed
by using the same units of time. A double-declining balance is obtained by setting r
equal to 2.
Examples
An asset has a depreciable initial value of $1000 and a fifteen-year lifetime. Using a
200 percent declining balance, the depreciation throughout the first 10 years can be
expressed as
a=daccdb(10,1000,15,2);
The value returned is 760.93. The first and the third arguments are expressed in
years.
DACCDBSL Function
Returns the accumulated declining balance with conversion to a straight-line depreciation.
Category:
Financial
Syntax
DACCDBSL(p,v,y,r)
Arguments
p
is numeric, the period for which the calculation is to be done.
v
is numeric, the depreciable initial value of the asset.
y
is an integer, the lifetime of the asset.
Range: y > 0
r
is numeric, the rate of depreciation that is expressed as a fraction.
Range: r > 0
Details
The DACCDBSL function returns the accumulated depreciation by using a declining
balance method, with conversion to a straight-line depreciation function that is defined
by
Functions and CALL Routines
DACCDBSL (p
; v; y; r
X
) = DEPDBSL (
p
i=1
i; v; y; r
4
DACCSL Function
605
)
The declining balance with conversion to a straight-line depreciation chooses for each
time period the method of depreciation (declining balance or straight-line on the
remaining balance) that gives the larger depreciation. The p and y arguments must be
expressed by using the same units of time.
Examples
An asset has a depreciable initial value of $1,000 and a ten-year lifetime. Using a
declining balance rate of 150 percent, the accumulated depreciation of that asset in its
fifth year can be expressed as
y5=daccdbsl(5,1000,10,1.5);
The value returned is 564.99. The first and the third arguments are expressed in
years.
DACCSL Function
Returns the accumulated straight-line depreciation.
Category: Financial
Syntax
DACCSL(p,v,y)
Arguments
p
is numeric, the period for which the calculation is to be done. For fractional p, the
depreciation is prorated between the two consecutive time periods that precede and
follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
y
is numeric, the lifetime of the asset.
Range: y > 0
Details
The DACCSL function returns the accumulated depreciation by using the straight-line
method, which is given by
606
DACCSYD Function
4
Chapter 4
8
0
< 0 p
)=: y 0 p <
DACCSL (p
; v; y
v
p
v
p > y
y
The p and y arguments must be expressed by using the same units of time.
Examples
An asset, acquired on 01APR86, has a depreciable initial value of $1000 and a
ten-year lifetime. The accumulated depreciation in the value of the asset through
31DEC87 can be expressed as
a=daccsl(1.75,1000,10);
The value returned is 175.00. The first and the third arguments are expressed in
years.
DACCSYD Function
Returns the accumulated sum-of-years-digits depreciation.
Category:
Financial
Syntax
DACCSYD(p,v,y)
Arguments
p
is numeric, the period for which the calculation is to be done. For noninteger p
arguments, the depreciation is prorated between the two consecutive time periods
that precede and follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
y
is numeric, the lifetime of the asset.
Range: y > 0
Details
The DACCSYD function returns the accumulated depreciation by using the
sum-of-years-digits method. The formula is
DACCSYD (p
; v; y
80
<
)=:
v
v
( 0 nt p 0int)y+(0p0int(p))(y0int(p))
int(y )(y 0
)+(y0int(y))
int(p) y
i
( )
2
1
( ) 1
2
2
p <
0
0 p
p > y
y
Functions and CALL Routines
4
DACCTAB Function
607
Note that int(y) indicates the integer part of y. The p and y arguments must be
expressed by using the same units of time.
Examples
An asset, acquired on 01OCT86, has a depreciable initial value of $1,000 and a
five-year lifetime. The accumulated depreciation of the asset throughout 01JAN88 can
be expressed as
y2=daccsyd(15/12,1000,5);
The value returned is 400.00. The first and the third arguments are expressed in
years.
DACCTAB Function
Returns the accumulated depreciation from specified tables.
Category: Financial
Syntax
DACCTAB(p,v,t1, . . . ,tn)
Arguments
p
is numeric, the period for which the calculation is to be done. For noninteger p
arguments, the depreciation is prorated between the two consecutive time periods
that precede and follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
t1,t2, . . . ,tn
are numeric, the fractions of depreciation for each time period with t1+t2+...tn 1.
Details
The DACCTAB function returns the accumulated depreciation by using user-specified
tables. The formula for this function is
DACCTAB (p;v;t1;t2;:::;tn) =
(0
0
v t1
v
+ t2 + ::: + t
int(p )
For a given p, only the arguments t1 ; t2 ;
+ (p 0 int (p)) t
...;t
k
int(p)+1
1
0
0<p<n
pn
p
need to be specified with k=ceil(p).
608
DAIRY Function
4
Chapter 4
Examples
An asset has a depreciable initial value of $1000 and a five-year lifetime. Using a
table of the annual depreciation rates of .15, .22, .21, .21, and .21 during the first,
second, third, fourth, and fifth years, respectively, the accumulated depreciation
throughout the third year can be expressed as
y3=dacctab(3,1000,.15,.22,.21,.21,.21);
The value that is returned is 580.00. The fourth rate, .21, and the fifth rate, .21, can
be omitted because they are not needed in the calculation.
DAIRY Function
Returns the derivative of the AIRY function.
Category:
Mathematical
Syntax
DAIRY(x)
Arguments
x
specifies a numeric constant, variable, or expression.
Details
The DAIRY function returns the value of the derivative of the AIRY function
(Abramowitz and Stegun 1964; Amos, Daniel, and Weston 1977).
Examples
SAS Statements
Results
x=dairy(2.0);
-0.053090384
x=dairy(-2.0);
0.6182590207
DATDIF Function
Returns the number of days between two dates after computing the difference between the dates
according to specified day count conventions.
Functions and CALL Routines
4
DATDIF Function
609
Category: Date and Time
Syntax
DATDIF(sdate,edate,basis)
Arguments
sdate
specifies a SAS date value that identifies the starting date.
If sdate falls at the end of a month, then SAS treats the date as if it were the
last day of a 30-day month.
Tip:
edate
specifies a SAS date value that identifies the ending date.
If edate falls at the end of a month, then SAS treats the date as if it were the
last day of a 30-day month.
Tip:
basis
specifies a character string that represents the day count basis. The following values
for basis are valid:
’30/360’
specifies a 30-day month and a 360-day year, regardless of the actual number of
calendar days in a month or year.
A security that pays interest on the last day of a month will either always make
its interest payments on the last day of the month, or it will always make its
payments on the numerically same day of a month, unless that day is not a valid
day of the month, such as February 30. For more information, see “Method of
Calculation for Day Count Basis (30/360)” on page 610.
Alias: ’360’
’ACT/ACT’
uses the actual number of days between dates. Each month is considered to have
the actual number of calendar days in that month, and each year is considered to
have the actual number of calendar days in that year.
Alias: ’Actual’
’ACT/360’
uses the actual number of calendar days in a particular month, and 360 days as
the number of days in a year, regardless of the actual number of days in a year.
Tip: ACT/360 is used for short-term securities.
’ACT/365’
uses the actual number of calendar days in a particular month, and 365 days as
the number of days in a year, regardless of the actual number of days in a year.
Tip: ACT/365 is used for short-term securities.
Details
The Basics
The DATDIF function has a specific meaning in the securities industry, and the method
of calculation is not the same as the actual day count method. Calculations can use
610
DATDIF Function
4
Chapter 4
months and years that contain the actual number of days. Calculations can also be
based on a 30-day month or a 360-day year. For more information about standard
securities calculation methods, see “References” on page 611.
Note: When counting the number of days in a month, DATDIF always includes the
starting date and excludes the ending date. 4
Method of Calculation for Day Count Basis (30/360)
To calculate the number of days
between two dates, use the following formula:
Numberofdays = Y 0 Y
[(
2
1)
3 360] + [(M 2 0 M 1) 3 30] + (D2 0 D1)
where
Y2
specifies the year of the later date.
Y1
specifies the year of the earllier date.
M2
specifies the month of the later date.
M1
specifies the month of the earlier date.
D2
specifies the day of the later date.
D1
specifies the day of the earlier date.
Because all months can contain only 30 days, you must adjust for the months that do
not contain 30 days. Do this before you calculate the number of days between the two
dates.
The following rules apply:
3 If the security follows the End-of-Month rule, and D2 is the last day of February
(28 days in a non-leap year, 29 days in a leap year), and D1 is the last day of
February, then change D2 to 30.
3 If the security follows the End-of-Month rule, and D1 is the last day of February,
then change D1 to 30.
3 If the value of D2 is 31 and the value of D1 is 30 or 31, then change D2 to 30.
3 If the value of D1 is 31, then change D1 to 30.
Examples
In the following example, DATDIF returns the actual number of days between two
dates, as well as the number of days based on a 30-day month and a 360-day year.
data _null;
sdate=’16oct78’d;
edate=’16feb96’d;
actual=datdif(sdate, edate, ’act/act’);
days360=datdif(sdate, edate, ’30/360’);
put actual= days360=;
run;
SAS Statements
Results
put actual=;
6332
put days360=;
6240
Functions and CALL Routines
4
DATEJUL Function
See Also
Functions:
“YRDIF Function” on page 1179
References
Securities Industry Association. 1994. Standard Securities Calculation Methods Fixed Income Securities Formulas for Analytic Measures, Volume 2. New York:
Securities Industry Association.
DATE Function
Returns the current date as a SAS date value.
Category: Date and Time
TODAY
See: “TODAY Function” on page 1112
Alias:
Syntax
DATE()
DATEJUL Function
Converts a Julian date to a SAS date value.
Category: Date and Time
Syntax
DATEJUL(julian-date)
Arguments
julian-date
specifies a SAS numeric expression that represents a Julian date. A Julian date in
SAS is a date in the form yyddd or yyyyddd, where yy or yyyy is a two-digit or
four-digit integer that represents the year and ddd is the number of the day of the
year. The value of ddd must be between 1 and 365 (or 366 for a leap year).
Examples
The following SAS statements produce these results:
611
612
DATEPART Function
4
Chapter 4
SAS Statements
Xstart=datejul(94365);
put Xstart / Xstart date9.;
Xend=datejul(2001001);
put Xend / Xend date9.;
Results
12783
31DEC1994
14976
01JAN2001
See Also
Function:
“JULDATE Function” on page 832
DATEPART Function
Extracts the date from a SAS datetime value.
Category:
Date and Time
Syntax
DATEPART(datetime)
Arguments
datetime
specifies a SAS expression that represents a SAS datetime value.
Examples
The following SAS statements produce this result:
SAS Statements
Results
conn=’01feb94:8:45’dt;
servdate=datepart(conn);
put servdate worddate.;
February 1, 1994
See Also
Functions:
Functions and CALL Routines
4
DAY Function
“DATETIME Function” on page 613
“TIMEPART Function” on page 1109
DATETIME Function
Returns the current date and time of day as a SAS datetime value.
Category: Date and Time
Syntax
DATETIME()
Examples
This example returns a SAS value that represents the number of seconds between
January 1, 1960 and the current time:
when=datetime();
put when=;
See Also
Functions:
“DATE Function” on page 611
“TIME Function” on page 1108
DAY Function
Returns the day of the month from a SAS date value.
Category: Date and Time
Syntax
DAY(date)
Arguments
date
specifies a SAS expression that represents a SAS date value.
613
614
DCLOSE Function
4
Chapter 4
Details
The DAY function produces an integer from 1 to 31 that represents the day of the month.
Examples
The following SAS statements produce this result:
SAS Statements
Results
now=’05may97’d;
d=day(now);
put d;
5
See Also
Functions:
“MONTH Function” on page 897
“YEAR Function” on page 1176
DCLOSE Function
Closes a directory that was opened by the DOPEN function.
Category:
External Files
Syntax
DCLOSE(directory-id)
Argument
directory-id
is a numeric variable that specifies the identifier that was assigned when the
directory was opened by the DOPEN function.
Details
DCLOSE returns 0 if the operation was successful, ≠0 if it was not successful. The
DCLOSE function closes a directory that was previously opened by the DOPEN
function. DCLOSE also closes any open members.
Note: All directories or members opened within a DATA step are closed
automatically when the DATA step ends. 4
Functions and CALL Routines
4
DCLOSE Function
615
Examples
Example 1: Using DCLOSE to Close a Directory
This example opens the directory to
which the fileref MYDIR has previously been assigned, returns the number of members,
and then closes the directory:
%macro memnum(filrf,path);
%let rc=%sysfunc(filename(filrf,&path));
%if %sysfunc(fileref(&filrf)) = 0 %then
%do;
/* Open the directory. */
%let did=%sysfunc(dopen(&filrf));
%put did=&did;
/* Get the member count. */
%let memcount=%sysfunc(dnum(&did));
%put &memcount members in &filrf.;
/* Close the directory. */
%let rc= %sysfunc(dclose(&did));
%end;
%else %put Invalid FILEREF;
%mend;
%memnum(MYDIR,physical-filename)
Example 2: Using DCLOSE within a DATA Step
This example uses the DCLOSE
function within a DATA step:
%let filrf=MYDIR;
data _null_;
rc=filename("&filrf","physical-filename");
if fileref("&filrf") = 0 then
do;
/* Open the directory. */
did=dopen("&filrf");
/* Get the member count. */
memcount=dnum(did);
put memcount "members in &filrf";
/* Close the directory. */
rc=dclose(did);
end;
else put "Invalid FILEREF";
run;
See Also
Functions:
“DOPEN Function” on page 635
“FCLOSE Function” on page 654
“FOPEN Function” on page 731
“MOPEN Function” on page 897
616
DCREATE Function
4
Chapter 4
DCREATE Function
Returns the complete pathname of a new, external directory.
Category:
External Files
Syntax
DCREATE(directory-name<,parent-directory>)
Arguments
directory-name
is a character constant, variable, or expression that specifies the name of the
directory to create. This value cannot include a pathname.
parent-directory
is a character constant, variable, or expression that contains the complete pathname
of the directory in which to create the new directory. If you do not supply a value for
parent-directory, then the current directory is the parent directory.
Details
The DCREATE function enables you to create a directory in your operating
environment. If the directory cannot be created, then DCREATE returns an empty
string.
Examples
To create a new directory in the UNIX operating environment, using the name that is
stored in the variable DirectoryName, follow this form:
NewDirectory=dcreate(DirectoryName,’/local/u/abcdef/’);
To create a new directory in the Windows operating environment, using the name
that is stored in the variable DirectoryName, follow this form:
NewDirectory=dcreate(DirectoryName,’d:\testdir\’);
DEPDB Function
Returns the declining balance depreciation.
Category:
Financial
Syntax
DEPDB(p,v,y,r)
Functions and CALL Routines
4
DEPDBSL Function
617
Arguments
p
is numeric, the period for which the calculation is to be done. For noninteger p
arguments, the depreciation is prorated between the two consecutive time periods
that precede and follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
y
is numeric, the lifetime of the asset.
Range: y > 0
r
is numeric, the rate of depreciation that is expressed as a fraction.
Range: r ≥ 0
Details
The DEPDB function returns the depreciation by using the declining balance method,
which is given by
DEPDB (p
; v; y; r
) = DACCDB (
)
0 DACCDB ( 0 1
)
p; v; y; r
p
; v; y; r
The p and y arguments must be expressed by using the same units of time. A
double-declining balance is obtained by setting r equal to 2.
Examples
An asset has an initial value of $1,000 and a fifteen-year lifetime. Using a declining
balance rate of 200 percent, the depreciation of the value of the asset for the tenth year
can be expressed as
y10=depdb(10,1000,15,2);
The value returned is 36.78. The first and the third arguments are expressed in
years.
DEPDBSL Function
Returns the declining balance with conversion to a straight-line depreciation.
Category: Financial
Syntax
DEPDBSL(p,v,y,r)
618
4
DEPDBSL Function
Chapter 4
Arguments
p
is an integer, the period for which the calculation is to be done.
v
is numeric, the depreciable initial value of the asset.
y
is an integer, the lifetime of the asset.
Range:
y>0
r
is numeric, the rate of depreciation that is expressed as a fraction.
Range:
r≥0
Details
The DEPDBSL function returns the depreciation by using the declining balance method
with conversion to a straight-line depreciation, which is given by the following equation:
80
0
>
01
>
< 10
0 ) = > (10 )
t<py
>
: y0t
v
DEPDBSL (p
; v; y; r
r
y
0
t
r
v
y
(
r
y
p
p
< p
t
)
p >y
where
t
= int
y
0 r +1
y
and int( )denotes the integer part of a numeric argument.
The p and y arguments must be expressed by using the same units of time. The
declining balance that changes to a straight-line depreciation chooses for each time
period the method of depreciation (declining balance or straight-line on the remaining
balance) that gives the larger depreciation.
Examples
An asset has a depreciable initial value of $1,000 and a ten-year lifetime. Using a
declining balance rate of 150 percent, the depreciation of the value of the asset in the
fifth year can be expressed as
y5=depdbsl(5,1000,10,1.5);
The value 87.001041667 is returned. The first and the third arguments are
expressed in years.
Functions and CALL Routines
4
DEPSYD Function
619
DEPSL Function
Returns the straight-line depreciation.
Category: Financial
Syntax
DEPSL(p,v,y)
Arguments
p
is numeric, the period for which the calculation is to be done. For fractional p, the
depreciation is prorated between the two consecutive time periods that precede and
follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
y
is numeric, the lifetime of the asset.
Range: y > 0
Details
The DEPSL function returns the straight-line depreciation, which is given by
DEPSL (p
; v; y
) = DACCSL (
)
0 DACCSL ( 0 1 )
p; v; y
p
; v; y
The p and y arguments must be expressed by using the same units of time.
Examples
An asset, acquired on 01APR86, has a depreciable initial value of $1,000 and a
ten-year lifetime. The depreciation in the value of the asset for the year 1986 can be
expressed as
d=depsl(9/12,1000,10);
The value returned is 75.00. The first and the third arguments are expressed in
years.
DEPSYD Function
Returns the sum-of-years-digits depreciation.
620
DEPTAB Function
4
Category:
Chapter 4
Financial
Syntax
DEPSYD(p,v,y)
Arguments
p
is numeric, the period for which the calculation is to be done. For noninteger p
arguments, the depreciation is prorated between the two consecutive time periods
that precede and follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
y
is numeric, the lifetime of the asset in number of depreciation periods.
Range:
y>0
Details
The DEPSYD function returns the sum-of-years-digits depreciation, which is given by
DEPSYD (p
; v; y
) = DACCSYD (
)
0 DACCSYD ( 0 1 )
p; v; y
p
; v; y
The p and y arguments must be expressed by using the same units of time.
Examples
An asset, acquired on 01OCT86, has a depreciable initial value of $1,000 and a
five-year lifetime. The depreciations in the value of the asset for the years 1986 and
1987 can be expressed as
y1=depsyd(3/12,1000,5);
y2=depsyd(15/12,1000,5);
The values returned are 83.33 and 316.67, respectively. The first and the third
arguments are expressed in years.
DEPTAB Function
Returns the depreciation from specified tables.
Category:
Financial
Functions and CALL Routines
4
DEQUOTE Function
621
Syntax
DEPTAB(p,v,t1,...,tn)
Arguments
p
is numeric, the period for which the calculation is to be done. For noninteger p
arguments, the depreciation is prorated between the two consecutive time periods
that precede and follow the fractional period.
v
is numeric, the depreciable initial value of the asset.
t1,t2, . . . ,tn
are numeric, the fractions of depreciation for each time period with t1+t2+...tn 1.
Details
The DEPTAB function returns the depreciation by using specified tables. The formula is
DEPTAB (p;v;t1;t2;:::;tn) = DACCTAB (p;v;t1;t2;:::;tn)
0 DACCTAB (p 0 1;v;t1;t2;:::;tn)
t ;t2; . . . ;tk need to be specified with k=ceil(p).
For a given p, only the arguments 1
Examples
An asset has a depreciable initial value of $1,000 and a five-year lifetime. Using a
table of the annual depreciation rates of .15, .22, .21, .21, and .21 during the first,
second, third, fourth, and fifth years, respectively, the depreciation in the third year can
be expressed as
y3 = deptab (3; 1000;:15;:22;:21;:21;:21) ;
The value that is returned is 210.00. The fourth rate, .21, and the fifth rate, .21, can be
omitted because they are not needed in the calculation.
DEQUOTE Function
Removes matching quotation marks from a character string that begins with a quotation mark, and
deletes all characters to the right of the closing quotation mark.
Category: Character
Restriction:
“I18N Level 2” on page 305
622
DEQUOTE Function
4
Chapter 4
Syntax
DEQUOTE(string)
Arguments
string
specifies a character constant, variable, or expression.
Details
Length of Returned Variable
In a DATA step, if the DEQUOTE function returns a
value to a variable that has not been previously assigned a length, then that variable is
given the length of the argument.
The Basics
The value that is returned by the DEQUOTE function is determined as
follows:
3 If the first character of string is not a single or double quotation mark, DEQUOTE
returns string unchanged.
3 If the first two characters of string are both single quotation marks or both double
quotation marks, and the third character is not the same type of quotation mark,
then DEQUOTE returns a result with a length of zero.
3 If the first character of string is a single quotation mark, the DEQUOTE function
removes that single quotation mark from the result. DEQUOTE then scans string
from left to right, looking for more single quotation marks. Each pair of
consecutive, single quotation marks is reduced to one single quotation mark. The
first single quotation mark that does not have an ending quotation mark in string
is removed and all characters to the right of that quotation mark are also removed.
3 If the first character of string is a double quotation mark, the DEQUOTE function
removes that double quotation mark from the result. DEQUOTE then scans string
from left to right, looking for more double quotation marks. Each pair of
consecutive, double quotation marks is reduced to one double quotation mark. The
first double quotation mark that does not have an ending quotation mark in string
is removed and all characters to the right of that quotation mark are also removed.
Note: If string is a constant enclosed by quotation marks, those quotation marks are
not part of the value of string. Therefore, you do not need to use DEQUOTE to remove
the quotation marks that denote a constant. 4
Examples
This example demonstrates the use of DEQUOTE within a DATA step.
options pageno=1 nodate ls=80 ps=64;
data test;
input string $60.;
result = dequote(string);
datalines;
No quotation marks, no change
No "leading" quotation marks, no change
"Matching double quotation marks are removed"
’Matching single quotation marks are removed’
Functions and CALL Routines
4
DEVIANCE Function
"Paired ""quotation marks"" are reduced"
’Paired ’’ quotation marks ’’ are reduced’
"Single ’quotation marks’ inside ’’ double’’ quotation marks are unchanged"
’Double "quotation marks" inside ""single"" quotation marks are unchanged’
"No matching quotation mark, no problem
Don’t remove this apostrophe
"Text after the matching quotation mark" is "deleted"
;
proc print noobs;
title ’Input Strings and Output Results from DEQUOTE’;
run;
Output 4.45
Removing Matching Quotation Marks with the DEQUOTE Function
Input Strings and Output Results from DEQUOTE
string
No quotation marks, no change
No "leading" quotation marks, no change
"Matching double quotation marks are removed"
’Matching single quotation marks are removed’
"Paired ""quotation marks"" are reduced"
’Paired ’’ quotation marks ’’ are reduced’
"Single ’quotation marks’ inside ’’ double’’ quotation marks
’Double "quotation marks" inside ""single"" quotation marks
"No matching quotation mark, no problem
Don’t remove this apostrophe
"Text after the matching quotation mark" is "deleted"
result
No quotation marks, no change
No "leading" quotation marks, no change
Matching double quotation marks are removed
Matching single quotation marks are removed
Paired "quotation marks" are reduced
Paired ’ quotation marks ’ are reduced
Single ’quotation marks’ inside ’’ double’’ quotation marks
Double "quotation marks" inside ""single"" quotation marks
No matching quotation mark, no problem
Don’t remove this apostrophe
Text after the matching quotation mark
DEVIANCE Function
Returns the deviance based on a probability distribution.
Category: Mathematical
Syntax
DEVIANCE(distribution, variable, shape-parameters<," >)
1
623
624
DEVIANCE Function
4
Chapter 4
Arguments
distribution
is a character constant, variable, or expression that identifies the distribution. Valid
distributions are listed in the following table:
Distribution
Argument
Bernoulli
’BERNOULLI’ | ’BERN’
Binomial
’BINOMIAL’ | ’BINO’
Gamma
’GAMMA’
Inverse Gauss (Wald)
’IGAUSS’ | ’WALD’
Normal
’NORMAL’ | ’GAUSSIAN’
Poisson
’POISSON’ | ’POIS’
variable
is a numeric constant, variable, or expression.
shape-parameter
are one or more distribution-specific numeric parameters that characterize the shape
of the distribution.
"
is an optional numeric small value used for all of the distributions, except for the
normal distribution.
Details
The Bernoulli Distribution
DEVIANCE(’BERNOULLI’, variable, p<, " >)
where
variable
is a binary numeric random variable that has the value of 1 for success and 0 for
failure.
p
is a numeric probability of success with " ≤ p ≤ 1–".
"
is an optional positive numeric value that is used to bound p. Any value of p in the
interval 0 ≤ p ≤ " is replaced by ". Any value of p in the interval 1 – " ≤ p ≤ 1 is
replaced by 1 – ".
The DEVIANCE function returns the deviance from a Bernoulli distribution with a
probability of success p, where success is defined as a random variable value of 1. The
equation follows:
00
1
(
02 log (1 0 p) x = 0
DEVIANCE BERN ; variable; p; = 02 log (p)
:
0
x=1
otherwise
Functions and CALL Routines
4
DEVIANCE Function
625
The Binomial Distribution
DEVIANCE(’BINO’, variable, , n<, " >)
where
variable
is a numeric random variable that contains the number of successes.
Range: 0 ≤ variable ≤ 1
is a numeric mean parameter.
Range: n" ≤ ≤ n(1–")
n
is an integer number of Bernoulli trials parameter
Range: n ≥ 0
"
is an optional positive numeric value that is used to bound . Any value of in
the interval 0 ≤ ≤ n" is replaced by n". Any value of in the interval n(1 – ") ≤ ≤ n is replaced by n(1 – ").
The DEVIANCE function returns the deviance from a binomial distribution, with a
probability of success p, and a number of independent Bernoulli trials n. The following
equation describes the DEVIANCE function for the Binomial distribution, where x is
the random variable.
00
(
1
:
DEVIANCE BINO ; x ; ; n = 2 x log
0
x
+ (n 0 x ) log
:
n 0x
n 0
x <0
x n
x >n
0
The Gamma Distribution
DEVIANCE(’GAMMA’, variable,
<, " >)
where
variable
is a numeric random variable.
Range: variable ≥ "
"
is a numeric mean parameter.
Range: ≥"
is an optional positive numeric value that is used to bound variable and . Any
value of variable in the interval 0 ≤ variable ≤ " is replaced by ". Any value of in
the interval 0 ≤ ≤ " is replaced by ".
The DEVIANCE function returns the deviance from a gamma distribution with a
mean parameter . The following equation describes the DEVIANCE function for the
gamma distribution, where x is the random variable:
DEVIANCE
0
0
; ;
GAMMA x
0
1
=
:
2
0
x
log x 0
+ x
x
<0
; 626
4
DEVIANCE Function
Chapter 4
The Inverse Gauss (Wald) Distribution
DEVIANCE(’IGAUSS’ | ’WALD’, variable, <, " >)
where
variable
is a numeric random variable.
Range: variable ≥ "
is a numeric mean parameter.
Range: ≥"
"
is an optional positive numeric value that is used to bound variable and . Any
value of variable in the interval 0 ≤ variable ≤ " is replaced by ". Any value of in
the interval 0 ≤ ≤ " is replaced by ".
The DEVIANCE function returns the deviance from an inverse Gaussian distribution
with a mean parameter . The following equation describes the DEVIANCE function
for the inverse Gaussian distribution, where x is the random variable:
DEVIANCE
00
IGAUSS
0
; x; 1
=
:
(x
0)2
2 x
x
x
<0
; The Normal Distribution
DEVIANCE(’NORMAL’ | ’GAUSSIAN’, variable, )
where
variable
is a numeric random variable.
is a numeric mean parameter.
The DEVIANCE function returns the deviance from a normal distribution with a
mean parameter . The following equation describes the DEVIANCE function for the
normal distribution, where x is the random variable:
DEVIANCE
00
NORMAL0 ; x ; The Poisson Distribution
DEVIANCE(’POISSON’, variable, <, " >)
where
variable
is a numeric random variable.
Range: variable ≥ 0
is a numeric mean parameter.
Range: ≥"
1
= (x 0 )2
Functions and CALL Routines
"
4
DHMS Function
627
is an optional positive numeric value that is used to bound . Any value of in
the interval 0 ≤ ≤ " is replaced by ".
The DEVIANCE function returns the deviance from a Poisson distribution with a
mean parameter . The following equation describes the DEVIANCE function for the
Poisson distribution, where x is the random variable:
00
1
:
x <0
DEVIANCE POISSON ; x ; = 2 x log x 0 (x 0 ) x 0 ; 0
DHMS Function
Returns a SAS datetime value from date, hour, minute, and second values.
Category: Date and Time
Syntax
DHMS(date,hour,minute,second)
Arguments
date
specifies a SAS expression that represents a SAS date value.
hour
is numeric.
minute
is numeric.
second
is numeric.
Details
The DHMS function returns a numeric value that represents a SAS datetime value.
This numeric value can be either positive or negative.
Examples
The following SAS statements produce these results:
628
DIF Function
4
Chapter 4
SAS Statements
Results
dtid=dhms(’01jan03’d,15,30,15);
put dtid;
put dtid datetime.;
1357054215
01JAN03:15:30:15
dtid2=dhms(’01jan03’d,15,30,61);
put dtid2;
put dtid2 datetime.;
1357054261
01JAN03:15:31:01
dtid3=dhms(’01jan03’d,15,.5,15);
put dtid3;
put dtid3 datetime.;
1357052445
01JAN03:15:00:45
The following SAS statements show how to combine a SAS date value with a SAS
time value into a SAS datetime value. If you execute these statements on April 2, 2003
at the time of 15:05:02, it produces these results:
SAS Statements
Result
day=date();
time=time();
sasdt=dhms(day,0,0,time);
put sasdt datetime.;
02APR03:15:05:02
See Also
Function:
“HMS Function” on page 771
DIF Function
Returns differences between an argument and its nth lag.
Category:
Special
Syntax
DIF< n>(argument)
Arguments
n
specifies the number of lags.
argument
specifies a numeric constant, variable, or expression.
Functions and CALL Routines
4
DIGAMMA Function
Details
The DIF functions, DIF1, DIF2, ..., DIF100, return the first differences between the
argument and its nth lag. DIF1 can also be written as DIF. DIFn is defined as
DIFn(x)=x-LAGn(x).
For details on storing and returning values from the LAGn queue, see the LAG
function.
Comparisons
The function DIF2(X) is not equivalent to the second difference DIF(DIF(X)).
Examples
This example demonstrates the difference between the LAG and DIF functions.
data two;
input X @@;
Z=lag(x);
D=dif(x);
datalines;
1 2 6 4 7
;
proc print data=two;
run;
Results of the PROC PRINT step follow:
OBS
1
2
3
4
5
X
1
2
6
4
7
Z
.
1
2
6
4
See Also
Function:
“LAG Function” on page 835
DIGAMMA Function
Returns the value of the digamma function.
Category: Mathematical
Syntax
DIGAMMA(argument)
D
.
1
4
- 2
3
629
630
DIM Function
4
Chapter 4
Arguments
argument
specifies a numeric constant, variable, or expression.
Restriction: Nonpositive integers are invalid.
Details
The DIGAMMA function returns the ratio that is given by
9 (x) = 0 (x) =0 (x)
0
0( )
0 ()
where
: and 0 : denote the Gamma function and its derivative, respectively. For
argument>0, the DIGAMMA function is the derivative of the LGAMMA function.
Examples
SAS Statements
Results
x=digamma(1.0);
-0.577215665
DIM Function
Returns the number of elements in an array.
Category:
Array
Syntax
DIM<n>(array-name)
DIM(array-name,bound-n)
Arguments
n
specifies the dimension, in a multidimensional array, for which you want to know the
number of elements. If no n value is specified, the DIM function returns the number
of elements in the first dimension of the array.
array-name
specifies the name of an array that was previously defined in the same DATA step.
This argument cannot be a constant, variable, or expression.
bound-n
Functions and CALL Routines
4
DIM Function
631
is a numeric constant, variable, or expression that specifies the dimension, in a
multidimensional array, for which you want to know the number of elements. Use
bound-n only when n is not specified.
Details
The DIM function returns the number of elements in a one-dimensional array or the
number of elements in a specified dimension of a multidimensional array when the lower
bound of the dimension is 1. Use DIM in array processing to avoid changing the upper
bound of an iterative DO group each time you change the number of array elements.
Comparisons
3 DIM always returns a total count of the number of elements in an array dimension.
3 HBOUND returns the literal value of the upper bound of an array dimension.
Note: This distinction is important when the lower bound of an array dimension has
a value other than 1 and the upper bound has a value other than the total number of
elements in the array dimension. 4
Examples
Example 1: One-dimensional Array
In this example, DIM returns a value of 5.
Therefore, SAS repeats the statements in the DO loop five times.
array big{5} weight sex height state city;
do i=1 to dim(big);
more SAS statements;
end;
Example 2: Multidimensional Array
This example shows two ways of specifying the
DIM function for multidimensional arrays. Both methods return the same value for
DIM, as shown in the table that follows the SAS code example.
array mult{5,10,2} mult1-mult100;
Syntax
Alternative Syntax
Value
DIM(MULT)
DIM(MULT,1)
5
DIM2(MULT)
DIM(MULT,2)
10
DIM3(MULT)
DIM(MULT,3)
2
See Also
Functions:
“HBOUND Function” on page 770
“LBOUND Function” on page 842
Statements:
632
4
DINFO Function
Chapter 4
“ARRAY Statement” on page 1375
“Array Reference Statement” on page 1381
“Array Processing” in SAS Language Reference: Concepts
DINFO Function
Returns information about a directory.
External Files
Category:
See:
DINFO Function in the documentation for your operating environment.
Syntax
DINFO(directory-id,info-item)
Arguments
directory-id
is a numeric variable that specifies the identifier that was assigned when the
directory was opened by the DOPEN function.
info-item
is a character constant, variable, or expression that specifies the information item to
be retrieved. DINFO returns a blank if the value of the info-item argument is
invalid. The information available varies according to the operating environment.
Details
Use the DOPTNAME function to determine the names of the available
system-dependent directory information items. Use the DOPTNUM function to
determine the number of directory information items that are available.
Operating Environment Information: DINFO returns the value of a system-dependent
directory parameter. See the SAS documentation for your operating environment for
information about system-dependent directory parameters. 4
Examples
Example 1: Using DINFO to Return Information about a Directory
This example opens
the directory MYDIR, determines the number of directory information items available,
and retrieves the value of the last one:
%let
%let
%let
%let
%let
%let
%let
filrf=MYDIR;
rc=%sysfunc(filename(filrf,physical-name));
did=%sysfunc(dopen(&filrf));
numopts=%sysfunc(doptnum(&did));
foption=%sysfunc(doptname(&did,&numopts));
charval=%sysfunc(dinfo(&did,&foption));
rc=%sysfunc(dclose(&did));
Functions and CALL Routines
4
DIVIDE Function
633
Example 2: Using DINFO within a DATA Step
This example creates a data set that
contains the name and value of each directory information item:
data diropts;
length foption $ 12 charval $ 40;
keep foption charval;
rc=filename("mydir","physical-name");
did=dopen("mydir");
numopts=doptnum(did);
do i=1 to numopts;
foption=doptname(did,i);
charval=dinfo(did,foption);
output;
end;
run;
See Also
Functions:
“DOPEN Function” on page 635
“DOPTNAME Function” on page 637
“DOPTNUM Function” on page 638
“FINFO Function” on page 718
“FOPTNAME Function” on page 733
“FOPTNUM Function” on page 735
DIVIDE Function
Returns the result of a division that handles special missing values for ODS output.
Category: Arithmetic
Syntax
DIVIDE(x, y)
Arguments
x
is a numeric constant, variable, or expression.
y
is a numeric constant, variable, or expression.
Details
The DIVIDE function divides two numbers and returns a result that is compatible with
ODS conventions. The function handles special missing values for ODS output. The
following list shows how certain special missing values are interpreted in ODS:
634
DNUM Function
4
Chapter 4
3 .I as infinity
3 .M as minus infinity
3 ._ as a blank
The following table shows the values that are returned by the DIVIDE function,
based on the values of x and y.
Display 4.7 Values That Are Returned by the DIVIDE Function
x
positive
zero
zero
negative
.I
.M
.__
other
x/y or .I
0
x/y or .M
.I
.M
.__
x
.I
.
.M
.I
.M
.__
x
x/y or .M
0
x/y or .I
.M
.I
.__
x
.I
0
0
0
.
.
.__
x
.M
0
0
0
.
.
.__
x
.__
.__
.__
.__
.__
.__
.__
.__
y
y
y
y
y
.__
x
negative
y
positive
other
Note: The DIVIDE function never writes a note to the SAS log regarding missing
values, division by zero, or overflow. 4
Examples
The following example shows the results of using the DIVIDE function.
data _null_;
a = divide(1, 0);
put +3 a= ’(infinity)’;
b = divide(2, .I);
put +3 b=;
c = divide(.I, -1);
put +3 c= ’(minus infinity)’;
d = divide(constant(’big’), constant(’small’));
put +3 d= ’(infinity because of overflow)’;
run;
SAS writes the following output to the log:
a=I (infinity)
b=0
c=M (minus infinity)
d=I (infinity because of overflow)
DNUM Function
Returns the number of members in a directory.
Category:
External Files
Functions and CALL Routines
4
DOPEN Function
635
Syntax
DNUM(directory-id)
Argument
directory-id
is a numeric variable that specifies the identifier that was assigned when the
directory was opened by the DOPEN function.
Details
You can use DNUM to determine the highest possible member number that can be
passed to DREAD.
Examples
Example 1: Using DNUM to Return the Number of Members
This example opens the
directory MYDIR, determines the number of members, and closes the directory:
%let
%let
%let
%let
%let
filrf=MYDIR;
rc=%sysfunc(filename(filrf,physical-name));
did=%sysfunc(dopen(&filrf));
memcount=%sysfunc(dnum(&did));
rc=%sysfunc(dclose(&did));
Example 2: Using DNUM within a DATA Step
This example creates a DATA step that
returns the number of members in a directory called MYDIR:
data _null_;
rc=filename("mydir","physical-name");
did=dopen("mydir");
memcount=dnum(did);
rc=dclose(did);
run;
See Also
Functions:
“DOPEN Function” on page 635
“DREAD Function” on page 639
DOPEN Function
Opens a directory, and returns a directory identifier value.
Category: External Files
636
DOPEN Function
See:
4
Chapter 4
DOPEN Function in the documentation for your operating environment.
Syntax
DOPEN(fileref)
Argument
fileref
is a character constant, variable, or expression that specifies the fileref assigned to
the directory.
Restriction: You must associate a fileref with the directory before calling DOPEN.
Details
DOPEN opens a directory and returns a directory identifier value (a number greater
than 0) that is used to identify the open directory in other SAS external file access
functions. If the directory could not be opened, DOPEN returns 0, and you can obtain
the error message by calling the SYSMSG function. The directory to be opened must be
identified by a fileref. You can assign filerefs using the FILENAME statement or the
FILENAME external file access function. Under some operating environments, you can
also assign filerefs using system commands.
If you call the DOPEN function from a macro, then the result of the call is valid only
when the result is passed to functions in a macro. If you call the DOPEN function from
the DATA step, then the result is valid only when the result is passed to functions in
the same DATA step.
Operating Environment Information: The term directory that is used in the description
of this function and related SAS external file access functions refers to an aggregate
grouping of files managed by the operating environment. Different operating
environments identify such groupings with different names, such as directory,
subdirectory, folder, MACLIB, or partitioned data set. For details, see the SAS
documentation for your operating environment. 4
Examples
Example 1: Using DOPEN to Open a Directory
This example assigns the fileref MYDIR
to a directory. It uses DOPEN to open the directory. DOPTNUM determines the
number of system-dependent directory information items available, and DCLOSE closes
the directory:
%let
%let
%let
%let
%let
filrf=MYDIR;
rc=%sysfunc(filename(filrf,physical-name));
did=%sysfunc(dopen(&filrf));
infocnt=%sysfunc(doptnum(&did));
rc=%sysfunc(dclose(&did));
Example 2: Using DOPEN within a DATA Step
processing within a DATA step.
data _null_;
drop rc did;
rc=filename("mydir","physical-name");
This example opens a directory for
Functions and CALL Routines
4
DOPTNAME Function
637
did=dopen("mydir");
if did > 0 then do;
...more statements...
end;
else do;
msg=sysmsg();
put msg;
end;
run;
See Also
Functions:
“DCLOSE Function” on page 614
“DOPTNUM Function” on page 638
“FOPEN Function” on page 731
“MOPEN Function” on page 897
“SYSMSG Function” on page 1101
DOPTNAME Function
Returns directory attribute information.
Category: External Files
See:
DOPTNAME Function in the documentation for your operating environment.
Syntax
DOPTNAME(directory-id,nval)
Arguments
directory-id
is a numeric variable that specifies the identifier that was assigned when the
directory was opened by the DOPEN function.
nval
is a numeric constant, variable, or expression that specifies the sequence number of
the option.
Details
Operating Environment Information: The number, names, and nature of the directory
information varies between operating environments. The number of options that are
available for a directory varies depending on the operating environment. For details,
see the SAS documentation for your operating environment. 4
638
DOPTNUM Function
4
Chapter 4
Examples
Example 1: Using DOPTNAME to Retrieve Directory Attribute Information
This example
opens the directory with the fileref MYDIR, retrieves all system-dependent directory
information items, writes them to the SAS log, and closes the directory:
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf,physical-name));
%let did=%sysfunc(dopen(&filrf));
%let infocnt=%sysfunc(doptnum(&did));
%do j=1 %to &infocnt;
%let opt=%sysfunc(doptname(&did,&j));
%put Directory information=&opt;
%end;
%let rc=%sysfunc(dclose(&did));
Example 2: Using DOPTNAME within a DATA Step
This example creates a data set that
contains the name and value of each directory information item:
data diropts;
length optname $ 12 optval $ 40;
keep optname optval;
rc=filename("mydir","physical-name");
did=dopen("mydir");
numopts=doptnum(did);
do i=1 to numopts;
optname=doptname(did,i);
optval=dinfo(did,optname);
output;
end;
run;
See Also
Functions:
“DINFO Function” on page 632
“DOPEN Function” on page 635
“DOPTNUM Function” on page 638
DOPTNUM Function
Returns the number of information items that are available for a directory.
Category:
See:
External Files
DOPTNUM Function in the documentation for your operating environment.
Syntax
DOPTNUM(directory-id)
Functions and CALL Routines
4
DREAD Function
639
Argument
directory-id
is a numeric variable that specifies the identifier that was assigned when the
directory was opened by the DOPEN function.
Details
Operating Environment Information: The number, names, and nature of the directory
information varies between operating environments. The number of options that are
available for a directory varies depending on the operating environment. For details,
see the SAS documentation for your operating environment. 4
Examples
Example 1: Retrieving the Number of Information Items
This example retrieves the
number of system-dependent directory information items that are available for the
directory MYDIR and closes the directory:
%let
%let
%let
%let
%let
filrf=mydir;
rc=%sysfunc(filename(filrf,physical-name));
did=%sysfunc(dopen(&filrf));
infocnt=%sysfunc(doptnum(&did));
rc=%sysfunc(dclose(&did));
Example 2: Using DOPTNUM within a DATA Step
This example creates a data set that
retrieves the number of system-dependent information items that are available for the
MYDIR directory:
data _null_;
rc=filename("mydir","physical-name");
did=dopen("mydir");
infocnt=doptnum(did);
rc=dclose(did);
run;
See Also
Functions:
“DINFO Function” on page 632
“DOPEN Function” on page 635
“DOPTNAME Function” on page 637
DREAD Function
Returns the name of a directory member.
Category: External Files
640
DROPNOTE Function
4
Chapter 4
Syntax
DREAD(directory-id,nval)
Arguments
directory-id
is a numeric value that specifies the identifier that was assigned when the directory
was opened by the DOPEN function.
nval
is a numeric constant, variable, or expression that specifies the sequence number of
the member within the directory.
Details
DREAD returns a blank if an error occurs (such as when nval is out-of-range). Use
DNUM to determine the highest possible member number that can be passed to
DREAD.
Examples
This example opens the directory identified by the fileref MYDIR, retrieves the
number of members, and places the number in the variable MEMCOUNT. It then
retrieves the name of the last member, places the name in the variable LSTNAME , and
closes the directory:
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf,physical-name));
%let did=%sysfunc(dopen(&filrf));
%let lstname=;
%let memcount=%sysfunc(dnum(&did));
%if &memcount > 0 %then
%let lstname=%sysfunc(dread(&did,&memcount));
%let rc=%sysfunc(dclose(&did));
See Also
Functions:
“DNUM Function” on page 634
“DOPEN Function” on page 635
DROPNOTE Function
Deletes a note marker from a SAS data set or an external file.
Category:
SAS File I/O
Category:
External Files
Functions and CALL Routines
4
DSNAME Function
641
Syntax
DROPNOTE(data-set-id | file-id,note-id)
Arguments
data-set-id | file-id
is a numeric variable that specifies the identifier that was assigned when the data set
or external file was opened, generally by the OPEN function or the FOPEN function.
note-id
is a numeric value that specifies the identifier that was assigned by the NOTE or
FNOTE function.
Details
DROPNOTE deletes a marker set by NOTE or FNOTE. It returns a 0 if successful and
≠0 if not successful.
Examples
This example opens the SAS data set MYDATA, fetches the first observation, and
sets a note ID at the beginning of the data set. It uses POINT to return to the first
observation, and then uses DROPNOTE to delete the note ID:
%let dsid=%sysfunc(open(mydata,i));
%let rc=%sysfunc(fetch(&dsid));
%let noteid=%sysfunc(note(&dsid));
more macro statements
%let rc=%sysfunc(point(&dsid,&noteid));
%let rc=%sysfunc(fetch(&dsid));
%let rc=%sysfunc(dropnote(&dsid,&noteid));
See Also
Functions:
“FETCH Function” on page 658
“FNOTE Function” on page 729
“FOPEN Function” on page 731
“FPOINT Function” on page 736
“NOTE Function” on page 916
“OPEN Function” on page 939
“POINT Function” on page 966
DSNAME Function
Returns the SAS data set name that is associated with a data set identifier.
Category: SAS File I/O
642
DUR Function
4
Chapter 4
Syntax
DSNAME(data-set-id)
Arguments
data-set-id
is a numeric variable that specifies the data set identifier that is returned by the
OPEN function.
Details
DSNAME returns the data set name that is associated with a data set identifier, or a
blank if the data set identifier is not valid.
Examples
This example determines the name of the SAS data set that is associated with the
variable DSID and displays the name in the SAS log.
%let dsid=%sysfunc(open(sasuser.houses,i));
%put The current open data set
is %sysfunc(dsname(&dsid)).;
See Also
Function:
“OPEN Function” on page 939
DUR Function
Returns the modified duration for an enumerated cash flow.
Category:
Financial
Syntax
DUR(y,f,c(1), ... ,c(k))
Arguments
y
specifies the effective per-period yield-to-maturity, expressed as a fraction.
Range:
y>0
Functions and CALL Routines
4
f
specifies the frequency of cash flows per period.
Range:
f >0
c(1), ... ,c(k)
specifies a list of cash flows.
Details
The DUR function returns the value
C
K
X
=
k
c(k) k
(1+y) f
k=1 (P (1 + y ) f )
where
P
=
K
X
c (k )
k=1 (1 + y ) f
k
Examples
data _null_;
d=dur(1/20,1,.33,.44,.55,.49,.50,.22,.4,.8,.01,.36,.2,.4);
put d;
run;
The value that is returned is 5.28402.
DURP Function
Returns the modified duration for a periodic cash flow stream, such as a bond.
Category: Financial
Syntax
DURP(A,c,n,K,k0,y)
Arguments
A
specifies the par value.
Range:
A>0
DURP Function
643
644
DURP Function
4
Chapter 4
c
specifies the nominal per-period coupon rate, expressed as a fraction.
Range:
0
c<1
n
specifies the number of coupons per period.
Range:
n > 0 and is an integer
K
specifies the number of remaining coupons.
Range:
K > 0 and is an integer
k0
specifies the time from the present date to the first coupon date, expressed in terms
of the number of periods.
Range:
0 < k0
n1
y
specifies the nominal per-period yield-to-maturity, expressed as a fraction.
Range:
y>0
Details
The DURP function returns the value
PK
c(k) t
tk
y k
1 k =1 (1+ n )
0
D=
y1
n P 1+ n
where
0
tk = nk0 + k
1
c
c (k ) = n A f or k = 1; . . . ; K
1
0
c (K ) = 1 + nc A
01
and where
P =
K
X
c (k )
0
y 1tk
k=1 1 + n
Examples
data _null_;
d=durp(1000,1/100,4,14,.33/2,.10);
put d;
run;
The value returned is 3.26496.
Functions and CALL Routines
4
ERF Function
ENVLEN Function
Returns the length of an environment variable.
Category: SAS File I/O
Syntax
ENVLEN(argument)
Arguments
argument
specifies a character variable that is the name of an operating system environment
variable. Enclose argument in quotation marks.
Details
The ENVLEN function returns the length of the value of an operating system
environment variable. If the environment variable does not exist, SAS returns –1.
Operating Environment Information:
operating environment. 4
The value of argument is specific to your
Examples
The following examples are for illustration purposes only. The actual value that is
returned depends on where SAS is installed on your computer.
SAS Statements
Results
/* Windows operating environment */
x=envlen("PATH");
put x;
309
/* UNIX operating environment */
y=envlen("PATH");
put y;
365
z=envlen("THIS IS NOT DEFINED");
put z;
-1
ERF Function
Returns the value of the (normal) error function.
Category: Mathematical
645
646
ERFC Function
4
Chapter 4
Syntax
ERF(argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The ERF function returns the integral, given by
ERF (x ) = p2
Zx
e0z dz
2
0
Examples
You can use the ERF function to find the probability (p) that a normally distributed
random variable with mean 0 and standard deviation will take on a value less than X.
For example, the quantity that is given by the following statement is equivalent to
PROBNORM(X):
p=.5+.5*erf(x/sqrt(2));
SAS Statements
Results
y=erf(1.0);
0.8427007929
y=erf(-1.0);
-0.842700793
ERFC Function
Returns the value of the complementary (normal) error function.
Category:
Mathematical
Syntax
ERFC(argument)
Functions and CALL Routines
4
EUCLID Function
647
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The ERFC function returns the complement to the ERF function (that is, 1 −
ERF(argument)).
Examples
SAS Statements
Results
x=erfc(1.0);
0.1572992071
x=erfc(-1.0);
.8427007929
EUCLID Function
Returns the Euclidean norm of the non-missing arguments.
Category: Descriptive Statistics
Syntax
EUCLID(value-1 < ,value-2 ...>)
Arguments
value
specifies a numeric constant, variable, or expression.
Details
If all arguments have missing values, then the result is a missing value. Otherwise, the
result is the Euclidean norm of the non-missing values.
In the following example, x1; x2; :::; xn are the values of the non-missing arguments.
EUCLID (x1; x2; :::; xn) =
px1
2
+ x22 + ::: + xn2
Examples
Example 1: Calculating the Euclidean Norm of Non-missing Arguments
example returns the Euclidean norm of the non-missing arguments.
The following
648
EXIST Function
4
Chapter 4
data _null_;
x=euclid(.,3,0,.q,-4);
put x=;
run;
SAS writes the following output to the log:
x=5
Example 2: Calculating the Euclidean Norm When You Use a Variable List
The
following example uses a variable list to calculate the Euclidean norm.
data _null_;
x1 = 1;
x2 = 3;
x3 = 4;
x4 = 3;
x5 = 1;
x = euclid(of x1-x5);
put x=;
run;
SAS writes the following output to the log:
x=6
See Also
Functions:
“RMS Function” on page 1048
“LPNORM Function” on page 876
EXIST Function
Verifies the existence of a SAS library member.
Category:
SAS File I/O
Syntax
EXIST(member-name<,member-type<, generation>>)
Arguments
member-name
is a character constant, variable, or expression that specifies the SAS library
member. If member-name is blank or a null string, then EXIST uses the value of the
_LAST_ system variable as the member name.
member-type
Functions and CALL Routines
4
EXIST Function
649
is a character constant, variable, or expression that specifies the type of SAS library
member. A few common member types include ACCESS, CATALOG, DATA, and
VIEW. If you do not specify a member-type, then the member type DATA is assumed.
generation
is a numeric constant, variable, or expression that specifies the generation number of
the SAS data set whose existence you are checking. If member-type is not DATA,
generation is ignored.
Positive numbers are absolute references to a historical version by its generation
number. Negative numbers are relative references to a historical version in relation
to the base version, from the youngest predecessor to the oldest. For example, –1
refers to the youngest version or, one version back from the base version. Zero is
treated as a relative generation number.
Details
If you use a sequential library, then the results of the EXIST function are undefined. If
you do not use a sequential library, then EXIST returns 1 if the library member exists,
or 0 if member-name does not exist or member-type is invalid.
Use the CEXIST function to verify the existence of an entry in a catalog.
Examples
Example 1: Verifying the Existence of a Data Set
This example verifies the existence
of a data set. If the data set does not exist, then the example displays a message in the
log:
%let dsname=sasuser.houses;
%macro opends(name);
%if %sysfunc(exist(&name)) %then
%let dsid=%sysfunc(open(&name,i));
%else %put Data set &name does not exist.;
%mend opends;
%opends(&dsname);
Example 2: Verifying the Existence of a Data View
This example verifies the existence
of the SAS view TEST.MYVIEW. If the view does not exist, then the example displays a
message in the log:
data _null_;
dsname="test.myview";
if (exist(dsname,"VIEW")) then
dsid=open(dsname,"i");
else put dsname ’does not exist.’;
run;
Example 3: Determining If a Generation Data Set Exists
This example verifies the
existence of a generation data set by using positive generation numbers (absolute
reference):
data new(genmax=3);
x=1;
run;
data new;
x=99;
run;
650
EXIST Function
4
Chapter 4
data new;
x=100;
run;
data new;
x=101;
run;
data _null_;
test=exist(’new’,
put test=;
test=exist(’new’,
put test=;
test=exist(’new’,
put test=;
test=exist(’new’,
put test=;
run;
’DATA’, 4);
’DATA’, 3);
’DATA’, 2);
’DATA’, 1);
These lines are written to the SAS log:
test=1
test=1
test=1
test=0
You can change this example to verify the existence of the generation data set by
using negative numbers (relative reference):
data new2(genmax=3);
x=1;
run;
data new2;
x=99;
run;
data new2;
x=100;
run;
data new2;
x=101;
run;
data _null_;
test=exist(’new2’,
put test=;
test=exist(’new2’,
put test=;
test=exist(’new2’,
put test=;
test=exist(’new2’,
put test=;
test=exist(’new2’,
put test=;
run;
’DATA’, 0);
’DATA’, -1);
’DATA’, -2);
’DATA’, -3);
’DATA’, -4);
These lines are written to the SAS log:
test=1
test=1
test=1
Functions and CALL Routines
4
FACT Function
651
test=0
test=0
See Also
Functions:
“CEXIST Function” on page 556
“FEXIST Function” on page 660
“FILEEXIST Function” on page 663
EXP Function
Returns the value of the exponential function.
Category: Mathematical
Syntax
EXP(argument)
Arguments
argument
specifies a numeric constant, variable, or expression.
Details
The EXP function raises the constant e, which is approximately 2.71828, to the power
that is supplied by the argument. The result is limited by the maximum value of a
floating-point value on the computer.
Examples
SAS Statements
Results
x=exp(1.0);
2.7182818285
x=exp(0);
1
FACT Function
Computes a factorial.
652
FAPPEND Function
4
Chapter 4
Mathematical
Category:
Syntax
FACT(n)
Arguments
n
is a numeric constant, variable, or expression.
Details
The mathematical representation of the FACT function is given by the following
equation:
F ACT (n) = n !
with n ≥ 0.
If the expression cannot be computed, a missing value is returned. For moderately
large values, it is sometimes not possible to compute the FACT function.
Examples
SAS Statements
Results
x=fact(5);
120
See Also
Functions:
“COMB Function” on page 568
“PERM Function” on page 964
“LFACT Function” on page 861
FAPPEND Function
Appends the current record to the end of an external file.
Category:
External Files
Functions and CALL Routines
4
FAPPEND Function
653
Syntax
FAPPEND(file-id< ,cc>)
Arguments
file-id
is a numeric variable that specifies the identifier that was assigned when the file was
opened, generally by the FOPEN function.
cc
is a character constant, variable, or expression that specifies a carriage-control
character:
blank
indicates that the record starts a new line.
0
skips one blank line before this new line.
-
skips two blank lines before this new line.
1
specifies that the line starts a new page.
+
specifies that the line overstrikes a previous line.
P
specifies that the line is a computer prompt.
=
specifies that the line contains carriage control information.
all else
specifies that the line record starts a new line.
Details
FAPPEND adds the record that is currently contained in the File Data Buffer (FDB) to
the end of an external file. FAPPEND returns a 0 if the operation was successful and
≠0 if it was not successful.
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file. If the file is opened successfully, it moves data into the File Data Buffer, appends a
record, and then closes the file. Note that in a macro statement you do not enclose
character strings in quotation marks.
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf,a));
%if &fid > 0 %then
%do;
%let rc=%sysfunc(fput(&fid,
Data for the new record));
%let rc=%sysfunc(fappend(&fid));
%let rc=%sysfunc(fclose(&fid));
%end;
%else
%do;
/* unsuccessful open processing */
%end;
654
FCLOSE Function
4
Chapter 4
See Also
Functions:
“DOPEN Function” on page 635
“FCLOSE Function” on page 654
“FGET Function” on page 661
“FOPEN Function” on page 731
“FPUT Function” on page 739
“FWRITE Function” on page 746
“MOPEN Function” on page 897
FCLOSE Function
Closes an external file, directory, or directory member.
External Files
FCLOSE Function in the documentation for your operating environment.
Category:
See:
Syntax
FCLOSE(file-id)
Argument
file-id
is a numeric variable that specifies the identifier that was assigned when the file was
opened, generally by the FOPEN function.
Details
FCLOSE returns a 0 if the operation was successful and ≠0 if it was not successful. If
you open a file within a DATA step, it is closed automatically when the DATA step ends.
Operating Environment Information: In some operating environments you must close
the file with the FCLOSE function at the end of the DATA step. For more information,
see the SAS documentation for your operating environment. 4
Examples
This example assigns the fileref MYFILE to an external file, and attempts to open
the file. If the file is opened successfully, indicated by a positive value in the variable
FID, the program reads the first record, closes the file, and deassigns the fileref:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf));
Functions and CALL Routines
4
FCOL Function
655
%if &fid > 0 %then
%do;
%let rc=%sysfunc(fread(&fid));
%let rc=%sysfunc(fclose(&fid));
%end;
%else
%do;
%put %sysfunc(sysmsg());
%end;
%let rc=%sysfunc(filename(filrf));
See Also
Functions:
“DCLOSE Function” on page 614
“DOPEN Function” on page 635
“FOPEN Function” on page 731
“FREAD Function” on page 741
“MOPEN Function” on page 897
FCOL Function
Returns the current column position in the File Data Buffer (FDB).
Category: External Files
Syntax
FCOL(file-id)
Argument
file-id
is a numeric variable that specifies the identifier that was assigned when the file was
opened, generally by the FOPEN function.
Details
Use FCOL combined with FPOS to manipulate data in the File Data Buffer (FDB).
Examples
This example assigns the fileref MYFILE to an external file and attempts