SAS 9.1.3 Language Reference: Dictionary, Fifth

SAS 9.1.3 Language Reference: Dictionary, Fifth
SAS 9.1.3
Language Reference: Dictionary
®
Fifth Edition
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2006.
SAS ® 9.1.3 Language Reference: Dictionary, Fifth Edition. Cary, NC: SAS Institute Inc.
SAS® 9.1.3 Language Reference: Dictionary, Fifth Edition
Copyright © 2002–2006, SAS Institute Inc., Cary, NC, USA
ISBN 978-1-59994-098-4
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 printing, July 2006
2nd printing, August 2006
3rd printing, June 2007
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/pubs 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
4 Introduction to the SAS 9.1 Language Reference: Dictionary
The SAS Language Reference: Dictionary
Chapter 2
4 SAS Data Set Options
Definition of Data Set Options
Syntax
6
Using Data Set Options
6
Data Set Options by Category
Dictionary 9
Chapter 3
1
4 Formats
3
3
5
6
7
69
Definition of Formats 73
Syntax
74
Using Formats 74
Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms
Data Conversions and Encodings 79
Working with Packed Decimal and Zoned Decimal Data
80
Formats by Category
84
Dictionary 95
Chapter 4
4 Functions and CALL Routines
77
259
Definitions of Functions and CALL Routines
268
Syntax
269
Using Functions 271
Using Random-Number Functions and CALL Routines
273
Pattern Matching Using SAS Regular Expressions (RX) and Perl Regular Expressions
(PRX)
276
Base SAS Functions for Web Applications 286
Functions and CALL Routines by Category
286
Dictionary 310
References
1005
Chapter 5
4 Informats
1007
Definition of Informats 1010
Syntax
1010
Using Informats
1011
iv
Byte Ordering for Integer Binary Data on Big Endian and Little Endian
1013
Platforms
Working with Packed Decimal and Zoned Decimal Data
Informats by Category
1019
Dictionary
Chapter 6
1015
1026
4 SAS ARM Macros
1137
Definition of ARM Macros 1137
Using ARM Macros 1138
Defining User Metrics in ARM Macros 1145
Defining Correlators in ARM Macros 1146
Enabling ARM Macro Execution
Setting the Macro Environment
1147
1149
Using ARM Post-Processing Macros 1150
Troubleshooting Error Messages
1151
ARM Macros by Category
1152
Dictionary
Chapter 7
1153
4 Statements
1171
Definition of Statements
1174
DATA Step Statements
1174
Global Statements
Dictionary
1184
Chapter 8
1179
4 SAS System Options
1549
Definition of System Options
1553
Syntax
1553
Using SAS System Options
1553
Comparisons
1558
SAS System Options by Category
Dictionary
PART
2
1568
Appendixes
Appendix 1
1559
1763
4 DATA Step Object Attributes and Methods
The DATA Step Component Object Interface
1765
Dot Notation and DATA Step Component Objects
Dictionary
1767
Appendix 2
4 DATA Step Debugger
Introduction
1765
1766
1793
1794
Basic Usage 1795
Advanced Usage: Using the Macro Facility with the Debugger
Examples
1797
Commands
Dictionary
1809
1810
1796
v
4 SAS Utility Macro 1827
Appendix 4 4 Recommended Reading
1831
Appendix 3
Recommended Reading
Index
1833
1831
vi
vii
What’s New
Overview
New and enhanced features in Base SAS save you time, effort, and system resources
by providing faster processing and easier data access and management, more robust
analysis, and improved data presentation.
3 By using new SAS system options that enable threading and the use of multiple
CPUs, the following SAS procedures take advantage of multi-processing I/O:
SORT, SQL, MEANS, TABULATE, and REPORT.
3 The LIBNAME statement now supports secure access to SAS libraries on a
WebDAV server.
3 You can now use longer, easier-to-read names for user-created formats and
informats. See “Rules for Words and Names in the SAS Language” in SAS
Language Reference: Concepts.
3 Two pre-defined component objects for the DATA step enable you to quickly store,
search, and retrieve data based on lookup keys.
3 The FILENAME statement now supports directory services, multiple FTP service
commands, and Secure Sockets Layering (SSL).
3 The Application Response Measurement (ARM) system enables you to monitor the
availability and performance of transactions within and across diverse applications.
3 The Perl regular expression (PRX) functions and CALL routines use a modified
version of Perl as a pattern-matching language to enhance search-and-replace
operations on text.
3 New character functions search and compare character strings in addition to
concatenating character strings.
3 There are several new descriptive statistic functions and mathematical functions.
3 New formats, informats, and functions support international and local values for
money, datetime, and Unicode values. All data set options, formats, informats,
functions, and system options that relate to national language support are
documented in the new SAS National Language Support (NLS): User’s Guide.
3 A new ODS statement enables you to render multiple ODS output formats without
re-running a PROC or a DATA step. See the SAS Output Delivery System: User’s
Guide.
viii
What’s New
Note:
3 This section describes the features of Base SAS that are new or enhanced since
SAS 8.2.
3 z/OS is the successor to the OS/390 operating system. SAS 9.1 (and later) is
supported on both OS/390 and z/OS operating systems and, throughout this
document, any reference to z/OS also applies to OS/390, unless otherwise stated.
4
SAS System Features
Application Response Measurement (ARM)
Application Response Measurement (ARM) enables you to monitor the availability
and performance of transactions within and across diverse applications. The SAS ARM
interface consists of the implementation of the ARM API as ARM macros and an ARM
agent. An ARM agent generates calls to the ARM macros. New ARM system options
enable you to manage the ARM environment and to log internal SAS processing
transactions. See “Monitoring Performance Using Application Response Measurement
(ARM)” in SAS Language Reference: Concepts, “ARM Macros” on page xx, and “System
Options” on page xxi.
Cross-Environment Data Access (CEDA)
CEDA processes SAS files that were created on a different host. This is especially
useful if you have upgraded from a 32–bit platform to a 64–bit platform. Messages in
the SAS log notify you when CEDA is being used to process a SAS file. See “Processing
Data Using Cross-Environment Data Access (CEDA)” in SAS Language Reference:
Concepts.
DATA Step Object Attributes and Methods
SAS now provides two pre-defined component objects for use in a DATA step: the
hash object and the hash iterator object. These objects enable you to quickly and
efficiently store, search, and retrieve data based on lookup keys.
The DATA step component object interface enables you to create and manipulate
these component objects by using statements, attributes, and methods. You use the
DATA step object dot notation to access the component object’s attributes and methods.
The hash and hash iterator objects have one attribute, fourteen methods, and two
statements associated with them. See Appendix 1, “DATA Step Object Attributes and
Methods,” on page 1765.
Engines
3 The default BASE engine in SAS supports longer format and informat names,
thread-enabled procedures such as the SORT and SUMMARY procedures, and
more than 32,767 variables in a SAS data set.
3 The metadata LIBNAME engine enables you to use metadata in order to access
and augment data that is identified by the metadata. The metadata engine
What’s New ix
3
3
3
3
retrieves information about the target SAS data library from metadata objects in a
specified SAS Metadata Repository on the SAS Metadata Server. The metadata
engine provides a consistent method for accessing many data sources. That is,
SAS provides different engines that have different options, behavior, and tuning
requirements. By taking advantage of metadata, the necessary information that is
required to access data can be created in one central location so that applications
can use the metadata engine to access different sources of data, without having to
understand the differences and details of each SAS engine. See the SAS Metadata
LIBNAME Engine: User’s Guide.
The XML LIBNAME engine imports and exports a broader variety of XML
documents. The XMLMAP= option specifies a separate XML document that
contains specific XMLMap syntax. The XMLMap syntax, Version 1.2, tells the
XML engine how to interpret the XML markup in order to successfully import an
XML document. See the SAS Metadata LIBNAME Engine: User’s Guide.
The new SASEDOC LIBNAME engine enables you to bind output objects that
persist in an ODS document. See the SAS Output Delivery System: User’s Guide.
The new SAS Information Maps LIBNAME Engine provides a read-only way to
access data that is generated from a SAS Information Map and to bring it into a
SAS session. After you retrieve the data, you can run almost any SAS procedure
against it. See the Base SAS Guide to Information Maps.
The new character variable padding (CVP) engine expands character variable
lengths, using a specified expansion amount, so that character data truncation
does not occur when a file requires transcoding. Character data truncation can
occur when the number of bytes for a character in one encoding is different from
the number of bytes for the same character in another encoding, such as when a
single-byte character set (SBCS) is transcoded to a double-byte character set
(DBCS). See the SAS National Language Support (NLS): User’s Guide.
Indexing
When creating an index that requires sorting, SAS tries to sort the data by using the
thread-enabled sort. By dividing the sorting task into separately executable processes,
the time that is required to sort the data can be reduced. See the topic “Creating an
Index” in Understanding SAS Indexes in SAS Language Reference: Concepts.
Integrity Constraints
Variables in a SAS data file can now be part of both a primary key (general integrity
constraint) and a foreign key (referential integrity constraint). However, there are
restrictions when defining a primary key constraint and a foreign key constraint that
use the same variables. See the topic “Overlapping Primary Key and Foreign Key
Constraints” in Understanding Integrity Constraints in SAS Language Reference:
Concepts.
Restricted System Options
System administrators can restrict system options from being modified by a user.
You can use the RESTRICT option in the OPTIONS procedure to list the restricted
options. The implementation of restricted options is specific to the operating
environment. For details about how to restrict options, see the configuration guide for
your operating environment. For information about listing restricted options, see the
OPTIONS procedure in the Base SAS Procedures Guide.
x
What’s New
SAS Utility Macro
The SAS utility macro, %DS2CSV, is available now in Base SAS. This macro converts
SAS data sets to comma-separated values (CSV) files. Prior to SAS 9.1, this macro was
available only for SAS/IntrNet users.
Universal Unique Identifiers
A Universal Unique Identifier (UUID) is a 128-bit identifier that consists of date and
time information, and the IEEE node address of a host. UUIDs are useful when objects
such as rows or other components of a SAS application must be uniquely identified. For
more information, see “Universal Unique Identifiers” in SAS Language Reference:
Concepts.
SAS Language Elements
Descriptions of the new and enhanced language elements for national language
support can be found in “What’s New for SAS 9.0 and 9.1 National Language Support”
in the SAS National Language Support (NLS): User’s Guide.
Data Set Options
3 The following data set options are new:
OBSBUF=
determines the size of the view buffer for processing a DATA step view.
SPILL=
specifies whether to create a spill file for non-sequential processing of a DATA
step view.
3 The following data set options are enhanced:
BUFNO=
supports the same syntax as the BUFNO= system option in order to specify
the number of buffers to be allocated for processing a SAS data set.
BUFSIZE=
supports the same syntax as the BUFSIZE= system option in order to specify
the permanent buffer page size for an output SAS data set.
FIRSTOBS=
supports the same syntax as the FIRSTOBS= system option in order to
specify which observation SAS processes first.
OBS=
supports the same syntax as the OBS= system option in order to specify
when to stop processing observations.
Formats
3 The maximum length for character format names is increased to 31. The
maximum length for numeric format names is increased to 32.
What’s New xi
3 Several formats have been enhanced with default and range values.
3 The following formats are new:
MMYY
writes date values in the form mmM<yy>yy, where M is the separator and the
year is written in either 2 or 4 digits.
PERCENTN
produces percentages, using a minus sign for negative values.
YYMM
writes date values in the form <yy>yyMmm, where the year is written in either
2 or 4 digits and M is the separator.
YYQ
writes date values in the form <yy>yyQq, where the year is written in either 2
or 4 digits, Q is the separator, and q is the quarter of the year.
YYQR
writes date values in the form <yy>yyQqr, where the year is written in either 2
or 4 digits, Q is the separator, and qr is the quarter of the year expressed in
Roman numerals.
3 The PVALUE format now returns missing values that are specified by the
MISSING= system option.
Functions and CALL Routines
New functions and CALL routines include character, mathematical, descriptive
statistical, and special functions, and character-string matching functions that can use
PERL expressions.
3 The following character functions are new:
ANYALNUM
searches a character string for an alphanumeric character and returns the
first position at which it is found.
ANYALPHA
searches a character string for an alphabetic character and returns the first
position at which it is found.
ANYCNTRL
searches a character string for a control character and returns the first
position at which it is found.
ANYDIGIT
searches a character string for a digit and returns the first position at which
it is found.
ANYFIRST
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
searches a character string for a graphical character and returns the first
position at which it is found.
ANYLOWER
searches a character string for a lowercase letter and returns the first
position at which it is found.
xii What’s New
ANYNAME
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
searches a character string for a printable character and returns the first
position at which it is found.
ANYPUNCT
searches a character string for a punctuation character and returns the first
position at which it is found.
ANYSPACE
searches a character string for a white-space character (blank, horizontal tab,
vertical tab, carriage return, line feed, or form feed), and returns the first
position at which it is found.
ANYUPPER
searches a character string for an uppercase letter and returns the first
position at which it is found.
ANYXDIGIT
searches a character string for a hexadecimal character that represents a
digit and returns the first position at which that character is found.
CAT
concatenates character strings without removing leading or trailing blanks.
CATS
concatenates character strings and removes leading and trailing blanks.
CATT
concatenates character strings and removes trailing blanks only.
CATX
concatenates character strings, removes leading and trailing blanks, and
inserts separators.
CHOOSEC
returns a character value that represents the results of choosing from a list of
arguments.
CHOOSEN
returns a numeric value that represents the results of choosing from a list of
arguments.
COMPARE
returns the position of the left-most character by which two strings differ, or
returns 0 if there is no difference.
COMPGED
compares two strings by computing the generalized edit distance.
COMPLEV
compares two strings by computing the Levenshtein edit distance.
COUNT
counts the number of times that a specific substring of characters appears
within a character string that you specify.
What’s New xiii
COUNTC
counts the number of specific characters that either appear or do not appear
within a character string that you specify.
FIND
searches for a specific substring of characters within a character string that
you specify.
FINDC
searches for specific characters that either appear or do not appear within a
character string that you specify.
IFC
returns a character value that matches an expression.
IFN
returns a numeric value that matches an expression.
LENGTHC
returns the length of a character string, including trailing blanks.
LENGTHM
returns the amount of memory (in bytes) that is allocated for a character
string.
LENGTHN
returns the length of a non-blank character string, excluding trailing blanks,
and returns 0 for a blank character string.
NLITERAL
converts a character string that you specify to a SAS name literal (n-literal).
NOTALNUM
searches a character string for a non-alphanumeric character and returns the
first position at which it is found.
NOTALPHA
searches a character string for a non-alphabetic character and returns the
first position at which it is found.
NOTCNTRL
searches a character string for a character that is not a control character and
returns the first position at which it is found.
NOTDIGIT
searches a character string for any character that is not a digit and returns
the first position at which that character is found.
NOTFIRST
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
searches a character string for a non-graphical character and returns the first
position at which it is found.
NOTLOWER
searches a character string for a character that is not a lowercase letter and
returns the first position at which that character is found.
xiv
What’s New
NOTNAME
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
searches a character string for a non-printable character and returns the first
position at which it is found.
NOTPUNCT
searches a character string for a character that is not a punctuation
character and returns the first position at which it is found.
NOTSPACE
searches a character string for a character that is not a white-space character
(blank, horizontal tab, vertical tab, carriage return, line feed, or form feed),
and returns the first position at which it is found.
NOTUPPER
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
searches a character string for a character that is not a hexadecimal digit
and returns the first position at which that character is found.
NVALID
checks a character string for validity for use as a SAS variable name in a
SAS statement.
PROPCASE
converts all words in an argument to proper case.
PRXCHANGE
performs a pattern-matching replacement.
PRXPOSN
returns the value for a capture buffer.
SCANQ
th
returns the n word from a character expression and ignores delimiters that
are enclosed in quotation marks.
STRIP
returns a character string with all leading and trailing blanks removed.
SUBPAD
returns a substring that has a length you specify, using blank padding if
necessary.
SUBSTRN
returns a substring that allows a result with a length of 0.
What’s New xv
3 The following descriptive statistics functions are new:
GEOMEAN
returns the geometric mean.
GEOMEANZ
returns the geometric mean without fuzzing the values of the arguments that
are approximately 0.
HARMEAN
returns the harmonic mean.
HARMEANZ
returns the harmonic mean without fuzzing the values of the arguments that
are approximately 0.
IQR
returns the interquartile range.
LARGEST
th
returns the k largest non-missing value.
MAD
returns the median absolute deviation from the median.
MEDIAN
computes median values.
MODZ
returns the remainder from the division of the first argument by the second
argument; uses 0 fuzzing.
PCTL
computes percentiles.
RMS
returns the root mean square.
SMALLEST
th
returns the k smallest non-missing value.
3 The following External Files function is new:
DCREATE
creates an external directory.
3 The following macro functions are new:
SYMEXIST
indicates the existence of a macro variable.
SYMGLOBL
indicates whether a macro variable has global scope in the DATA step during
DATA step execution.
SYMLOCAL
indicates whether a macro variable has local scope in the DATA step during
DATA step execution.
3 The following mathematical functions are new:
BETA
returns the value of the beta function.
COALESCE
returns the first non-missing value from a list of numeric arguments.
xvi
What’s New
COALESCEC
returns the first non-missing value from a list of character arguments.
LOGBETA
returns the logarithm of the beta function.
3 The following probability function is new:
LOGCDF
returns the logarithm of a left cumulative distribution function.
3 The following quantile function is new:
QUANTILE
returns the quantile from the specified distribution.
3 The following special function is new:
UUIDGEN
returns the short or the binary form of a Universal Unique Identifier (UUID).
3 The following state and ZIP code function is new:
ZIPCITY
returns a city name and the two-character postal code that corresponds to a
ZIP code.
3 The following trigonometric function is new:
ATAN2
returns the arc tangent of two numeric variables.
3 The following truncation functions are new:
CEILZ
returns the smallest integer that is greater than or equal to the argument; uses
0 fuzzing.
FLOORZ
returns the largest integer that is less than or equal to the argument; uses 0
fuzzing.
INTZ
returns the integer portion of the argument; uses 0 fuzzing.
ROUND
rounds the first argument to the nearest multiple of the second argument, or to
the nearest integer when the second argument is omitted.
ROUNDE
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
rounds the first argument to the nearest multiple of the second argument; uses
0 fuzzing.
What’s New xvii
3 The following variable information functions are new:
VVALUE
returns the formatted value that is associated with the variable that you specify.
VVALUEX
returns the formatted value that is associated with the argument that you
specify.
3 Using Perl regular expression (PRX) functions and CALL routines is new. The
following PRX functions are new. For more information, see “Pattern Matching
Using SAS Regular Expressions (RX) and Perl Regular Expressions (PRX)” on
page 276.
PRXMATCH
searches for a pattern match and returns the position at which the pattern is
found.
PRXPAREN
returns the last bracket match for which there is a match in a pattern.
PRXPARSE
compiles a Perl regular expression that can be used for pattern-matching a
character value.
CALL PRXCHANGE
performs a pattern-matching substitution.
CALL PRXDEBUG
enables Perl regular expressions in a DATA step to send debug output to the
SAS log.
CALL PRXFREE
frees unneeded memory that was allocated for a Perl regular expression.
CALL PRXNEXT
returns the position and length of a substring that matches a pattern and
iterates over multiple matches within one string.
CALL PRXPOSN
returns the start position and length for a capture buffer.
CALL PRXSUBSTR
returns the position and length of a substring that matches a pattern.
3 The following CALL routines are new:
CALL ALLPERM
generates all permutations of the values of several variables.
CALL CATS
concatenates character strings and removes leading and trailing blanks.
CALL CATT
concatenates character strings and removes trailing blanks only.
CALL CATX
concatenates character strings, removes leading and trailing blanks, and
inserts separators.
CALL COMPCOST
sets the costs of operations for later use by the COMPGED function.
xviii What’s New
CALL LOGISTIC
returns the logistic value of each argument.
CALL MISSING
assigns a missing value to specified character or numeric variables.
CALL RANPERK
randomly permutes the values of the arguments and returns a permutation
of k out of n values.
CALL RANPERM
randomly permutes the values of the arguments.
CALL SCAN
returns the position and length of a given word in a character expression.
CALL SCANQ
returns the position and length of a given word in a character expression, and
ignores delimiters that are enclosed in quotation marks.
CALL SOFTMAX
returns the softmax value for each argument.
CALL STDIZE
standardizes the values of one or more variables.
CALL STREAMINIT
specifies a seed value to use for subsequent random number generation by
the RAND function.
CALL SYMPUTX
assigns a value to a macro variable and removes both leading and trailing
blanks.
CALL TANH
returns the hyperbolic tangent of each argument.
CALL VNEXT
returns the name, type, and length of a variable that is used in a DATA step.
What’s New xix
3 The following functions are enhanced:
COMPRESS
accepts a third optional argument that can modify the characters in the second
argument.
EXIST
accepts all SAS data library type members. A third optional argument enables
you to specify a generation data set number.
INDEXW
accepts a third optional argument that enables you to use delimiters for
inter-word boundaries.
accepts an argument that enables you to use a Perl regular expression.
SUBSTR (left of=)
assigns a length of 8 to an undeclared variable when the function is compiled.
Informats
3 The maximum length for character informat names is increased to 30. The
maximum length for numeric informat names is increased to 31.
3 The following informats are new:
ANYDTDTE
extracts date values from DATE, DATETIME, DDMMYY, JULIAN,
MMDDYY, MONYY, TIME, or YYQ informat values.
ANYDTDTM
extracts datetime values from DATE, DATETIME, DDMMYY, JULIAN,
MMDDYY, MONYY, TIME, or YYQ informat values.
ANYDTTME
extracts time values from DATE, DATETIME, DDMMYY, JULIAN,
MMDDYY, MONYY, TIME, or YYQ informat values.
STIMERw.
reads time values and determines whether the values are hours, minutes, or
seconds; reads the output of the STIMER system option.
xx
What’s New
ARM Macros
%ARMCONV, the new ARM macro, converts an ARM log that is created in SAS 9.0
and later, which uses a simple format, into the ARM log format that is used in SAS 8.2,
which is more detailed.
SAS Utility Macro
%DS2CSV, the new SAS utility macro, converts SAS data sets to comma-separated
values (CSV) files.
Statements
3 The following statements are new:
ODS Statements
control different features of the Output Delivery System. For more
information about these statements, see the SAS Output Delivery System:
User’s Guide.
LIBNAME Statement for WebDAV Server Access
associates a libref with a SAS library on a WebDAV server.
Beginning with SAS 9.1.3 Service Pack 4, the following option is new:
PROXY=
specifies the Uniform Resource Locator (URL) for the proxy server.
FILENAME, CLIPBAORD Access Method
enables you to read text data from and write text data to the clipboard on the
host machine.
FILENAME, WebDAV Access Method
Enables you to access remote files by using the WebDAV protocol.
DECLARE
declares a DATA step component object; creates an instance of and initializes
data for a DATA step component object.
_NEW_
creates an instance of a DATA step component object.
PUTLOG
writes a message to the SAS log.
3 The following statements are enhanced:
FILENAME, FTP Access Method
supports directory services and multiple FTP service commands.
FILENAME, URL Access Method
supports Secure Sockets Layering (SSL).
What’s New xxi
LIBNAME statement
the following options are new:
COMPRESS=
controls the compression of observations in output SAS data sets in a
SAS data library.
CVPBYTES=
specifies the number of bytes to use in order to expand character variable
lengths when processing a SAS data set that requires transcoding.
CVPENGINE=
specifies which engine to use in order to process character variable
lengths in a SAS data set that requires transcoding.
CVPMULTIPLIER=
specifies the multiplier value to use in order to expand character variable
lengths when processing a SAS data set that requires transcoding.
INENCODING=
overrides the encoding for input processing.
OUTENCODING=
overrides the encoding for output processing.
System Options
3 The following system options are new:
ARMAGENT=
specifies an ARM agent, which is an executable module that contains a
vendor’s implementation of the ARM API.
ARMLOC=
specifies the location of the ARM log.
ARMSUBSYS=
enables and disables the ARM subsystems that determine which internal
SAS processing transactions should be logged.
AUTHPROVIDERDOMAIN=
associates a domain suffix with an authentication provider.
AUTOSAVELOC=
specifies the location of the Program Editor autosave file.
BYSORTED
specifies whether observations in one or more data sets are sorted in
alphabetical or numerical order or are grouped in another logical order.
CMPLIB=
specifies one or more SAS catalogs that contain compiler subroutines that
should be included during program compilation.
CMPOPT=
specifies which type of code generation optimizations should be used in the
SAS language compiler.
CPUCOUNT=
specifies the number of processors that the thread-enabled applications
should assume are available for concurrent processing.
xxii What’s New
DMSLOGSIZE=
specifies the maximum number of rows that can be displayed in the Log
window in the SAS windowing environment.
DMSOUTSIZE=
specifies the maximum number of rows that can be displayed in the Output
window in the SAS windowing environment .
DMSSYNCHK
enables syntax checking for multiple steps in the SAS windowing
environment.
DTRESET
updates the date and the time in the SAS log and in the listing file.
EMAILAUTHPROTOCOL=
specifies the authentication protocol for SMTP e-mail.
EMAILID=
specifies the identity of the individual who is sending e-mail from within SAS.
EMAILPW=
specifies your e-mail login password.
ERRORBYABEND
specifies how SAS responds to BY-group error conditions.
FONTSLOC=
specifies the location that contains the SAS fonts that are loaded by a printer
to use with Universal Printing.
HELPENCMD
specifies whether SAS uses the English version or the translated version of
the keyword list for the command–line Help.
IBUFSIZE=
specifies the buffer page size for an index file.
LOGPARM=
controls when SAS log files are opened and closed and (in conjunction with
the LOG= system option) how they are named.
METAAUTORESOURCES=
identifies which resources should be assigned at SAS initialization.
METACONNECT=
identifies which named connection from the metadata user profiles should be
used as the default value for logging into the SAS Metadata Server.
METAENCRYPTALT=
specifies which type of encryption should be used when communicating with a
SAS Metadata Server.
METAENCRYPTLEVEL=
specifies what should be encrypted when communicating with a SAS
Metadata Server.
METAID=
identifies the current SAS version that is installed on the SAS Metadata
Server.
METAPASSWORD=
specifies the default password for the SAS Metadata Server.
What’s New
xxiii
METAPORT=
specifies the TCP port for the SAS Metadata Server.
METAPROFILE=
specifies which file contains the SAS Metadata Server user profiles.
METAPROTOCOL=
specifies which network protocol should be used for communicating with the
SAS Metadata Server.
METAREPOSITORY=
specifies which default SAS Metadata Repository should be used on the SAS
Metadata Server.
METASERVER=
specifies the address of the SAS Metadata Server.
METAUSER=
specifies the default user ID for logging on to the SAS Metadata Server.
PAGEBREAKINITIAL
begins the SAS log and listing files on a new page.
QUOTELENMAX
specifies that SAS write a warning to the SAS log about the maximum length
that can be used for strings that are enclosed in quotation marks.
SORTEQUALS
controls the order in which PROC SORT arranges observations that have
identical BY values in the output data set.
SYSPRINTFONT
specifies the font for the current default printer.
SYNTAXCHECK
specifies whether to validate SAS program syntax.
TERMSTMT=
specifies which SAS statements should be executed when the SAS session is
terminated.
TEXTURELOC=
specifies the location of textures and images that are used by ODS styles.
THREADS
specifies that SAS use threaded processing if it is available.
TOOLSMENU
specifies whether to include or to suppress the Tools menu in windows that
display SAS menus.
UUIDCOUNT
specifies the number of UUIDs that should be acquired each time the UUID
Generator Daemon is used.
UUIDGENHOST
identifies the host and the port for the UUID Generator Daemon.
UTILLOC=
specifies a set of file system locations in which applications can store utility
files.
xxiv
What’s New
VALIDFMTNAME=
specifies the length of format and informat names that can be used when
creating new SAS data sets and format catalogs.
VIEWMENU
specifies whether to include or to suppress the View menu in windows that
display menus.
V6CREATEUPDATE=
controls or monitors the creation of new, version 6 SAS data sets or the
updating of existing, version 6 SAS data sets.
3 The following system options have been enhanced:
CMPOPT=
specifies which type of code generation optimizations should be used in the
SAS language compiler.
SORTSIZE=
specifies the amount of memory that is available when using the SORT
procedure.
1
1
P A R T
Dictionary of Language Elements
Chapter
1. . . . . . . . . . Introduction to the SAS 9.1 Language Reference:
Dictionary 3
Chapter
2 . . . . . . . . . . SAS Data Set Options
Chapter
3 . . . . . . . . . . Formats
Chapter
4 . . . . . . . . . . Functions and CALL Routines
Chapter
5 . . . . . . . . . . Informats
Chapter
6 . . . . . . . . . . SAS ARM Macros
Chapter
7 . . . . . . . . . . Statements
Chapter
8 . . . . . . . . . . SAS System Options
5
69
1007
1137
1171
1549
259
2
3
CHAPTER
1
Introduction to the SAS 9.1
Language Reference: Dictionary
The SAS Language Reference: Dictionary
3
The SAS Language Reference: Dictionary
SAS Language Reference: Dictionary provides detailed reference information for the
major language elements of Base SAS software:
3 data set options
3
3
3
3
3
3
formats
functions and CALL routines
informats
Application Response Measurement (ARM) macros
statements
SAS system options.
It also includes the following four appendixes:
3
3
3
3
DATA Step Object Attributes and Methods
ENCODING= values for SAS commands and statements
DATA step debugger
Recommended reading.
For extensive conceptual information about the SAS System and the SAS language,
including the DATA step, see SAS Language Reference: Concepts.
4
5
CHAPTER
2
SAS Data Set Options
Definition of Data Set Options 6
Syntax 6
Using Data Set Options 6
Using Data Set Options with Input or Output SAS Data Sets
How Data Set Options Interact with System Options 7
Data Set Options by Category 7
Dictionary 9
ALTER= Data Set Option 9
BUFNO= Data Set Option 10
BUFSIZE= Data Set Option 12
CNTLLEV= Data Set Option 13
COMPRESS= Data Set Option 15
DLDMGACTION= Data Set Option 17
DROP= Data Set Option 18
ENCODING= Data Set Option 19
ENCRYPT= Data Set Option 19
FILECLOSE= Data Set Option 21
FIRSTOBS= Data Set Option 22
GENMAX= Data Set Option 23
GENNUM= Data Set Option 24
IDXNAME= Data Set Option 26
IDXWHERE= Data Set Option 27
IN= Data Set Option 29
INDEX= Data Set Option 30
KEEP= Data Set Option 31
LABEL= Data Set Option 32
OBS= Data Set Option 34
OBSBUF= Data Set Option 39
OUTREP= Data Set Option 41
POINTOBS= Data Set Option 43
PW= Data Set Option 44
PWREQ= Data Set Option 45
READ= Data Set Option 46
RENAME= Data Set Option 47
REPEMPTY= Data Set Option 49
REPLACE= Data Set Option 50
REUSE= Data Set Option 51
SORTEDBY= Data Set Option 52
SORTSEQ= Data Set Option 54
SPILL= Data Set Option 55
TOBSNO= Data Set Option 62
6
6
Definition of Data Set Options
4
Chapter 2
TYPE= Data Set Option 62
WHERE= Data Set Option 63
WHEREUP= Data Set Option 65
WRITE= Data Set Option 67
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 such operations as
3 renaming variables
3 selecting only the first or last n observations for processing
3 dropping variables from processing or from the output data set
3 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
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 may be
present.
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 life 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, SAS applies data set options to input data sets before it evaluates
programming statements or before it 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.
SAS Data Set Options
4
Data Set Options by Category
7
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, because SAS will
process KEEP= before the data set is read. The new names specified in RENAME= will
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 will be 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 5 observations will be
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;
Data Set Options by Category
Table 2.1
Category
SAS Data Set Option
Description
Data Set Control
“ALTER= Data Set
Option” on page 9
Assigns an alter password to a SAS file and enables
access to a password-protected SAS file
“BUFNO= Data Set
Option” on page 10
Specifies the number of buffers to be allocated for
processing a SAS data set
“BUFSIZE= Data Set
Option” on page 12
Specifies the permanent buffer page size for an output
SAS data set
“CNTLLEV= Data Set
Option” on page 13
Specifies the level of shared access to a SAS data set
“COMPRESS= Data Set
Option” on page 15
Controls the compression of observations in an output
SAS data set
8
Data Set Options by Category
Category
Miscellaneous
4
Chapter 2
SAS Data Set Option
Description
“DLDMGACTION= Data
Set Option” on page 17
Specifies what type of action to take when a SAS data set
in a SAS data library is detected as damaged
“ENCODING= Data Set
Option” on page 19
Overrides the encoding to use for reading or writing a
SAS data set
“ENCRYPT= Data Set
Option” on page 19
Encrypts SAS data files
“GENMAX= Data Set
Option” on page 23
Requests generations for a data set and specifies the
maximum number of versions
“GENNUM= Data Set
Option” on page 24
References a specific generation of a data set
“INDEX= Data Set Option”
on page 30
Defines indexes when a SAS data set is created
“LABEL= Data Set
Option” on page 32
Specifies a label for the SAS data set
“OBSBUF= Data Set
Option” on page 39
Determines the size of the view buffer for processing a
DATA step view
“OUTREP= Data Set
Option” on page 41
Specifies the data representation for the output SAS data
set
“PW= Data Set Option” on
page 44
Assigns a read, write, or alter password to a SAS file and
enables access to a password-protected SAS file
“PWREQ= Data Set
Option” on page 45
Controls the pop up of a requestor window for a data set
password
“READ= Data Set Option”
on page 46
Assigns a read password to a SAS file and enables access
to a read-protected SAS file
“REPEMPTY= Data Set
Option” on page 49
Controls replacement of like-named temporary or
permanent SAS data sets when the new one is empty
“REPLACE= Data Set
Option” on page 50
Controls replacement of like-named temporary or
permanent SAS data sets
“REUSE= Data Set
Option” on page 51
Specifies whether new observations are written to free
space in compressed SAS data sets
“SORTEDBY= Data Set
Option” on page 52
Specifies how the data set is currently sorted
“SORTSEQ= Data Set
Option” on page 54
Specifies a language-specific collation sequence for the
SORT procedure to use for the specified SAS data set
“SPILL= Data Set Option”
on page 55
Specifies whether to create a spill file for non-sequential
processing of a DATA step view
“TOBSNO= Data Set
Option” on page 62
Specifies the number of observations to be transmitted in
each multi-observation exchange with a SAS server
“TYPE= Data Set Option”
on page 62
Specifies the data set type for a specially structured SAS
data set
“WRITE= Data Set
Option” on page 67
Assigns a write password to a SAS file and enables
access to a write-protected SAS file
“FILECLOSE= Data Set
Option” on page 21
Specifies how a tape is positioned when a SAS file on the
tape is closed
SAS Data Set Options
4
ALTER= Data Set Option
Category
SAS Data Set Option
Description
Observation Control
“FIRSTOBS= Data Set
Option” on page 22
Specifies which observation SAS processes first
“IN= Data Set Option” on
page 29
Creates a variable that indicates whether the data set
contributed data to the current observation
“OBS= Data Set Option”
on page 34
Specifies when to stop processing observations
“POINTOBS= Data Set
Option” on page 43
Controls whether a compressed data set can be processed
with random access (by observation number) rather than
with sequential access only
“WHERE= Data Set
Option” on page 63
Selects observations that meet the specified condition
“WHEREUP= Data Set
Option” on page 65
Specifies whether to evaluate added observations and
modified observations against a WHERE expression
“IDXNAME= Data Set
Option” on page 26
Directs SAS to use a specific index to satisfy the
conditions of a WHERE expression
“IDXWHERE= Data Set
Option” on page 27
Overrides the SAS decision about whether to use an
index to satisfy the conditions of a WHERE expression
“DROP= Data Set Option”
on page 18
Excludes variables from processing or from output SAS
data sets
“KEEP= Data Set Option”
on page 31
Specifies variables for processing or for writing to output
SAS data sets
“RENAME= Data Set
Option” on page 47
Changes the name of a variable
User Control of SAS Index
Usage
Variable Control
Dictionary
ALTER= Data Set Option
Assigns an alter password to a SAS file and enables access to a password-protected SAS file
DATA step and PROC steps
Category: Data Set Control
See: ALTER= Data Set Option in the documentation for your operating environment.
Valid in:
Syntax
ALTER=alter-password
9
10
BUFNO= Data Set Option
4
Chapter 2
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 an alter-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 alter protected, 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
See Also
Data Set Options:
“ENCRYPT= Data Set Option” on page 19
“PW= Data Set Option” on page 44
“READ= Data Set Option” on page 46
“WRITE= Data Set Option” on page 67
“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
Valid in:
Category:
DATA step and PROC steps
Data Set Control
Syntax
BUFNO= n | nK | hexX | MIN | MAX
SAS Data Set Options
4
BUFNO= Data Set Option
11
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.
hex
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.
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.
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 12
System Options:
“BUFNO= System Option” on page 1594
Statements:
“SASFILE Statement” on page 1495
12
BUFSIZE= Data Set Option
4
Chapter 2
BUFSIZE= Data Set Option
Specifies the permanent buffer page size 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
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=.
4
SAS Data Set Options
4
CNTLLEV= Data Set Option
13
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
Comparisons
If the BUFSIZE= data set option is not specified, then the value of the BUFSIZE=
system option is used. If both are specified in the same SAS session, the BUFSIZE=
data set option overrides the value specified for the BUFSIZE= system option.
See Also
Data Set Options:
“BUFNO= Data Set Option” on page 10
System Options:
“BUFSIZE= System Option” on page 1596
CNTLLEV= Data Set Option
Specifies the level of shared access to a SAS data set
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.
14
CNTLLEV= Data Set Option
4
Chapter 2
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
normally 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
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;
SAS Data Set Options
4
COMPRESS= Data Set Option
15
COMPRESS= Data Set Option
Controls the compression of observations in an output SAS data set
Valid in:
DATA step and PROC steps
Category: Data Set Control
Restriction:
Use with output data sets only.
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.
ON
Tip: Use this compression algorithm for character data.
Alias:
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.
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.
Tip:
16
COMPRESS= Data Set Option
4
Chapter 2
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
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 on 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. For example, the following
statement results in a compressed data file that cannot be processed with random
access:
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.
SAS Data Set Options
4
DLDMGACTION= Data Set Option
17
See Also
Data Set Options:
“POINTOBS= Data Set Option” on page 43
“REUSE= Data Set Option” on page 51
Statements:
“LIBNAME Statement” on page 1381
System Options:
“COMPRESS= System Option” on page 1614
“REUSE= System Option” on page 1715
“Compressing Data Files” in SAS Language Reference: Concepts
DLDMGACTION= Data Set Option
Specifies what type of action to take when a SAS data set in a SAS data library is detected as
damaged
Valid in:
DATA step and PROC steps
Category: Data Set Control
Syntax
DLDMGACTION=FAIL | ABORT | REPAIR | 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 aborts the SAS session.
REPAIR
automatically repairs and rebuilds indexes and integrity constraints, unless the data
set 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.
PROMPT
displays a requestor window that asks you to select the FAIL, ABORT, or REPAIR
action.
18
4
DROP= Data Set Option
Chapter 2
DROP= Data Set Option
Excludes variables from processing or from output SAS data sets
Valid in:
DATA step and PROC steps
Category:
Variable Control
Syntax
DROP=variable(s)
Syntax Description
variable(s)
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;
SAS Data Set Options
4
ENCRYPT= Data Set Option
19
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;
See Also
Data Set Options:
“KEEP= Data Set Option” on page 31
Statements:
“DROP Statement” on page 1237
ENCODING= Data Set Option
Overrides the encoding to use for reading or writing a SAS data set
DATA step and PROC steps
Category: Data Set Control
Valid in:
See: The ENCODING data set option in SAS National Language Support (NLS): User’s
Guide
ENCRYPT= Data Set Option
Encrypts SAS data files
DATA step and PROC steps
Category: Data Set Control
Valid in:
Restriction:
Use with output data sets only.
Syntax
ENCRYPT=YES | NO
20
ENCRYPT= Data Set Option
4
Chapter 2
Syntax Description
YES
encrypts the file. The encryption method uses passwords. 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.
NO
does not encrypt the file.
CAUTION:
Record all passwords. If you forget the password, you cannot reset it without
assistance from SAS. The process is time-consuming and resource-intensive.
4
Details
3 You can use the ENCRYPT= option only when you are creating a SAS data file.
3 In order to copy an encrypted SAS data file, the output engine must support
encryption. Otherwise, the data file is not copied.
3 Encrypted files work only in Release 6.11 or in later releases of SAS.
3 You cannot encrypt SAS data views or stored programs because they contain no
data.
3 If the data file is encrypted, all associated indexes are also encrypted.
3 Encryption requires roughly the same amount of CPU resources as compression.
3 You cannot use PROC CPORT on encrypted SAS data files.
Example
This example creates an encrypted SAS data set:
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;
SAS Data Set Options
4
FILECLOSE= Data Set Option
21
See Also
Data Set Options:
“ALTER= Data Set Option” on page 9
“PW= Data Set Option” on page 44
“READ= Data Set Option” on page 46
“WRITE= Data Set Option” on page 67
“SAS Data File Encryption” in SAS Language Reference: Concepts
FILECLOSE= Data Set Option
Specifies how a tape is positioned when a SAS file on the tape is closed
Valid in:
DATA step and PROC steps
Category: Miscellaneous
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.
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 on using SAS data libraries that are stored on tape. 4
22
FIRSTOBS= Data Set Option
4
Chapter 2
FIRSTOBS= Data Set Option
Specifies which observation SAS processes first
DATA step and PROC steps
Category: Observation Control
Valid in:
Restriction:
Restriction:
Valid for input (read) processing only.
Cannot use with PROC SQL views.
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.
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.
SAS Data Set Options
4
GENMAX= Data Set Option
23
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 34
Statements:
“INFILE Statement” on page 1318
“WHERE Statement” on page 1529
System Options:
“FIRSTOBS= System Option” on page 1646
GENMAX= Data Set Option
Requests generations for a 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..
24
GENNUM= Data Set Option
4
Chapter 2
Details
You use GENMAX= to request generations for a new data set and to modify the number
of generations on 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.
Once generations of a data set is requested, its 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 on an existing data set, SAS deletes the
oldest version(s) 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;
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 24
“Generation Data Sets” in “SAS Data Sets” in SAS Language Reference: Concepts
GENNUM= Data Set Option
References a specific generation of a data set
DATA step and PROC steps
Data Set Control
Restriction: Use with input data sets only.
Valid in:
Category:
Syntax
GENNUM=integer
SAS Data Set Options
4
GENNUM= Data Set Option
25
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
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
will result 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;
26
IDXNAME= Data Set Option
4
Chapter 2
See Also
Data Set Option:
“GENMAX= Data Set Option” on page 23
“Understanding Generation Data Sets” in “SAS Data Files” in SAS Language
Reference: Concepts
“The DATASETS Procedure” in the Base SAS Procedures Guide
IDXNAME= Data Set Option
Directs SAS to use a specific index to satisfy the conditions of a WHERE expression
Valid in:
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
Syntax
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 if the specified index is the best one or
if 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 selects the one that it
determines will provide 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= will not process the request; that is, IDXNAME= will not allow you to
specify an index that would produce incorrect results.
SAS Data Set Options
4
IDXWHERE= Data Set Option
27
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 if 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;
See Also
Data Set Option:
“IDXWHERE= Data Set Option” on page 27
“Using an Index for WHERE Processing” in SAS Language Reference: Concepts.
“WHERE-Expression Processing” in SAS Language Reference: Concepts
IDXWHERE= Data Set Option
Overrides the SAS decision about whether to use an index to satisfy 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 IDXNAME= data set option
Valid in:
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.
28
IDXWHERE= Data Set Option
4
Chapter 2
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 may 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
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 examples 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 26
“Understanding SAS Indexes” in the “SAS Data Files” section in SAS Language
Reference: Concepts
“WHERE-Expression Processing” in SAS Language Reference: Concepts
SAS Data Set Options
4
IN= Data Set Option
29
IN= Data Set Option
Creates a 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
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 explicitly 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 if 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;
30
4
INDEX= Data Set Option
Chapter 2
See Also
Statements:
“BY Statement” on page 1199
“MERGE Statement” on page 1406
“MODIFY Statement” on page 1410
“SET Statement” on page 1505
“UPDATE Statement” on page 1524
“BY-Group Processing” in SAS Language Reference: Concepts
INDEX= Data Set Option
Defines indexes when a SAS data set is created
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Restriction:
Use with output data sets only.
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(s)
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.
SAS Data Set Options
4
KEEP= Data Set Option
31
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)));
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
Specifies variables for processing or for writing to output SAS data sets
DATA step and PROC steps
Category: Variable Control
Valid in:
Syntax
KEEP=variable(s)
Syntax Description
variable(s)
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
32
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 18
Statements:
“KEEP Statement” on page 1373
LABEL= Data Set Option
Specifies a label for the 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
33
Syntax Description
’label’
is 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)’);
34
OBS= Data Set Option
4
Chapter 2
See Also
Statements:
“ATTRIB Statement” on page 1195
“LABEL Statement” on page 1375
“MODIFY Statement” on page 1410
“The CONTENTS Procedure” in Base SAS Procedures Guide
“The DATASETS Procedure” in Base SAS Procedures Guide
OBS= Data Set Option
Specifies when to stop processing observations
Valid in:
DATA step and PROC steps
Observation Control
Category:
Restriction:
Use with input data sets only
Restriction:
Cannot use with PROC SQL views
Default
MAX
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.
SAS Data Set Options
4
OBS= Data Set Option
35
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
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, then 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, but this is only a coincidence.
data Ages;
input Name $ Age;
datalines;
Miguel 53
Brad 27
Willie 69
Marc 50
Sylvia 40
Arun 25
Gary 40
36
OBS= Data Set Option
4
Chapter 2
Becky 51
Alma 39
Tom 62
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
SAS Data Set Options
4
OBS= Data Set Option
37
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, then applies OBS= to the subset.
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.
38
OBS= Data Set Option
4
Chapter 2
First, here is PROC PRINT output of the modified file:
proc print data=Ages;
run;
Output 2.5
PROC PRINT Output Showing Observation 6 Deleted
The SAS System
Obs
Name
1
2
3
4
5
7
8
9
10
11
12
13
14
15
Miguel
Brad
Willie
Marc
Sylvia
Gary
Becky
Alma
Tom
Kris
Paul
Randy
Barbara
Virginia
1
Age
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
Miguel
Brad
Willie
Marc
Sylvia
Gary
Becky
Alma
Tom
Kris
Paul
Randy
2
Age
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.
SAS Data Set Options
4
OBSBUF= Data Set Option
39
proc print data=Ages (firstobs=2 obs=12);
run;
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 22
Statements:
“INFILE Statement” on page 1318
“WHERE Statement” on page 1529
System Options:
“OBS= System Option” on page 1694
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
40
OBSBUF= Data Set Option
4
Chapter 2
Syntax Description
n
specifies the number of observations that are read into the view buffer at a time.
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.
Tip: To determine the observation length, which is its size in bytes, use PROC
CONTENTS for the DATA step view.
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 will fit.
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 will fit 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
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
SAS Data Set Options
4
OUTREP= Data Set Option
41
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 55
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
Syntax
OUTREP=format
Syntax Description
format
specifies the data representation for the output SAS data set. Data representation is
the format in which data is represented in a computer architecture or in an operating
environment. For example, on an IBM PC, character data is represented by its
ASCII encoding and byte-swapped integers. Native data representation refers to an
environment for which the data representation is comparable to the CPU that is
accessing the file. For example, a file that is in Windows data representation is
native to the Windows operating environment.
Specifying this option enables you to create a SAS data set within the native
environment by using a foreign environment data representation. For example, in a
UNIX environment, you can create a SAS data set in Windows data representation.
42
OUTREP= Data Set Option
4
Chapter 2
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
Compaq Tru64 UNIX
ALPHA_VMS_32
ALPHA_VMS
OpenVMS Alpha on 32-bit platform
ALPHA_VMS_64
OpenVMS Alpha on 64-bit platform
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
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
Sun Solaris on 32-bit platform
SOLARIS_64
Sun Solaris on 64-bit platform
VAX_VMS
VAX VMS
WINDOWS_32
WINDOWS_64
WINDOWS
Microsoft Windows on 32-bit platform
Microsoft Windows 64-bit Edition
* It is recommended that you use the current values. The aliases are available for compatibility
only.
Details
By default, SAS creates a new SAS data set by using the native data representation of
the CPU that is running SAS. For example, when using a PC, SAS creates a SAS data
set that has ASCII characters and byte-swapped integers.
You can specify the OUTREP= data set option to create a new data set in a foreign
data representation. This option enables you to create a SAS data set within the native
environment by using a foreign data representation. For example, in a UNIX
environment, you can create a SAS data set in Windows data representation.
SAS Data Set Options
4
POINTOBS= Data Set Option
43
See Also
Statements:
OUTREP= option in “LIBNAME Statement” on page 1381
“Processing Data Using Cross-Environment Data Access (CEDA)” in SAS Language
Reference: Concepts
POINTOBS= Data Set Option
Controls whether a compressed data set can be processed with random access (by observation
number) rather than with sequential access only
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 may 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 roughly 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.
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 roughly 10% when creating a compressed data set and when
updating or adding observations to it by specifying POINTOBS=NO.
Tip:
44
PW= Data Set Option
4
Chapter 2
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 15
“REUSE= Data Set Option” on page 51
System Options:
“COMPRESS= System Option” on page 1614
“REUSE= System Option” on page 1715
PW= Data Set Option
Assigns a read, write, or alter password to a SAS file and enables access to a password-protected
SAS file
DATA step and PROC steps
Category: Data Set Control
Valid in:
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.
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 alter protected, 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
PWREQ= Data Set Option
45
See Also
Data Set Options:
“ALTER= Data Set Option” on page 9
“ENCRYPT= Data Set Option” on page 19
“READ= Data Set Option” on page 46
“WRITE= Data Set Option” on page 67
“Manipulating Passwords” in “The DATASETS Procedure” in Base SAS Procedures
Guide
“File Protection” in SAS Language Reference: Concepts
PWREQ= Data Set Option
Controls the pop up of a requestor window for a data set password
DATA and PROC steps
Category: Data Set Control
Valid in:
Syntax
PWREQ=YES|NO
Syntax Description
YES
specifies that a requestor window appear.
NO
prevents a requestor window from appearing. If a missing or invalid password is
entered, the data set is not opened and an error message is written to the SAS log.
Details
In an interactive SAS session, the PWREQ= option controls whether a requestor
window appears 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.
46
4
READ= Data Set Option
Chapter 2
See Also
Data Set Options:
“ALTER= Data Set Option” on page 9
“ENCRYPT= Data Set Option” on page 19
“PW= Data Set Option” on page 44
“READ= Data Set Option” on page 46
“WRITE= Data Set Option” on page 67
READ= Data Set Option
Assigns a read password to a SAS file and enables access to a read-protected SAS file
Valid in:
Category:
DATA step and PROC steps
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 read-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
47
See Also
Data Set Options:
“ALTER= Data Set Option” on page 9
“ENCRYPT= Data Set Option” on page 19
“PW= Data Set Option” on page 44
“WRITE= Data Set Option” on page 67
“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. The list of variables to rename
must be enclosed in parentheses:
proc print data=test(rename=(score1=score2));
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=. Thus, use old-name in the DROP= and KEEP= data set options. You
cannot drop and rename the same variable in the same statement.
48
4
RENAME= Data Set Option
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, for example, if two input data sets 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;
SAS Data Set Options
4
REPEMPTY= Data Set Option
49
See Also
Data Set Options:
“DROP= Data Set Option” on page 18
“KEEP= Data Set Option” on page 31
Statements:
“RENAME Statement” on page 1483
“The DATASETS Procedure” in Base SAS Procedures Guide
REPEMPTY= Data Set Option
Controls replacement of like-named temporary or permanent SAS data sets when the new one is
empty
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.
50
REPLACE= Data Set Option
4
Chapter 2
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 50
Statement Options:
REPEMPTY= in the LIBNAME statement on page 1385
System Options:
“REPLACE System Option” on page 1714
REPLACE= Data Set Option
Controls replacement of like-named temporary or permanent SAS data sets
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.
SAS Data Set Options
4
REUSE= Data Set Option
51
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.
See Also
System Options:
“REPLACE System Option” on page 1714
REUSE= Data Set Option
Specifies whether new observations are written to free 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.
52
SORTEDBY= Data Set Option
4
Chapter 2
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);
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 15
System Options:
“REUSE= System Option” on page 1715
SORTEDBY= Data Set Option
Specifies how the data set is currently sorted
Valid in:
DATA step and PROC steps
Category:
Data Set Control
Syntax
SORTEDBY=by-clause </ collate-name> | _NULL_
SAS Data Set Options
4
SORTEDBY= Data Set Option
53
Syntax Description
by-clause < / collate-name>
indicates how the data are 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 on collating
sequences, see the SAS documentation for your operating
environment. 4
_NULL_
removes any existing sort information.
Details
SAS uses the sort information in these ways:
3 For BY-group processing, if the data are already sorted by the BY variable, SAS
does not use the index, even if the data set is indexed on the BY variable.
3 If an index is selected for WHERE expression processing, the sort information for
that data set is changed to reflect the order that is specified by the index.
3 At the time you create an index, the sort information can make sorting of key
variables unnecessary.
3 PROC SQL uses the sort information to process queries more efficiently and to
determine whether an internal sort is necessary before performing a join.
3 PROC SORT checks for the sort information before it sorts a data set so that data
are not resorted unnecessarily.
3 PROC SORT sets the sort information whenever it does a sort.
If you update a SAS file in a way that affects the validity of the sort, the sort
information is removed. That is, if you change or add any values of the variables by
which the data set is sorted, the sort information is removed.
Comparisons
3 Use the CONTENTS statement in the DATASETS procedure to see how a data set
is sorted.
3 The SORTEDBY= option does not cause a data set to be sorted.
54
SORTSEQ= Data Set Option
4
Chapter 2
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 information is stored with it.
These statements create the data set ORDERS and record the sort information:
libname mylib ’SAS-data-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
SORTSEQ= Data Set Option
Specifies a language-specific collation sequence for the SORT procedure to use for the specified
SAS data set
DATA step and PROC steps
Category: Data Set Control
Valid in:
See:
Guide
The SORTSEQ data set option in SAS National Language Support (NLS): User’s
SAS Data Set Options
4
SPILL= Data Set Option
55
SPILL= Data Set Option
Specifies whether to create a spill file for non-sequential processing of a DATA step view
DATA step and PROC steps
Category: Data Set Control
Valid in:
Valid only for a DATA step view
YES
Restriction:
Default:
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.
Tip: 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.
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.
Tip: 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, then specify SPILL=NO.
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 will read 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.
56
SPILL= Data Set Option
4
Chapter 2
SPILL=YES creates a spill file the size of all the data that is
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
will be the 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, then 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, then 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;
SAS Data Set Options
4
SPILL= Data Set Option
Output 2.8 SAS Log Output
1
2
3
4
5
6
7
8
9
10
11
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
57
58
SPILL= Data Set Option
4
Chapter 2
Example 2: Using a Spill File for a Large Number of Small BY Groups
This example
creates a DATA step view that generates a large amount of random data, then 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;
SAS Data Set Options
4
SPILL= Data Set Option
Output 2.9 SAS Log Output
1
2
3
4
5
6
7
8
9
10
11
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
59
60
SPILL= Data Set Option
4
Chapter 2
Example 3: Using a Spill File with Two-Pass Access
This examples creates a DATA
step view that generates a large amount of random data, then 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, then 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 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;
SAS Data Set Options
Output 2.10
1
2
3
4
5
6
7
8
9
10
11
4
SPILL= Data Set Option
61
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
62
4
TOBSNO= Data Set Option
Chapter 2
See Also
Data Set Options:
“OBSBUF= Data Set Option” on page 39
TOBSNO= Data Set Option
Specifies the number of observations to be transmitted in each multi-observation exchange with a
SAS server
Valid in:
DATA step and PROC steps
Category:
Data Set Control
The TOBSNO= option is valid only for data sets that are accessed through a
SAS server via the REMOTE engine.
Restriction:
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
SAS Data Set Options
4
WHERE= Data Set Option
63
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.
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 SAS/STAT User’s Guide
“The CONTENTS Procedure” in Base SAS Procedures Guide
WHERE= Data Set Option
Selects observations that meet the specified condition
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>)
64
WHERE= Data Set Option
4
Chapter 2
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.
SAS Data Set Options
4
WHEREUP= Data Set Option
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 1529
“WHERE-Expression Processing” in SAS Language Reference: Concepts
WHEREUP= Data Set Option
Specifies whether to evaluate added observations and modified observations against a WHERE
expression
Valid in:
DATA step and PROC steps
Category: 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.
65
66
WHEREUP= Data Set Option
4
Chapter 2
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 63
SAS Data Set Options
4
WRITE= Data Set Option
67
WRITE= Data Set Option
Assigns a write password to a SAS file and enables access to a write-protected SAS file
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 write-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 9
“ENCRYPT= Data Set Option” on page 19
“PW= Data Set Option” on page 44
“READ= Data Set Option” on page 46
“Manipulating Passwords” in “The DATASETS Procedure” in Base SAS Procedures
Guide
68
69
CHAPTER
3
Formats
Definition of Formats 73
Syntax 74
Using Formats 74
Ways to Specify Formats 74
PUT Statement 75
PUT Function 75
%SYSFUNC 75
FORMAT Statement 75
ATTRIB Statement 76
Permanent versus Temporary Association 76
User-Defined Formats 76
Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms 77
Definitions 77
How Bytes are Ordered Differently 77
Writing Data Generated on Big Endian or Little Endian Platforms 78
Integer Binary Notation and Different Programming Languages 78
Data Conversions and Encodings 79
Working with Packed Decimal and Zoned Decimal Data 80
Definitions 80
Types of Data 80
Packed Decimal Data 80
Zoned Decimal Data 81
Packed Julian Dates 81
Platforms Supporting Packed Decimal and Zoned Decimal Data 81
Languages Supporting Packed Decimal and Zoned Decimal Data 81
Summary of Packed Decimal and Zoned Decimal Formats and Informats 82
Formats by Category 84
Dictionary 95
$ASCIIw. Format 95
$BIDIw. Format 96
$BINARYw. Format 97
$CHARw. Format 98
$CPTDWw. Format 99
$CPTWDw. Format 99
$EBCDICw. Format 99
$HEXw. Format 100
$KANJIw. Format 101
$KANJIXw. Format 101
$LOGVSw. Format 101
$LOGVSRw. Format 102
$MSGCASEw. Format 102
70
Contents
4
Chapter 3
$OCTALw. Format 103
$QUOTEw. Format 104
$REVERJw. Format 105
$REVERSw. Format 106
$UCS2Bw. Format 107
$UCS2BEw. Format 107
$UCS2Lw. Format 107
$UCS2LEw. Format 108
$UCS2Xw. Format 108
$UCS2XEw. Format 108
$UCS4Bw. Format 108
$UCS4BEw. Format 109
$UCS4Lw. Format 109
$UCS4LEw. Format 109
$UCS4Xw. Format 109
$UCS4XEw. Format 110
$UESCw. Format 110
$UESCEw. Format 110
$UNCRw. Format 110
$UNCREw. Format 111
$UPARENw. Format 111
$UPARENEw. Format 111
$UPCASEw. Format 111
$UTF8Xw. Format 112
$VARYINGw. Format 112
$VSLOGw. Format 114
$VSLOGRw. Format 114
$w. Format 115
BESTw. Format 116
BINARYw. Format 117
COMMAw.d Format 118
COMMAXw.d Format 119
Dw.s Format 120
DATEw. Format 121
DATEAMPMw.d Format 122
DATETIMEw.d Format 124
DAYw. Format 126
DDMMYYw. Format 126
DDMMYYxw. Format 128
DOLLARw.d Format 130
DOLLARXw.d Format 131
DOWNAMEw. Format 133
DTDATEw. Format 134
DTMONYYw. Format 135
DTWKDATXw. Format 136
DTYEARw. Format 137
DTYYQCw. Format 138
Ew. Format 139
EURDFDDw. Format 140
EURDFDEw. Format 140
EURDFDNw. Format 141
EURDFDTw.d Format 141
EURDFDWNw. Format 141
EURDFMNw. Format 141
Formats
EURDFMYw. Format 142
EURDFWDXw. Format 142
EURDFWKXw. Format 142
EURFRATSw.d Format 142
EURFRBEFw.d Format 143
EURFRCHFw.d Format 143
EURFRCZKw.d Format 143
EURFRDEMw.d Format 143
EURFRDKKw.d Format 144
EURFRESPw.d Format 144
EURFRFIMw.d Format 144
EURFRFRFw.d Format 144
EURFRGBPw.d Format 145
EURFRGRDw.d Format 145
EURFRHUFw.d Format 145
EURFRIEPw.d Format 145
EURFRITLw.d Format 146
EURFRLUFw.d Format 146
EURFRNLGw.d Format 146
EURFRNOKw.d Format 146
EURFRPLZw.d Format 147
EURFRPTEw.d Format 147
EURFRROLw.d Format 147
EURFRRURw.d Format 147
EURFRSEKw.d Format 148
EURFRSITw.d Format 148
EURFRTRLw.d Format 148
EURFRYUDw.d Format 148
EUROw.d Format 149
EUROXw.d Format 149
EURTOATSw.d Format 149
EURTOBEFw.d Format 149
EURTOCHFw.d Format 150
EURTOCZKw.d Format 150
EURTODEMw.d Format 150
EURTODKKw.d Format 150
EURTOESPw.d Format 151
EURTOFIMw.d Format 151
EURTOFRFw.d Format 151
EURTOGBPw.d Format 151
EURTOGRDw.d Format 152
EURTOHUFw.d Format 152
EURTOIEPw.d Format 152
EURTOITLw.d Format 152
EURTOLUFw.d Format 153
EURTONLGw.d Format 153
EURTONOKw.d Format 153
EURTOPLZw.d Format 153
EURTOPTEw.d Format 154
EURTOROLw.d Format 154
EURTORURw.d Format 154
EURTOSEKw.d Format 154
EURTOSITw.d Format 155
EURTOTRLw.d Format 155
4
Contents
71
72
Contents
4
Chapter 3
EURTOYUDw.d Format 155
FLOATw.d Format 155
FRACTw. Format 157
HDATEw. Format 158
HEBDATEw. Format 158
HEXw. Format 158
HHMMw.d Format 159
HOURw.d Format 161
IBw.d Format 162
IBRw.d Format 163
IEEEw.d Format 165
JULDAYw. Format 166
JULIANw. Format 167
MINGUOw. Format 168
MMDDYYw. Format 168
MMDDYYxw. Format 170
MMSSw.d Format 172
MMYYw. Format 173
MMYYxw. Format 174
MONNAMEw. Format 176
MONTHw. Format 177
MONYYw. Format 178
NEGPARENw.d Format 179
NENGOw. Format 181
NLDATEw. Format 181
NLDATEMNw. Format 181
NLDATEWw. Format 181
NLDATEWNw. Format 182
NLDATMw. Format 182
NLDATMAPw. Format 182
NLDATMTMw. Format 182
NLDATMWw. Format 183
NLMNYw.d Format 183
NLMNYIw.d Format 183
NLNUMw.d Format 183
NLNUMIw.d Format 184
NLPCTw.d Format 184
NLPCTIw.d Format 184
NLTIMAPw. Format 184
NLTIMEw. Format 185
NUMXw.d Format 185
OCTALw. Format 186
PDw.d Format 187
PDJULGw. Format 188
PDJULIw. Format 190
PERCENTw.d Format 192
PERCENTNw.d Format 193
PIBw.d Format 194
PIBRw.d Format 196
PKw.d Format 198
PVALUEw.d Format 199
QTRw. Format 200
QTRRw. Format 201
RBw.d Format 202
Formats
4
Definition of Formats
ROMANw. Format 204
S370FFw.d Format 204
S370FIBw.d Format 206
S370FIBUw.d Format 207
S370FPDw.d Format 209
S370FPDUw.d Format 210
S370FPIBw.d Format 211
S370FRBw.d Format 213
S370FZDw.d Format 214
S370FZDLw.d Format 216
S370FZDSw.d Format 217
S370FZDTw.d Format 218
S370FZDUw.d Format 219
SSNw. Format 220
TIMEw.d Format 221
TIMEAMPMw.d Format 223
TODw.d Format 224
VAXRBw.d Format 226
w.d Format 227
WEEKDATEw. Format 228
WEEKDATXw. Format 230
WEEKDAYw. Format 232
WEEKUw. Format 233
WEEKVw. Format 233
WEEKWw. Format 233
WORDDATEw. Format 234
WORDDATXw. Format 235
WORDFw. Format 237
WORDSw. Format 238
YEARw. Format 239
YENw.d Format 240
YYMMw. Format 240
YYMMxw. Format 242
YYMMDDw. Format 244
YYMMDDxw. Format 246
YYMONw. Format 249
YYQw. Format 250
YYQxw. Format 251
YYQRw. Format 253
YYQRxw. Format 254
Zw.d Format 256
ZDw.d Format 257
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.
73
74
Syntax
4
Chapter 3
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 on user-defined formats, see “The FORMAT Procedure” in Base SAS
Procedures Guide.
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, regardless of how many decimal
places are in the data. 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. This includes 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 is not
feasible, 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 fifteenth decimal place might not be accurate.
Using Formats
Ways to Specify Formats
You can use formats in the following ways:
3 in a PUT statement
3 with the PUT, PUTC, or PUTN functions
Formats
4
Ways to Specify Formats
75
3 with the %SYSFUNC macro function
3 in a FORMAT statement in a DATA step or a PROC step
3 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 DOLLAR.
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
See “PUT Statement” on page 1446 for more information.
PUT Function
The PUT function writes a numeric variable, a character variable, or a constant with
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 creates a character variable named CHAR that has a value of 0F.
The PUT function is useful for converting a numeric value to a character value. See
“PUT Function” on page 803 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 1301 for more information.
76
Permanent versus Temporary Association
4
Chapter 3
Note: Formats that you specify in a PUT statement behave differently from those
that you associate with a variable in a FORMAT statement. The major difference is that
formats that are specified in the PUT statement preserve leading blanks. If you assign
formats with a FORMAT statement prior to a PUT statement, all leading blanks are
trimmed. The result is the same as if you used the colon (:) format modifier. For details
about using the colon (:) format modifier, see “PUT Statement, List” on page 1470. 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;
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 1195 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 on 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:
Formats
4
How Bytes are Ordered Differently
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.
77
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.
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. The following platforms are considered little endian: OpenVMS Alpha, Digital
UNIX, Intel ABI, 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.
78
Writing Data Generated on Big Endian or Little Endian Platforms
4
Chapter 3
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 Sign? 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
Data created
for…
Data written
by…
Sign?
Format
big endian
big endian
yes
IB or S370FIB
big endian
big endian
no
PIB, S370FPIB,
S370FIBU
big endian
little endian
yes
S370FIB
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
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)
Formats
4
Data Conversions and Encodings
Language
2 Bytes
4 Bytes
IBM assembler
H
F
C
short
long
79
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 24hex. The Danish EBCDIC encoding for the dollar
symbol $ is 67hex. 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 hex
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.
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 on SAS features designed to handle data conversions from
different encodings or operating environments, see SAS National Language Support
(NLS): User’s Guide.
80
Working with Packed Decimal and Zoned Decimal Data
4
Chapter 3
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 digit. For
example, the value 15 is stored in two nibbles, using the hexadecimal digits 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
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.
Formats
4
Languages Supporting Packed Decimal and Zoned Decimal Data
81
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 digit. 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 different languages support packed decimal and zoned decimal data. The
following table shows how COBOL picture clauses correspond to SAS formats and
informats.
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.
82
Summary of Packed Decimal and Zoned Decimal Formats and Informats
4
Chapter 3
IBM VS COBOL II clauses
Corresponding S370Fxxx
formats/informats
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
ZD
Zoned decimal
ZD
Local zoned decimal
none
Zoned decimal
ZDB
Translates EBCDIC blank
(hex 40) to EBCDIC zero (hex
F0), then corresponds to the
informat as zoned decimal
none
Zoned decimal
ZDV
Non-IBM zoned decimal
representation
Formats
4
Summary of Packed Decimal and Zoned Decimal Formats and Informats
Format
Type of data
representation
Corresponding
informat
Comments
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 hex C0 (positive)
or D0 (negative) in format
S370FZDS
Zoned decimal
S370FZDS
Leading sign of - (hex 60) or +
(hex 4E)
S370FZDT
Zoned decimal
S370FZDT
Trailing sign of - (hex 60) or +
(hex 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
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
83
84
Formats by Category
4
Chapter 3
Formats by Category
There are six categories of formats in SAS:
Category
Description
BIDI text handling
instructs SAS to write bidirectional data values from data variables
Character
instructs SAS to write character data values from character variables.
Currency Conversion
instructs SAS to convert an amount from one currency to another currency.
DBCS
instructs SAS to handle various Asian languages.
Date and Time
instructs SAS to write data values from variables that represent dates,
times, and datetimes.
Hebrew text handling
instructs SAS to write Hebrew data from data variables
Numeric
instructs SAS to write numeric data values from numeric variables.
User-Defined
instructs SAS to write data values by using a format that is created with
PROC FORMAT.
Storing user-defined formats is an important consideration if you associate these
formats with variables in permanent SAS data sets, especially those shared with other
users. For information on 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.3 Categories and Descriptions of Formats
Category
Formats
Description
BIDI text handling
“$LOGVSw. Format” on
page 101
Writes a character string in left-to-right logical order to
visual order
“$LOGVSRw. Format” on
page 102
Writes a character string in right-to-left logical order to
visual order
“$VSLOGw. Format” on
page 114
Writes a character string in visual order to left-to-right
logical order
“$VSLOGRw. Format” on
page 114
Writes a character string in visual order to right-to-left
logical order
“$ASCIIw. Format” on
page 95
Converts native format character data to ASCII
representation
“$BIDIw. Format” on page
96
Convert a Logical ordered string to a Visually ordered
string, and vice versa by reversing the order of Hebrew
characters while preserving the order of Latin characters
and numbers
“$BINARYw. Format” on
page 97
Converts character data to binary representation
“$CHARw. Format” on
page 98
Writes standard character data
Character
Formats
Category
4
Formats by Category
Formats
Description
“$EBCDICw. Format” on
page 99
Converts native format character data to EBCDIC
representation
“$HEXw. Format” on page
100
Converts character data to hexadecimal representation
“$MSGCASEw. Format”
on page 102
Writes character data in uppercase when the MSGCASE
system option is in effect
“$OCTALw. Format” on
page 103
Converts character data to octal representation
“$QUOTEw. Format” on
page 104
Writes data values that are enclosed in double quotation
marks
“$REVERJw. Format” on
page 105
Writes character data in reverse order and preserves
blanks
“$REVERSw. Format” on
page 106
Writes character data in reverse order and left aligns
“$UCS2Bw. Format” on
page 107
Writes a character string in big-endian, 16-bit, universal
character set code in 2 octets (UCS2), Unicode encoding
“$UCS2BEw. Format” on
page 107
Writes a big-endian, 16–bit, universal character set code
in 2 octets (UCS2) character string in the encoding of the
current SAS session
“$UCS2Lw. Format” on
page 107
Writes data in little-endian, 16-bit, universal character
set code in 2 octets (UCS2), Unicode encoding
“$UCS2LEw. Format” on
page 108
Writes a character string that is encoded in little-endian,
16-bit, universal character set code in 2 octets (UCS2), in
the encoding of the current SAS session
“$UCS2Xw. Format” on
page 108
Writes a character string in native-endian, 16-bit,
universal character set code in 2 octets (UCS2) Unicode
encoding
“$UCS2XEw. Format” on
page 108
Writes a native-endian, 16-bit, universal character set
code in 2 octets (UCS2) character string in the encoding
of the current SAS session
“$UCS4Bw. Format” on
page 108
Writes a character string in big-endian, 32-bit, universal
character set code in 4 octets (UCS4), Unicode encoding
“$UCS4BEw. Format” on
page 109
Writes a big-endian, 32-bit, universal character set code
in 4 octets (UCS4), character string in the encoding of
the current SAS session
“$UCS4Lw. Format” on
page 109
Writes a character string in little-endian, 32-bit,
universal character set code in 4 octets, (UCS4), Unicode
encoding
“$UCS4LEw. Format” on
page 109
Writes a little-endian, 32-bit, universal character set
code in 4 octets (UCS4) character string in the encoding
of the current SAS session
“$UCS4Xw. Format” on
page 109
Writes a character string in native-endian, 32-bit,
universal character set code in 4 octets (UCS4), Unicode
encoding
85
86
Formats by Category
Category
Currency Conversion
4
Chapter 3
Formats
Description
“$UCS4XEw. Format” on
page 110
Writes a native-endian, 32-bit, universal character set
code in 4 octets (UCS4) character string in the encoding
of the current SAS session
“$UESCw. Format” on
page 110
Writes a character string that is encoded in the current
SAS session in Unicode escape (UESC) representation
“$UESCEw. Format” on
page 110
Writes a Unicode escape (UESC) representation character
string in the encoding of the current SAS session
“$UNCRw. Format” on
page 110
Writes a character string that is encoded in the current
SAS session in numeric character representation (NCR)
“$UNCREw. Format” on
page 111
Writes the numeric character representation (NCR)
character string in the encoding of the current SAS
session
“$UPARENw. Format” on
page 111
Writes a character string that is encoded in the current
SAS session in Unicode parenthesis (UPAREN)
representation
“$UPARENEw. Format”
on page 111
Writes a character string that is in Unicode parenthesis
(UPAREN) in a character string that is encoded in the
current SAS session
“$UPCASEw. Format” on
page 111
Converts character data to uppercase
“$UTF8Xw. Format” on
page 112
Writes a character string in universal transformation
format (UTF-8) encoding
“$VARYINGw. Format” on
page 112
Writes character data of varying length
“$w. Format” on page 115
Writes standard character data
“EURFRATSw.d Format”
on page 142
Converts an amount from Austrian schillings to euros
“EURFRBEFw.d Format”
on page 143
Converts an amount from Belgian francs to euros
“EURFRCHFw.d Format”
on page 143
Converts an amount from Swiss francs to euros
“EURFRCZKw.d Format”
on page 143
Converts an amount from Czech koruny to euros
“EURFRDEMw.d Format”
on page 143
Converts an amount from Deutsche marks to euros
“EURFRDKKw.d Format”
on page 144
Converts an amount from Danish kroner to euros
“EURFRESPw.d Format”
on page 144
Converts an amount from Spanish pesetas to euros
“EURFRFIMw.d Format”
on page 144
Converts an amount from Finnish markkaa to euros
“EURFRFRFw.d Format”
on page 144
Converts an amount from French francs to euros
Formats
Category
4
Formats by Category
Formats
Description
“EURFRGBPw.d Format”
on page 145
Converts an amount from British pounds to euros
“EURFRGRDw.d Format”
on page 145
Converts an amount from Greek drachmas to euros
“EURFRHUFw.d Format”
on page 145
Converts an amount from Hungarian forints to euros
“EURFRIEPw.d Format”
on page 145
Converts an amount from Irish pounds to euros
“EURFRITLw.d Format”
on page 146
Converts an amount from Italian lire to euros
“EURFRLUFw.d Format”
on page 146
Converts an amount from Luxembourg francs to euros
“EURFRNLGw.d Format”
on page 146
Converts an amount from Dutch guilders to euros
“EURFRNOKw.d Format”
on page 146
Converts an amount from Norwegian krone to euros
“EURFRPLZw.d Format”
on page 147
Converts an amount from Polish zlotys to euros
“EURFRPTEw.d Format”
on page 147
Converts an amount from Portuguese escudos to euros
“EURFRROLw.d Format”
on page 147
Converts an amount from Romanian lei to euros
“EURFRRURw.d Format”
on page 147
Converts an amount from Russian rubles to euros
“EURFRSEKw.d Format”
on page 148
Converts an amount from Swedish kronor to euros
“EURFRSITw.d Format”
on page 148
Converts an amount from Slovenian tolars to euros
“EURFRTRLw.d Format”
on page 148
Converts an amount from Turkish liras to euros
“EURFRYUDw.d Format”
on page 148
Converts an amount from Yugoslavian dinars to euros
“EURTOATSw.d Format”
on page 149
Converts an amount in euros to Austrian schillings
“EURTOBEFw.d Format”
on page 149
Converts an amount in euros to Belgian francs
“EURTOCHFw.d Format”
on page 150
Converts an amount in euros to Swiss francs
“EURTOCZKw.d Format”
on page 150
Converts an amount in euros to Czech koruny
“EURTODEMw.d Format”
on page 150
Converts an amount in euros to Deutsche marks
“EURTODKKw.d Format”
on page 150
Converts an amount in euros to Danish kroner
87
88
Formats by Category
Category
DBCS
Date and Time
4
Chapter 3
Formats
Description
“EURTOESPw.d Format”
on page 151
Converts an amount in euros to Spanish pesetas
“EURTOFIMw.d Format”
on page 151
Converts an amount in euros to Finnish markkaa
“EURTOFRFw.d Format”
on page 151
Converts an amount in euros to French francs
“EURTOGBPw.d Format”
on page 151
Converts an amount in euros to British pounds
“EURTOGRDw.d Format”
on page 152
Converts an amount in euros to Greek drachmas
“EURTOHUFw.d Format”
on page 152
Converts an amount in euros to Hungarian forints
“EURTOIEPw.d Format”
on page 152
Converts an amount in euros to Irish pounds
“EURTOITLw.d Format”
on page 152
Converts an amount in euros to Italian lire
“EURTOLUFw.d Format”
on page 153
Converts an amount in euros to Luxembourg francs
“EURTONLGw.d Format”
on page 153
Converts an amount in euros to Dutch guilders
“EURTONOKw.d Format”
on page 153
Converts an amount in euros to Norwegian krone
“EURTOPLZw.d Format”
on page 153
Converts an amount in euros to Polish zlotys
“EURTOPTEw.d Format”
on page 154
Converts an amount in euros to Portuguese escudos
“EURTOROLw.d Format”
on page 154
Converts an amount in euros to Romanian lei
“EURTORURw.d Format”
on page 154
Converts an amount in euros to Russian rubles
“EURTOSEKw.d Format”
on page 154
Converts an amount in euros to Swedish kronor
“EURTOSITw.d Format”
on page 155
Converts an amount in euros to Slovenian tolars
“EURTOTRLw.d Format”
on page 155
Converts an amount in euros to Turkish liras
“EURTOYUDw.d Format”
on page 155
Converts an amount in euros to Yugoslavian dinars
“$KANJIw. Format” on
page 101
Adds shift-code data to DBCS data
“$KANJIXw. Format” on
page 101
Removes shift code data from DBCS data
“DATEw. Format” on page
121
Writes date values in the form ddmmmyy or ddmmmyyyy
Formats
Category
4
Formats by Category
Formats
Description
“DATEAMPMw.d Format”
on page 122
Writes datetime values in the form
ddmmmyy:hh:mm:ss.ss with AM or PM
“DATETIMEw.d Format”
on page 124
Writes datetime values in the form
ddmmmyy:hh:mm:ss.ss
“DAYw. Format” on page
126
Writes date values as the day of the month
“DDMMYYw. Format” on
page 126
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 128
Writes date values in the form ddmm<yy> yy or
ddXmmX<yy>yy , where X represents a specified
separator and the year appears as either 2 or 4 digits
“DOWNAMEw. Format”
on page 133
Writes date values as the name of the day of the week
“DTDATEw. Format” on
page 134
Expects a datetime value as input and writes date values
in the form ddmmmyy or ddmmmyyyy
“DTMONYYw. Format” on
page 135
Writes the date part of a datetime value as the month
and year in the form mmmyy or mmmyyyy
“DTWKDATXw. Format”
on page 136
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 137
Writes the date part of a datetime value as the year in
the form yy or yyyy
“DTYYQCw. Format” on
page 138
Writes the date part of a datetime value as the year and
the quarter and separates them with a colon (:)
“EURDFDDw. Format” on
page 140
Writes international date values in the form dd.mm.yy or
dd.mm.yyyy
“EURDFDEw. Format” on
page 140
Writes international date values in the form ddmmmyy
or ddmmmyyyy
“EURDFDNw. Format” on
page 141
Writes international date values as the day of the week
“EURDFDTw.d Format”
on page 141
Writes international datetime values in the form
ddmmmyy:hh:mm:ss.ss or ddmmmyyyy hh:mm:ss.ss
“EURDFDWNw. Format”
on page 141
Writes international date values as the name of the day
“EURDFMNw. Format” on
page 141
Writes international date values as the name of the
month
“EURDFMYw. Format” on
page 142
Writes international date values in the form mmmyy or
mmmyyyy
“EURDFWDXw. Format”
on page 142
Writes international date values as the name of the
month, the day, and the year in the form dd month-name
yy (or yyyy )
89
90
Formats by Category
Category
4
Chapter 3
Formats
Description
“EURDFWKXw. Format”
on page 142
Writes international date values as the name of the day
and date in the form day-of-week, dd month-name yy (or
yyyy)
“HDATEw. Format” on
page 158
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” on
page 158
Writes date values according to the Jewish calendar
“HHMMw.d Format” on
page 159
Writes time values as hours and minutes in the form
hh:mm
“HOURw.d Format” on
page 161
Writes time values as hours and decimal fractions of
hours
“JULDAYw. Format” on
page 166
Writes date values as the Julian day of the year
“JULIANw. Format” on
page 167
Writes date values as Julian dates in the form yyddd or
yyyyddd
“MINGUOw. Format” on
page 168
Writes date values as Taiwanese dates in the form
yyymmdd
“MMDDYYw. Format” on
page 168
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 170
Writes date values in the form mmdd<yy> yy or
mmXddX<yy>yy , where X represents a specified
separator and the year appears as either 2 or 4 digits
“MMSSw.d Format” on
page 172
Writes time values as the number of minutes and
seconds since midnight
“MMYYw. Format” on
page 173
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 174
Writes date values in the form mm<yy> yy or
mmX<yy>yy, where X represents a specified separator
and the year appears as either 2 or 4 digits
“MONNAMEw. Format”
on page 176
Writes date values as the name of the month
“MONTHw. Format” on
page 177
Writes date values as the month of the year
“MONYYw. Format” on
page 178
Writes date values as the month and the year in the
form mmmyy or mmmyyyy
“NENGOw. Format” on
page 181
Writes date values as Japanese dates in the form
e.yymmdd
“NLDATEw. Format” on
page 181
Converts a SAS date value to the date value of the
specified locale and then writes the value in the format
of date
“NLDATEMNw. Format”
on page 181
Converts a SAS date value to the date value of the
specified locale and then writes the date value in the
format of name of month
Formats
Category
4
Formats by Category
Formats
Description
“NLDATEWw. Format” on
page 181
Converts a SAS date value to the date value of the
specified locale, and then writes the date value in the
format of the date and the day of week
“NLDATEWNw. Format”
on page 182
Converts the SAS date value to the date value of the
specified locale and then writes the date value in the
format of the name of day of week
“NLDATMw. Format” on
page 182
Converts a SAS datetime value to the datetime value of
the specified locale and then writes the value in the
format of datetime
“NLDATMAPw. Format”
on page 182
Converts a SAS datetime value to the datetime value of
the specified locale and then writes the value in the
format of datetime with a.m. or p.m.
“NLDATMTMw. Format”
on page 182
Converts the time portion of a SAS datetime value to the
time-of-day value of the specified locale and then writes
the value in the format of time of day
“NLDATMWw. Format” on
page 183
Converts a SAS date value to a datetime value of the
specified locale and then writes the value in the format
of day of week and datetime
“NLTIMAPw. Format” on
page 184
Converts a SAS time value to the time value of a
specified locale and then writes the value in the format
of a time value with a.m. or p.m.
“NLTIMEw. Format” on
page 185
Converts a SAS time value to the time value of the
specified locale and then writes the value in the format
of time
“PDJULGw. Format” on
page 188
Writes packed Julian date values in the hexadecimal
format yyyydddF for IBM
“PDJULIw. Format” on
page 190
Writes packed Julian date values in the hexadecimal
format ccyydddF for IBM
“QTRw. Format” on page
200
Writes date values as the quarter of the year
“QTRRw. Format” on page
201
Writes date values as the quarter of the year in Roman
numerals
“TIMEw.d Format” on
page 221
Writes time values as hours, minutes, and seconds in the
form hh:mm:ss.ss
“TIMEAMPMw.d Format”
on page 223
Writes time values as hours, minutes, and seconds in the
form hh:mm:ss.ss with AM or PM
“TODw.d Format” on page
224
Writes the time portion of datetime values in the form
hh:mm:ss.ss
“WEEKDATEw. Format”
on page 228
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 230
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 232
Writes date values as the day of the week
91
92
Formats by Category
Category
Hebrew text handling
Numeric
4
Chapter 3
Formats
Description
“WEEKUw. Format” on
page 233
Writes a week number in decimal format by using the U
algorithm
“WEEKVw. Format” on
page 233
Writes a week number in decimal format by using the V
algorithm
“WEEKWw. Format” on
page 233
Reads the format of the number-of-week value within the
year and returns a SAS-date value using the W algorithm
“WORDDATEw. Format”
on page 234
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 235
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
239
Writes date values as the year
“YYMMw. Format” on
page 240
Writes date values in the form <yy>yyM mm, where M is
the separator and the year appears as either 2 or 4 digits
“YYMMxw. Format” on
page 242
Writes date values in the form <yy>yymm or
<yy>yyXmm, where X represents a specified separator
and the year appears as either 2 or 4 digits
“YYMMDDw. Format” on
page 244
Writes date values in the form <yy>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 246
Writes date values in the form <yy>yymmdd or
<yy>yyXmmXdd, where X represents a specified
separator and the year appears as either 2 or 4 digits
“YYMONw. Format” on
page 249
Writes date values in the form yymmm or yyyymmm
“YYQw. Format” on page
250
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
251
Writes date values in the form <yy>yyq or <yy>yyXq,
where X represents a specified separator, the year
appears as either 2 or 4 digits, and q is the quarter of the
year
“YYQRw. Format” on page
253
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 254
Writes date values in the form <yy>yy qr or <yy>yyXqr,
where X represents a specified separator, the year
appears as either 2 or 4 digits, and qr is the quarter of
the year expressed in Roman numerals
“$CPTDWw. Format” on
page 99
Writes a character string in Hebrew text that is encoded
in IBM-PC (cp862) to Windows Hebrew encoding (cp1255)
“$CPTWDw. Format” on
page 99
Writes a character string that is encoded in Windows
(cp1255) to Hebrew DOS (cp862) encoding
“BESTw. Format” on page
116
SAS chooses the best notation
Formats
Category
4
Formats by Category
Formats
Description
“BINARYw. Format” on
page 117
Converts numeric values to binary representation
“COMMAw.d Format” on
page 118
Writes numeric values with a comma that separates
every three digits and a period that separates the
decimal fraction
“COMMAXw.d Format” on
page 119
Writes numeric values with a period that separates every
three digits and a comma that separates the decimal
fraction
“Dw.s Format” on page 120
Prints variables, possibly with a great range of values,
lining up decimal places for values of similar magnitude
“DOLLARw.d Format” on
page 130
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 131
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 139
Writes numeric values in scientific notation
“EUROw.d Format” on
page 149
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” on
page 149
Writes numeric values with a leading euro symbol (E), a
period that separates every three digits, and a comma
that separates the decimal fraction
“FLOATw.d Format” on
page 155
Generates a native single-precision, floating-point value
by multiplying a number by 10 raised to the dth power
“FRACTw. Format” on
page 157
Converts numeric values to fractions
“HEXw. Format” on page
158
Converts real binary (floating-point) values to
hexadecimal representation
“IBw.d Format” on page
162
Writes native integer binary (fixed-point) values,
including negative values
“IBRw.d Format” on page
163
Writes integer binary (fixed-point) values in Intel and
DEC formats
“IEEEw.d Format” on page
165
Generates an IEEE floating-point value by multiplying a
number by 10 raised to the dth power
“NEGPARENw.d Format”
on page 179
Writes negative numeric values in parentheses
“NLMNYw.d Format” on
page 183
Writes the monetary format of the local expression in the
specified locale using local currency
“NLMNYIw.d Format” on
page 183
Writes the monetary format of the international
expression in the specified locale
“NLNUMw.d Format” on
page 183
Writes the numeric format of the local expression in the
specified locale
93
94
Formats by Category
Category
4
Chapter 3
Formats
Description
“NLNUMIw.d Format” on
page 184
Writes the numeric format of the international
expression in the specified locale
“NLPCTw.d Format” on
page 184
Writes percentage data of the local expression in the
specified locale
“NLPCTIw.d Format” on
page 184
Writes percentage data of the international expression in
the specified locale
“NUMXw.d Format” on
page 185
Writes numeric values with a comma in place of the
decimal point
“OCTALw. Format” on
page 186
Converts numeric values to octal representation
“PDw.d Format” on page
187
Writes data in packed decimal format
“PERCENTw.d Format” on
page 192
Writes numeric values as percentages
“PERCENTNw.d Format”
on page 193
Produces percentages, using a minus sign for negative
values.
“PIBw.d Format” on page
194
Writes positive integer binary (fixed-point) values
“PIBRw.d Format” on page
196
Writes positive integer binary (fixed-point) values in
Intel and DEC formats
“PKw.d Format” on page
198
Writes data in unsigned packed decimal format
“PVALUEw.d Format” on
page 199
Writes p-values
“RBw.d Format” on page
202
Writes real binary data (floating-point) in real binary
format
“ROMANw. Format” on
page 204
Writes numeric values as roman numerals
“S370FFw.d Format” on
page 204
Writes native standard numeric data in IBM mainframe
format
“S370FIBw.d Format” on
page 206
Writes integer binary (fixed-point) values, including
negative values, in IBM mainframe format
“S370FIBUw.d Format” on
page 207
Writes unsigned integer binary (fixed-point) values in
IBM mainframe format
“S370FPDw.d Format” on
page 209
Writes packed decimal data in IBM mainframe format
“S370FPDUw.d Format”
on page 210
Writes unsigned packed decimal data in IBM mainframe
format
“S370FPIBw.d Format” on
page 211
Writes positive integer binary (fixed-point) values in IBM
mainframe format
“S370FRBw.d Format” on
page 213
Writes real binary (floating-point) data in IBM
mainframe format
“S370FZDw.d Format” on
page 214
Writes zoned decimal data in IBM mainframe format
Formats
Category
Description
“S370FZDLw.d Format” on
page 216
Writes zoned decimal leading–sign data in IBM
mainframe format
“S370FZDSw.d Format” on
page 217
Writes zoned decimal separate leading-sign data in IBM
mainframe format
“S370FZDTw.d Format” on
page 218
Writes zoned decimal separate trailing-sign data in IBM
mainframe format
“S370FZDUw.d Format”
on page 219
Writes unsigned zoned decimal data in IBM mainframe
format
“SSNw. Format” on page
220
Writes Social Security numbers
“VAXRBw.d Format” on
page 226
Writes real binary (floating-point) data in VMS format
“w.d Format” on page 227
Writes standard numeric data one digit per byte
“WORDFw. Format” on
page 237
Writes numeric values as words with fractions that are
shown numerically
“WORDSw. Format” on
page 238
Writes numeric values as words
“YENw.d Format” on page
240
Writes numeric values with yen signs, commas, and
decimal points
“Zw.d Format” on page 256
Writes standard numeric data with leading 0s
“ZDw.d Format” on page
257
Writes numeric data in zoned decimal format
$ASCIIw. Format
Converts native format character data to ASCII representation
Category: Character
Syntax
$ASCIIw.
$ASCIIw. Format
Formats
Dictionary
Alignment:
4
left
95
96
4
$BIDIw. Format
Chapter 3
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.
3 On all other systems, $ASCIIw. behaves like the $CHARw. format.
Examples
put x $ascii3.;
When x = ...
The Result* is ...
abc
616263
ABC
414243
();
28293B
* The results are hexadecimal representations of ASCII codes for characters.
Each two
hexadecimal digits correspond to one byte of binary data, and each byte corresponds to one
character.
$BIDIw. Format
Convert a Logical ordered string to a Visually ordered string, and vice versa by reversing the order
of Hebrew characters while preserving the order of Latin characters and numbers
Category:
Character
left
See: The BIDI format in SAS National Language Support (NLS): User’s Guide
Alignment:
Formats
4
$BINARYw. Format
$BINARYw. Format
Converts character data to binary representation
Category: Character
Alignment:
left
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.
Examples
put @1 name $binary16.;
When name =
...
AB
The Result is ...
ASCII
EBCDIC
----+----1----+----2
----+----1----+----2
0100000101000010
1100000111000010
97
98
$CHARw. Format
4
Chapter 3
$CHARw. Format
Writes standard character data
Category:
Alignment:
Character
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 prior to output, 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)
Examples
put @7 name $char4.;
When name = ...
The Result is ...
----+----1
XYZ
XYZ
Formats
4
$EBCDICw. Format
$CPTDWw. Format
Writes a character string in Hebrew text that is encoded in IBM-PC (cp862) to Windows Hebrew
encoding (cp1255)
Category: Hebrew text handling
Alignment:
See:
left
The $CPTDW format in SAS National Language Support (NLS): User’s Guide
$CPTWDw. Format
Writes a character string that is encoded in Windows (cp1255) to Hebrew DOS (cp862) encoding
Category: Hebrew text handling
Alignment:
See:
left
The $CPTWD format in SAS National Language Support (NLS): User’s Guide
$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.
99
100
4
$HEXw. Format
Chapter 3
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.;
When name = ...
The Result* is ...
qrs
9899A2
QRS
D8D9E2
+;>
4E5E6E
* The results are shown as hexadecimal representations of EBCDIC codes for characters. Each
two hexadecimal digits correspond to one byte of binary data, and each byte corresponds to one
character.
$HEXw. Format
Converts character data to hexadecimal representation
Character
left
See: $HEXw. Format in the documentation for your operating environment.
Category:
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 digits. Each blank
counts as one character, including trailing blanks.
Formats
4
$LOGVSw. Format
Comparisons
The HEXw. format converts real binary numbers to their hexadecimal equivalent.
Examples
put @5 name $hex4.;
When name = ...
The Result is ...
EBCDIC
ASCII
----+----1
----+----1
AB
C1C2
4142
$KANJIw. Format
Adds shift-code data to DBCS data
Category: DBCS
Alignment:
See:
left
The $KANJI format in SAS National Language Support (NLS): User’s Guide
$KANJIXw. Format
Removes shift code data from DBCS data
Category: DBCS
Alignment:
See:
left
The $KANJIX format in SAS National Language Support (NLS): User’s Guide
$LOGVSw. Format
Writes a character string in left-to-right logical order to visual order
Category: BIDI text handling
Alignment:
See:
left
The $LOGVS format in SAS National Language Support (NLS): User’s Guide
101
102
$LOGVSRw. Format
4
Chapter 3
$LOGVSRw. Format
Writes a character string in right-to-left logical order to visual order
BIDI text handling
left
See: The $LOGVSR format in SAS National Language Support (NLS): User’s Guide
Category:
Alignment:
$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 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.;
When name = ...
The Result is ...
sas
SAS
Formats
4
$OCTALw. Format
103
$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
Because each character value generates three octal characters, increase the
value of w by three times the length of the character value.
Tip:
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.
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
104
$QUOTEw. Format
4
Chapter 3
$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 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 105.
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
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.
Formats
4
$REVERJw. Format
105
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.;
When name = ...
The Result is ...
----+----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.
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.
106
$REVERSw. Format
4
Chapter 3
Examples
put @1 name $reverj7.;
When name* = ...
The Result is ...
----+----1
ABCD###
DCBA
###ABCD
DCBA
* The character # represents a blank space.
$REVERSw. Format
Writes character data in reverse order and left aligns
Category:
Character
Alignment:
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.
Examples
put @1 name $revers7.;
Formats
When name* = ...
4
$UCS2Lw. Format
107
The Result is ...
----+----1
ABCD###
DCBA
###ABCD
DCBA
* The character # represents a blank space.
$UCS2Bw. Format
Writes a character string in big-endian, 16-bit, universal character set code in 2 octets (UCS2),
Unicode encoding
Category: Character
Left
The $UCS2B format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
$UCS2BEw. Format
Writes a big-endian, 16–bit, universal character set code in 2 octets (UCS2) character string in the
encoding of the current SAS session
Category: Character
left
The $UCS2BE format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
$UCS2Lw. Format
Writes data in little-endian, 16-bit, universal character set code in 2 octets (UCS2), Unicode
encoding
Category: Character
Alignment:
See:
Left
The $UCS2L format in SAS National Language Support (NLS): User’s Guide
108
$UCS2LEw. Format
4
Chapter 3
$UCS2LEw. Format
Writes a character string that is encoded in little-endian, 16-bit, universal character set code in 2
octets (UCS2), in the encoding of the current SAS session
Category:
Character
left
Alignment:
See:
The $UCS2LE format in SAS National Language Support (NLS): User’s Guide
$UCS2Xw. Format
Writes a character string in native-endian, 16-bit, universal character set code in 2 octets (UCS2)
Unicode encoding
Category:
Character
Left
Alignment:
See:
The $UCS2X format in SAS National Language Support (NLS): User’s Guide
$UCS2XEw. Format
Writes a native-endian, 16-bit, universal character set code in 2 octets (UCS2) character string in
the encoding of the current SAS session
Category:
Character
left
Alignment:
See:
The $UCS2XE format in SAS National Language Support (NLS): User’s Guide
$UCS4Bw. Format
Writes a character string in big-endian, 32-bit, universal character set code in 4 octets (UCS4),
Unicode encoding
Category:
Alignment:
See:
Character
Left
The $UCS4B format in SAS National Language Support (NLS): User’s Guide
Formats
4
$UCS4Xw. Format
109
$UCS4BEw. Format
Writes a big-endian, 32-bit, universal character set code in 4 octets (UCS4), character string in
the encoding of the current SAS session
Category: Character
Alignment:
See:
left
The $UCS4BE format in SAS National Language Support (NLS): User’s Guide
$UCS4Lw. Format
Writes a character string in little-endian, 32-bit, universal character set code in 4 octets, (UCS4),
Unicode encoding
Category: Character
Alignment:
See:
left
The $UCS4L format in SAS National Language Support (NLS): User’s Guide
$UCS4LEw. Format
Writes a little-endian, 32-bit, universal character set code in 4 octets (UCS4) character string in
the encoding of the current SAS session
Category: Character
Alignment:
See:
left
The $UCS4LE format in SAS National Language Support (NLS): User’s Guide
$UCS4Xw. Format
Writes a character string in native-endian, 32-bit, universal character set code in 4 octets (UCS4),
Unicode encoding
Category: Character
Alignment:
See:
left
The $UCS4X format in SAS National Language Support (NLS): User’s Guide
110
$UCS4XEw. Format
4
Chapter 3
$UCS4XEw. Format
Writes a native-endian, 32-bit, universal character set code in 4 octets (UCS4) character string in
the encoding of the current SAS session
Category:
Alignment:
See:
Character
left
The $UCS4XE format in SAS National Language Support (NLS): User’s Guide
$UESCw. Format
Writes a character string that is encoded in the current SAS session in Unicode escape (UESC)
representation
Category:
Alignment:
See:
Character
left
The $UESC format in SAS National Language Support (NLS): User’s Guide
$UESCEw. Format
Writes a Unicode escape (UESC) representation character string in the encoding of the current SAS
session
Category:
Alignment:
See:
Character
left
The $UESCE format in SAS National Language Support (NLS): User’s Guide
$UNCRw. Format
Writes a character string that is encoded in the current SAS session in numeric character
representation (NCR)
Category:
Alignment:
See:
Character
left
The $UNCR format in SAS National Language Support (NLS): User’s Guide
Formats
4
$UPCASEw. Format
111
$UNCREw. Format
Writes the numeric character representation (NCR) character string in the encoding of the current
SAS session
Category: Character
Alignment:
See:
left
The $UNCRE format in SAS National Language Support (NLS): User’s Guide
$UPARENw. Format
Writes a character string that is encoded in the current SAS session in Unicode parenthesis
(UPAREN) representation
Category: Character
Alignment:
See:
left
The $UPAREN format in SAS National Language Support (NLS): User’s Guide
$UPARENEw. Format
Writes a character string that is in Unicode parenthesis (UPAREN) in a character string that is
encoded in the current SAS session
Category: Character
Alignment:
See:
left
The $UPARENE format in SAS National Language Support (NLS): User’s Guide
$UPCASEw. Format
Converts character data to uppercase
Category: Character
Alignment:
left
Syntax
$UPCASEw.
112
$UTF8Xw. Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 8 if the length of the variable is undefined; otherwise, 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.;
When name = ...
The Result is ...
----+----1
coxe-ryan
COXE-RYAN
$UTF8Xw. Format
Writes a character string in universal transformation format (UTF-8) encoding
Character
left
See: The $UTF8X format in SAS National Language Support (NLS): User’s Guide
Category:
Alignment:
$VARYINGw. Format
Writes character data of varying length
in DATA step
Character
Alignment: left
Valid:
Category:
Syntax
$VARYINGw. length-variable
Formats
4
$VARYINGw. Format
113
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 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.
You must specify length-variable immediately after $VARYINGw. in
a SAS statement.
Requirement:
Restriction:
Length-variable cannot be an array reference.
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.
Tip:
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.
When name* = ...
The Result is ...
----+----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.
114
$VSLOGw. Format
4
Chapter 3
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.
$VSLOGw. Format
Writes a character string in visual order to left-to-right logical order
BIDI text handling
left
See: The $VSLOG format in SAS National Language Support (NLS): User’s Guide
Category:
Alignment:
$VSLOGRw. Format
Writes a character string in visual order to right-to-left logical order
BIDI text handling
left
See: The $VSLOGR format in SAS National Language Support (NLS): User’s Guide
Category:
Alignment:
Formats
4
$w. Format
115
$w. Format
Writes standard character data
Category: Character
left
Alias: $Fw.
Alignment:
Syntax
$w.
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 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 prior
to output, or use list output with the colon (:) format modifier and the format of your
choice.
Examples
put @10 name $5.;
put name $ 10-15;
Values*
Results
----+----1----+----2
#Cary
Cary
Tokyo
Tokyo
* The character # represents a blank space.
116
4
BESTw. Format
Chapter 3
BESTw. Format
SAS chooses the best notation
Category:
Numeric
Alignment:
See:
right
BESTw. Format in the documentation for your operating environment.
Syntax
BESTw.
Syntax Description
w
specifies the width of the output field.
Default: 12
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.
Tip:
Range:
1–32
Details
The BESTw. format is the default format for writing numeric values. When there is no
format specification, SAS chooses the format that provides the most information about
the value according to the available field width. BESTw. rounds the value, and if SAS
can display at least one significant digit in the decimal portion, within the width
specified, BESTw. produces the result in decimal. Otherwise, it produces the result in
scientific notation. SAS always stores the complete value regardless of the format that
you use to represent it.
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
Formats
4
BINARYw. Format
117
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
Comparisons
BINARYw. converts numeric values to binary representation. The $BINARYw. format
converts character values to binary representation.
Examples
put @1 x binary8.;
When x = ...
The Result is ...
----+----1
123.45
01111011
123
01111011
-123
10000101
118
COMMAw.d Format
4
Chapter 3
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
optionally 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
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.
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;
When sales = ...
The result is ...
----+----1----+----2
23451.23
123451.234
23,451.23
123,451.23
Formats
4
COMMAXw.d Format
119
See Also
Formats:
“COMMAXw.d Format” on page 119
“DOLLARw.d Format” on page 130
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.
Default: 6
Range: 1–32
Make w wide enough to write the numeric values, the commas, and the
optional decimal point.
Tip:
d
optionally 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
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.
120
Dw.s Format
4
Chapter 3
Examples
put @10 sales commax10.2;
When sales = ...
The result is ...
----+----1----+----2
23451.23
23.451,23
123451.234
123.451,23
Dw.s Format
Prints variables, possibly with a great range of values, lining up decimal places for values of
similar magnitude
Category:
Alignment:
Numeric
right
Syntax
Dw.s
Syntax Description
w
optionally specifies the width of the output field.
Default: 12
Range: 1–32
s
optionally specifies the significant digits.
Default: 3
Range: 0–16
Requirement: must be less than w
Details
The Dw.s format writes numbers so that the decimal point aligns in groups of values
with similar magnitude.
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.
Formats
4
DATEw. Format
121
3 Dw.s writes numbers with the desired precision and more alignment than BESTw.
3 The w.d format aligns decimal points, if possible, but does not necessarily show
the same precision for all numbers.
Examples
put @1 x d10.4;
When x = ...
The Result is ...
----+----1----+----2
12345
12345.0
1234.5
1234.5
123.45
123.45000
12.345
12.34500
1.2345
1.23450
.12345
0.12345
DATEw. Format
Writes date values in the form ddmmmyy or ddmmmyyyy
Category: Date and Time
Alignment:
right
Syntax
DATEw.
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.
122
4
DATEAMPMw.d Format
Chapter 3
Details
The DATEw. format writes SAS date values in the form ddmmmyy or ddmmmyyyy,
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 15780, which is the SAS date value that
corresponds to March 16, 2003.
When the SAS Statement is ...
The Result is ...
----+----1----+
put day date5.;
16MAR
put day date6.;
16MAR
put day date7.;
16MAR03
put day date8.;
16MAR03
put day date9.;
16MAR2003
See Also
Function:
“DATE Function” on page 501
Informat:
“DATEw. Informat” on page 1060
DATEAMPMw.d Format
Writes datetime values in the form ddmmmyy:hh:mm:ss.ss with AM or PM
Category:
Alignment:
Date and Time
right
Syntax
DATEAMPMw.d
Formats
4
DATEAMPMw.d Format
Syntax Description
w
specifies the width of the output field.
Default: 19
Range: 7–40
Tip: 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.
d
optionally specifies the number of digits to the right of the decimal point in the
seconds value.
Requirement: must be less than w
Range: 0–39
Note: 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.
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 AM on April 20, 2003.
When the SAS Statement is ...
The Result is ...
----+----1----+----2----+
put event dateampm.;
20APR03:11:01:34 AM
put event dateampm7.;
20APR03
123
124
4
DATETIMEw.d Format
Chapter 3
When the SAS Statement is ...
The Result is ...
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 124
DATETIMEw.d Format
Writes datetime values in the form ddmmmyy:hh:mm:ss.ss
Category:
Date and Time
Alignment:
right
Syntax
DATETIMEw.d
Syntax Description
w
specifies the width of the output field.
Default: 16
Range:
7–40
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.
Tip:
d
optionally specifies the number of digits to the right of the decimal point in the
seconds value.
Requirement:
Range:
Note:
must be less than w
0–39
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
Formats
4
DATETIMEw.d Format
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 AM on November 10, 2005.
When the SAS Statement is ...
The Result is ...
----+----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
put event datetime20.1;
10NOV2005:03:49:19.0
put event datetime21.2;
10NOV2005:03:49:19.00
See Also
Formats:
“DATEw. Format” on page 121
“TIMEw.d Format” on page 221
Function:
“DATETIME Function” on page 502
Informats:
“DATEw. Informat” on page 1060
“DATETIMEw. Informat” on page 1061
“TIMEw. Informat” on page 1120
125
126
DAYw. Format
4
Chapter 3
DAYw. Format
Writes date values as the day of the month
Category:
Date and Time
right
Alignment:
Syntax
DAYw.
Syntax Description
w
specifies the width of the output field.
Default: 2
2–32
Range:
Examples
The example table uses the input value of 16601, which is the SAS date value that
corresponds to June 14, 2005.
When the SAS Statement is ...
The Result is ...
----+----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:
Alignment:
Date and Time
right
Syntax
DDMMYYw.
Formats
4
DDMMYYw. Format
127
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.
Examples
The following examples use the input value of 16794, which is the SAS date value
that corresponds to December 24, 2005.
When the SAS Statement is ...
The Result is ...
----+----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
128
DDMMYYxw. Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYxw. Format” on page 128
“MMDDYYw. Format” on page 168
“YYMMDDw. Format” on page 244
Function:
“MDY Function” on page 680
Informats:
“DATEw. Informat” on page 1060
“DDMMYYw. Informat” on page 1062
“MMDDYYw. Informat” on page 1074
“YYMMDDw. Informat” on page 1128
DDMMYYxw. Format
Writes date values in the form ddmm<yy>yy or ddXmmX<yy>yy, where X represents a specified
separator and the year appears as either 2 or 4 digits
Category:
Alignment:
Date and Time
right
Syntax
DDMMYYxw.
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
Formats
4
DDMMYYxw. Format
129
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 16511, which is the SAS date value
that corresponds to March 16, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date ddmmyyc5.;
16:03
put date ddmmyyd8.;
16-03-05
put date ddmmyyp10.;
16.03.2005
put date ddmmyyn8.;
16032005
130
DOLLARw.d Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYw. Format” on page 126
“MMDDYYxw. Format” on page 170
“YYMMDDxw. Format” on page 246
Functions:
“DAY Function” on page 503
“MDY Function” on page 680
“MONTH Function” on page 695
“YEAR Function” on page 991
Informat:
“DDMMYYw. Informat” on page 1062
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
d
optionally 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
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.
Formats
4
DOLLARXw.d Format
131
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 “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;
When netpay = ...
The result is ...
----+----1----+
1254.71
$1,254.71
See Also
Formats:
“COMMAw.d Format” on page 118
“DOLLARXw.d Format” on page 131
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
Category: Numeric
Alignment:
right
Syntax
DOLLARXw.d
132
DOLLARXw.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 2–32
d
optionally specifies the number of digits to the right of the decimal point in the
numeric value.
Default: 0
Range: 2–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;
When netpay = ...
The result is ...
----+----1----+
1254.71
$1.254,71
Formats
4
DOWNAMEw. Format
See Also
Formats:
“COMMAXw.d Format” on page 119
“DOLLARw.d Format” on page 130
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: 1–32
Tip:
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.
When the SAS Statement is ...
The Result is ...
----+----1
put date downame.;
Sunday
133
134
DTDATEw. Format
4
Chapter 3
See Also
Format:
“WEEKDAYw. Format” on page 232
DTDATEw. Format
Expects a datetime value as input and writes date values in the form ddmmmyy or ddmmmyyyy
Category:
Date and Time
right
Alignment:
Syntax
DTDATEw.
Syntax Description
w
specifies the width of the output field.
Default: 7
Range:
Tip:
5–9
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.
Formats
When the SAS statement is ...
4
DTMONYYw. Format
135
The Result is ...
----+----+
put trip_date=dtdate.;
16APR00
put trip_date=dtdate9.;
16APR2000
See Also
Formats:
“DATEw. Format” on page 121
DTMONYYw. Format
Writes the date part of a datetime value as the month and year in the form mmmyy or mmmyyyy
Category: Date and Time
Alignment:
right
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.
136
DTWKDATXw. Format
4
Chapter 3
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 AM.
When the SAS Statement is ...
The Result is ...
----+----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 124
“MONYYw. Format” on page 178
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)
Date and Time
Alignment: right
Category:
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
Formats
4
DTYEARw. Format
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 AM.
When the SAS Statement is ...
The Result is ...
----+----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 124
“WEEKDATXw. Format” on page 230
DTYEARw. Format
Writes the date part of a datetime value as the year in the form yy or yyyy
Category: Date and Time
Alignment:
right
Syntax
DTYEARw.
137
138
DTYYQCw. Format
4
Chapter 3
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 AM.
When the SAS Statement is ...
The Result is ...
----+----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 124
“YEARw. Format” on page 239
DTYYQCw. Format
Writes the date part of a datetime value as the year and the quarter and separates them with a
colon (:)
Category:
Alignment:
Date and Time
right
Syntax
DTYYQCw.
Formats
4
Ew. Format
139
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 4–6
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 PM.
When the SAS Statement is ...
The Result is ...
----+----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 124
Ew. Format
Writes numeric values in scientific notation
Category: Numeric
Alignment:
See:
Ew. Format in the documentation for your operating environment.
Syntax
Ew.
right
140
EURDFDDw. Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 12
7–32
Range:
Details
SAS reserves the first column of the result for a minus sign.
Examples
put @1 x e10.;
When x = ...
The Result is ...
----+----1----+
1257
1.257E+03
-1257
-1.257E+03
EURDFDDw. Format
Writes international date values in the form dd.mm.yy or dd.mm.yyyy
Category:
Alignment:
See:
Date and Time
right
The EURDFDD format in SAS National Language Support (NLS): User’s Guide
EURDFDEw. Format
Writes international date values in the form ddmmmyy or ddmmmyyyy
Category:
Alignment:
See:
Date and Time
right
The EURDFDE format in SAS National Language Support (NLS): User’s Guide
Formats
4
EURDFMNw. Format
141
EURDFDNw. Format
Writes international date values as the day of the week
Category: Date and Time
right
The EURDFDN format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURDFDTw.d Format
Writes international datetime values in the form ddmmmyy:hh:mm:ss.ss or
ddmmmyyyy hh:mm:ss.ss
Category: Date and Time
Alignment:
See:
right
The EURDFDT format in SAS National Language Support (NLS): User’s Guide
EURDFDWNw. Format
Writes international date values as the name of the day
Category: Date and Time
right
The EURDFDWN format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURDFMNw. Format
Writes international date values as the name of the month
Date and Time
Alignment: right
See: The EURDFMN format in SAS National Language Support (NLS): User’s Guide
Category:
142
4
EURDFMYw. Format
Chapter 3
EURDFMYw. Format
Writes international date values in the form mmmyy or mmmyyyy
Date and Time
Alignment: right
See: The EURDFMY format in SAS National Language Support (NLS): User’s Guide
Category:
EURDFWDXw. Format
Writes international date values as the name of the month, the day, and the year in the form dd
month-name yy (or yyyy)
Date and Time
Alignment: right
Category:
See:
The EURDFWDX format in SAS National Language Support (NLS): User’s Guide
EURDFWKXw. Format
Writes international date values as the name of the day and date in the form day-of-week, dd
month-name yy (or yyyy)
Date and Time
Alignment: right
See: The EURDFWKX format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRATSw.d Format
Converts an amount from Austrian schillings to euros
Currency Conversion
Alignment: right
See: The EURFRATS format in SAS National Language Support (NLS): User’s Guide
Category:
Formats
4
EURFRDEMw.d Format
143
EURFRBEFw.d Format
Converts an amount from Belgian francs to euros
Category: Currency Conversion
right
The EURFRBEF format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRCHFw.d Format
Converts an amount from Swiss francs to euros
Category: Currency Conversion
right
The EURFRCHF format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRCZKw.d Format
Converts an amount from Czech koruny to euros
Category: Currency Conversion
right
The EURFRCZK format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRDEMw.d Format
Converts an amount from Deutsche marks to euros
Category: Currency Conversion
Alignment:
See:
right
The EURFRDEM format in SAS National Language Support (NLS): User’s Guide
144
EURFRDKKw.d Format
4
Chapter 3
EURFRDKKw.d Format
Converts an amount from Danish kroner to euros
Currency Conversion
Alignment: right
See: The EURFRDKK format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRESPw.d Format
Converts an amount from Spanish pesetas to euros
Currency Conversion
Alignment: right
See: The EURFRESP format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRFIMw.d Format
Converts an amount from Finnish markkaa to euros
Category:
Currency Conversion
right
The EURFRFIM format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRFRFw.d Format
Converts an amount from French francs to euros
Currency Conversion
Alignment: right
Category:
See:
The EURFRFRF format in SAS National Language Support (NLS): User’s Guide
Formats
4
EURFRIEPw.d Format
145
EURFRGBPw.d Format
Converts an amount from British pounds to euros
Category: Currency Conversion
right
The EURFRGBP format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRGRDw.d Format
Converts an amount from Greek drachmas to euros
Category: Currency Conversion
right
The EURFRGRD format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRHUFw.d Format
Converts an amount from Hungarian forints to euros
Category: Currency Conversion
right
The EURFRHUF format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRIEPw.d Format
Converts an amount from Irish pounds to euros
Category: Currency Conversion
Alignment:
See:
right
The EURFRIEP format in SAS National Language Support (NLS): User’s Guide
146
EURFRITLw.d Format
4
Chapter 3
EURFRITLw.d Format
Converts an amount from Italian lire to euros
Currency Conversion
Alignment: right
See: The EURFRITL format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRLUFw.d Format
Converts an amount from Luxembourg francs to euros
Category:
Currency Conversion
right
The EURFRLUF format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRNLGw.d Format
Converts an amount from Dutch guilders to euros
Category:
Currency Conversion
right
The EURFRNLG format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRNOKw.d Format
Converts an amount from Norwegian krone to euros
Currency Conversion
Alignment: right
Category:
See:
The EURFRNOK format in SAS National Language Support (NLS): User’s Guide
Formats
4
EURFRRURw.d Format
147
EURFRPLZw.d Format
Converts an amount from Polish zlotys to euros
Category: Currency Conversion
right
The EUFRRPLZ format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRPTEw.d Format
Converts an amount from Portuguese escudos to euros
Category: Currency Conversion
right
The EURFRPTE format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRROLw.d Format
Converts an amount from Romanian lei to euros
Category: Currency Conversion
right
The EURFRROL format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURFRRURw.d Format
Converts an amount from Russian rubles to euros
Category: Currency Conversion
Alignment:
See:
right
The EURFRRUR format in SAS National Language Support (NLS): User’s Guide
148
EURFRSEKw.d Format
4
Chapter 3
EURFRSEKw.d Format
Converts an amount from Swedish kronor to euros
Currency Conversion
Alignment: right
See: The EURFRSEK format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRSITw.d Format
Converts an amount from Slovenian tolars to euros
Currency Conversion
Alignment: right
See: The EURFRSIT format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRTRLw.d Format
Converts an amount from Turkish liras to euros
Currency Conversion
Alignment: right
See: The EURFRTRL format in SAS National Language Support (NLS): User’s Guide
Category:
EURFRYUDw.d Format
Converts an amount from Yugoslavian dinars to euros
Currency Conversion
Alignment: right
Category:
See:
The EURFRYUD format in SAS National Language Support (NLS): User’s Guide
Formats
4
EURTOBEFw.d Format
149
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
Category: Numeric
right
The EURO format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
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
Category: Numeric
right
See: The EUROX format in SAS National Language Support (NLS): User’s Guide
Alignment:
EURTOATSw.d Format
Converts an amount in euros to Austrian schillings
Category: Currency Conversion
right
See: The EURTOATS format in SAS National Language Support (NLS): User’s Guide
Alignment:
EURTOBEFw.d Format
Converts an amount in euros to Belgian francs
Category: Currency Conversion
right
See: The EURTOBEF format in SAS National Language Support (NLS): User’s Guide
Alignment:
150
EURTOCHFw.d Format
4
Chapter 3
EURTOCHFw.d Format
Converts an amount in euros to Swiss francs
Currency Conversion
Alignment: right
See: The EURTOCHF format in SAS National Language Support (NLS): User’s Guide
Category:
EURTOCZKw.d Format
Converts an amount in euros to Czech koruny
Currency Conversion
Alignment: right
See: The EURTOCZK format in SAS National Language Support (NLS): User’s Guide
Category:
EURTODEMw.d Format
Converts an amount in euros to Deutsche marks
Currency Conversion
Alignment: right
See: The EURTODEM format in SAS National Language Support (NLS): User’s Guide
Category:
EURTODKKw.d Format
Converts an amount in euros to Danish kroner
Currency Conversion
Alignment: right
See: The EURTODKK format in SAS National Language Support (NLS): User’s Guide
Category:
Formats
4
EURTOGBPw.d Format
151
EURTOESPw.d Format
Converts an amount in euros to Spanish pesetas
Category: Currency Conversion
right
The EURTOESP format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURTOFIMw.d Format
Converts an amount in euros to Finnish markkaa
Category: Currency Conversion
right
See: The EURTOFIM format in SAS National Language Support (NLS): User’s Guide
Alignment:
EURTOFRFw.d Format
Converts an amount in euros to French francs
Category: Currency Conversion
right
See: The EURTOFRF format in SAS National Language Support (NLS): User’s Guide
Alignment:
EURTOGBPw.d Format
Converts an amount in euros to British pounds
Category: Currency Conversion
right
See: The EURTOGBP format in SAS National Language Support (NLS): User’s Guide
Alignment:
152
EURTOGRDw.d Format
4
Chapter 3
EURTOGRDw.d Format
Converts an amount in euros to Greek drachmas
Currency Conversion
Alignment: right
See: The EURTOGRD format in SAS National Language Support (NLS): User’s Guide
Category:
EURTOHUFw.d Format
Converts an amount in euros to Hungarian forints
Currency Conversion
Alignment: right
See: The EURTOHUF format in SAS National Language Support (NLS): User’s Guide
Category:
EURTOIEPw.d Format
Converts an amount in euros to Irish pounds
Currency Conversion
Alignment: right
See: The EURTOIEP format in SAS National Language Support (NLS): User’s Guide
Category:
EURTOITLw.d Format
Converts an amount in euros to Italian lire
Currency Conversion
Alignment: right
See: The EURTOITL format in SAS National Language Support (NLS): User’s Guide
Category:
Formats
4
EURTOPLZw.d Format
153
EURTOLUFw.d Format
Converts an amount in euros to Luxembourg francs
Category: Currency Conversion
right
The EURTOLUF format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
EURTONLGw.d Format
Converts an amount in euros to Dutch guilders
Category: Currency Conversion
right
See: The EURTONLG format in SAS National Language Support (NLS): User’s Guide
Alignment:
EURTONOKw.d Format
Converts an amount in euros to Norwegian krone
Category: Currency Conversion
right
See: The EURTONOK format in SAS National Language Support (NLS): User’s Guide
Alignment:
EURTOPLZw.d Format
Converts an amount in euros to Polish zlotys
Category: Currency Conversion
right
See: The EURTOPLZ format in SAS National Language Support (NLS): User’s Guide
Alignment:
154
EURTOPTEw.d Format
4
Chapter 3
EURTOPTEw.d Format
Converts an amount in euros to Portuguese escudos
Currency Conversion
Alignment: right
See: The EURTOPTE format in SAS National Language Support (NLS): User’s Guide
Category:
EURTOROLw.d Format
Converts an amount in euros to Romanian lei
Currency Conversion
Alignment: right
See: The EURTOROL format in SAS National Language Support (NLS): User’s Guide
Category:
EURTORURw.d Format
Converts an amount in euros to Russian rubles
Currency Conversion
Alignment: right
See: The EURTORUR format in SAS National Language Support (NLS): User’s Guide
Category:
EURTOSEKw.d Format
Converts an amount in euros to Swedish kronor
Currency Conversion
Alignment: right
See: The EURTOSEK format in SAS National Language Support (NLS): User’s Guide
Category:
Formats
4
FLOATw.d Format
155
EURTOSITw.d Format
Converts an amount in euros to Slovenian tolars
Category: Currency Conversion
Alignment:
See:
right
The EURTOSIT format in SAS National Language Support (NLS): User’s Guide
EURTOTRLw.d Format
Converts an amount in euros to Turkish liras
Category: Currency Conversion
Alignment:
See:
right
The EURTOTRL format in SAS National Language Support (NLS): User’s Guide
EURTOYUDw.d Format
Converts an amount in euros to Yugoslavian dinars
Category: Currency Conversion
Alignment:
See:
right
The EURTOYUD format in SAS National Language Support (NLS): User’s Guide
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
156
FLOATw.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Requirement: width must be 4
d
optionally specifies the power of 10 by which to multiply the value.
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 those 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 may have this
same characteristic.
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)
Formats
4
FRACTw. Format
157
Examples
put x float4.;
When x = ...
The Result* is ...
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: Numeric
Alignment:
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.
Examples
put x fract8.;
When x = ...
The Result is ...
----+----1
0.6666666667
0.2784
2/3
174/625
158
HDATEw. Format
4
Chapter 3
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
Category:
Date and Time
right
Alignment:
See:
The HDATE format in SAS National Language Support (NLS): User’s Guide
HEBDATEw. Format
Writes date values according to the Jewish calendar
Category:
Date and Time
right
Alignment:
See:
The HEBDATE format in SAS National Language Support (NLS): User’s Guide
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 digits. 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:
Formats
4
HHMMw.d Format
159
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
Comparisons
The HEXw. numeric format and the $HEXw. character format both generate the
hexadecimal equivalent of values.
Examples
put @8 x hex8.;
When x = ...
The Result is ...
----+----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
Category:
Date and Time
Alignment:
right
Syntax
HHMMw.d
Syntax Description
w
specifies the width of the output field.
160
HHMMw.d Format
4
Chapter 3
Default: 5
Range:
2–20
d
optionally 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.
Default: 0
Range:
0–19
Requirement:
must be less than w
Details
The HHMMw.d format writes SAS datetime values in the form hh:mm, where
hh
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.
Comparisons
The HHMMw.d format is similar to the TIMEw.d format except that the HHMMw.d
format does not print seconds.
Examples
The example table uses the input value of 46796, which is the SAS time value that
corresponds to 12:59:56 PM.
When the SAS statement is ...
The result is ...
----+----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 161
“MMSSw.d Format” on page 172
“TIMEw.d Format” on page 221
Formats
4
HOURw.d Format
161
Functions:
“HMS Function” on page 610
“HOUR Function” on page 611
“MINUTE Function” on page 684
“SECOND Function” on page 880
“TIME Function” on page 922
Informat:
“TIMEw. Informat” on page 1120
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
optionally specifies the number of digits to the right of the decimal point in the hour
value. Therefore, SAS prints decimal fractions of the hour.
Requirement: must be less than w
Range: 0-19
Details
SAS rounds hours based on the value of minutes in the SAS time value.
Examples
The example table uses the input value of 41400, which is the SAS time value that
corresponds to 11:30 AM.
When the SAS Statement is ...
The Result is ...
----+----1
put time hour4.1;
11.5
162
IBw.d Format
4
Chapter 3
See Also
Formats:
“HHMMw.d Format” on page 159
“MMSSw.d Format” on page 172
“TIMEw.d Format” on page 221
“TODw.d Format” on page 224
Functions:
“HMS Function” on page 610
“HOUR Function” on page 611
“MINUTE Function” on page 684
“SECOND Function” on page 880
“TIME Function” on page 922
Informat:
“TIMEw. Informat” on page 1120
IBw.d Format
Writes native integer binary (fixed-point) values, including negative values
Numeric
Alignment: left
Category:
See:
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
optionally specifies to multiply the number by 10 .
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
Formats
4
IBRw.d Format
163
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 77. 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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
Examples
y=put(x,ib4.);
put y $hex8.;
When x = ...
128
The Result on Big Endian Platforms*
is ...
The Result on Little Endian Platforms* is
...
----+----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 163
IBRw.d Format
Writes integer binary (fixed-point) values in Intel and DEC formats
Category: Numeric
Alignment:
left
164
IBRw.d Format
4
Chapter 3
Syntax
IBRw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range:
1–8
d
d
optionally specifies to multiply the number by 10 .
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 77. 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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
Examples
y=put(x,ibr4.);
put y $hex8.;
Formats
When x = ...
4
IEEEw.d Format
165
The Result* is ...
----+----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.
See Also
Format:
“IBw.d Format” on page 162
IEEEw.d Format
Generates an IEEE floating-point value by multiplying a number by 10 raised to the dth power
Category: 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 IEEE informat.
Syntax
IEEEw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 3–8
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.
Tip:
d
d
optionally specifies to multiply the number by 10 .
Default: 0
Range: 0–10
166
JULDAYw. Format
4
Chapter 3
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.
Examples
test1=put(x,ieee4.);
put test1 $hex8.;
test2=put(x,ieee5.);
put test2 $hex10.;
When x = ...
The Result* is ...
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
Formats
4
JULIANw. Format
167
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.
When the SAS Statement is ...
The Result is ...
----+----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
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.
Tip:
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.
168
MINGUOw. Format
4
Chapter 3
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).
When the SAS Statement is ...
The Result is ...
----+----1
put date julian5.;
05358
put date julian7.;
2005358
See Also
Functions:
“DATEJUL Function” on page 501
“JULDATE Function” on page 646
Informat:
“JULIANw. Informat” on page 1073
MINGUOw. Format
Writes date values as Taiwanese dates in the form yyymmdd
Date and Time
Alignment: left
See: The MINGUO format in SAS National Language Support (NLS): User’s Guide
Category:
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
169
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.
When the SAS Statement is ...
The Result is ...
----+----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
170
MMDDYYxw. Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYw. Format” on page 126
“MMDDYYxw. Format” on page 170
“YYMMDDw. Format” on page 244
Functions:
“DAY Function” on page 503
“MDY Function” on page 680
“MONTH Function” on page 695
“YEAR Function” on page 991
Informats:
“DATEw. Informat” on page 1060
“DDMMYYw. Informat” on page 1062
“YYMMDDw. Informat” on page 1128
MMDDYYxw. Format
Writes date values in the form mmdd<yy>yy or mmXddX<yy>yy, where X represents a specified
separator and the year appears as 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
171
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 16731, which is the SAS date value
that corresponds to October 22, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put day mmddyyc5.;
10:22
put day mmddyyd8.;
10-22-05
put day mmddyyp10.;
10.22.2005
put day mmddyyn8.;
10222005
172
MMSSw.d Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYxw. Format” on page 128
“MMDDYYw. Format” on page 168
“YYMMDDxw. Format” on page 246
Functions:
“DAY Function” on page 503
“MDY Function” on page 680
“MONTH Function” on page 695
“YEAR Function” on page 991
Informat:
“MMDDYYw. Informat” on page 1074
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
optionally specifies the number of digits to the right of the decimal point in the
seconds value. Therefore, the SAS time value includes fractional seconds.
Range:
0–19
Restriction:
must be less than w
Examples
The example table uses the input value of 4530.
Formats
When the SAS Statement is ...
4
MMYYw. Format
173
The Result is ...
----+----1
put time mmss.;
75:30
See Also
Formats:
“HHMMw.d Format” on page 159
“TIMEw.d Format” on page 221
Functions:
“HMS Function” on page 610
“MINUTE Function” on page 684
“SECOND Function” on page 880
Informat:
“TIMEw. Informat” on page 1120
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
174
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.
When the SAS Statement is ...
The Result is ...
----+----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 174
“YYMMw. Format” on page 240
MMYYxw. Format
Writes date values in the form mm<yy>yy or mmX<yy>yy, where X represents a specified
separator and the year appears as either 2 or 4 digits
Date and Time
Alignment: right
Category:
Syntax
MMYYxw.
Formats
4
MMYYxw. Format
175
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.
176
4
MONNAMEw. Format
Chapter 3
Examples
The following examples use the input value of 16631, which is the SAS date value
that corresponds to July14, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date mmyyc5.;
07:05
put date mmyyd.;
07-2005
put date mmyyn4.;
0705
put date mmyyp8.;
put date mmyys10.;
07.2005
07/2005
See Also
Format:
“MMYYw. Format” on page 173
“YYMMxw. Format” on page 242
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.
Formats
4
MONTHw. Format
Examples
The example table uses the input value of 16500, which is the SAS date value that
corresponds to March 5, 2005.
When the SAS Statement is ...
The Result is ...
----+----1
put date monname1.;
M
put date monname3.;
Mar
put date monname5.;
March
See Also
Format:
“MONTHw. Format” on page 177
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 hex value.
Details
The MONTHw. format writes the month (1 through 12) of the year from a SAS date
value.
Examples
The example table uses the input value of 17045, which is the SAS date value that
corresponds to September 01, 2006.
177
178
MONYYw. Format
4
Chapter 3
When the SAS statement is ...
The result is ...
----+----1
put date month.;
9
See Also
Format:
“MONNAMEw. Format” on page 176
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.
When the SAS Statement is ...
The Result is ...
----+----1
put date monyy5.;
DEC05
put date monyy7.;
DEC2005
See Also
Formats:
“DTMONYYw. Format” on page 135
“DDMMYYw. Format” on page 126
“MMDDYYw. Format” on page 168
“YYMMDDw. Format” on page 244
Functions:
“MONTH Function” on page 695
“YEAR Function” on page 991
Informat:
“MONYYw. Informat” on page 1076
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
179
180
NEGPARENw.d Format
4
Chapter 3
d
optionally specifies the number of digits to the right of the decimal point in the
numeric value.
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 right 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 negparen6.;
When sales = ...
The result is ...
----+----1----+
100
100
1000
1,000
-200
(200)
-2000
-2,000
Formats
4
NLDATEWw. Format
181
NENGOw. Format
Writes date values as Japanese dates in the form e.yymmdd
Category: Date and Time
left
The NENGO format in SAS National Language Support (NLS): User’s Guide
Alignment:
See:
NLDATEw. Format
Converts a SAS date value to the date value of the specified locale and then writes the value in
the format of date
Category: Date and Time
See:
The NLDATE format in SAS National Language Support (NLS): User’s Guide
NLDATEMNw. Format
Converts a SAS date value to the date value of the specified locale and then writes the date value
in the format of name of month
Date and Time
See: The NLDATEMN format in SAS National Language Support (NLS): User’s Guide
Category:
NLDATEWw. Format
Converts a SAS date value to the date value of the specified locale, and then writes the date value
in the format of the date and the day of week
Date and Time
See: The NLDATEW format in SAS National Language Support (NLS): User’s Guide
Category:
182
NLDATEWNw. Format
4
Chapter 3
NLDATEWNw. Format
Converts the SAS date value to the date value of the specified locale and then writes the date
value in the format of the name of day of week
Category:
See:
Date and Time
The NLDATEWN format in SAS National Language Support (NLS): User’s Guide
NLDATMw. Format
Converts a SAS datetime value to the datetime value of the specified locale and then writes the
value in the format of datetime
Date and Time
See: The NLDATM format in SAS National Language Support (NLS): User’s Guide
Category:
NLDATMAPw. Format
Converts a SAS datetime value to the datetime value of the specified locale and then writes the
value in the format of datetime with a.m. or p.m.
Date and Time
See: The NLDATMAP format in SAS National Language Support (NLS): User’s Guide
Category:
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 in the format of time of day
Date and Time
The NLDATMTM format in SAS National Language Support (NLS): User’s Guide
Category:
See:
Formats
4
NLNUMw.d Format
183
NLDATMWw. Format
Converts a SAS date value to a datetime value of the specified locale and then writes the value in
the format of day of week and datetime
Category: Date and Time
See:
The NLDATMW format in SAS National Language Support (NLS): User’s Guide
NLMNYw.d Format
Writes the monetary format of the local expression in the specified locale using local currency
Numeric
See: The NLMNY format in SAS National Language Support (NLS): User’s Guide
Category:
NLMNYIw.d Format
Writes the monetary format of the international expression in the specified locale
Category:
See:
Numeric
The NLMNYI format in SAS National Language Support (NLS): User’s Guide
NLNUMw.d Format
Writes the numeric format of the local expression in the specified locale
Numeric
The NLNUM format in SAS National Language Support (NLS): User’s Guide
Category:
See:
184
NLNUMIw.d Format
4
Chapter 3
NLNUMIw.d Format
Writes the numeric format of the international expression in the specified locale
Numeric
See: The NLNUMI format in SAS National Language Support (NLS): User’s Guide
Category:
NLPCTw.d Format
Writes percentage data of the local expression in the specified locale
Category:
See:
Numeric
The NLPCT format in SAS National Language Support (NLS): User’s Guide
NLPCTIw.d Format
Writes percentage data of the international expression in the specified locale
Numeric
The NLPCTI format in SAS National Language Support (NLS): User’s Guide
Category:
See:
NLTIMAPw. Format
Converts a SAS time value to the time value of a specified locale and then writes the value in the
format of a time value with a.m. or p.m.
Category:
See:
Date and Time
The NLTIMAP format in SAS National Language Support (NLS): User’s Guide
Formats
4
NUMXw.d Format
185
NLTIMEw. Format
Converts a SAS time value to the time value of the specified locale and then writes the value in
the format of time
Category: Date and Time
See:
The NLTIME format in SAS National Language Support (NLS): User’s Guide
NUMXw.d Format
Writes numeric values with a comma in place of the decimal point
Category: Numeric
Alignment:
right
Syntax
NUMXw.d
Syntax Description
w
specifies the width of the output field.
Default: 12
Range: 1–32
d
optionally specifies the number of digits to the right of the decimal point (comma) in
the numeric value.
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.
186
OCTALw. Format
4
Chapter 3
Examples
put x numx10.2;
When x = ...
The Result is ...
----+----1----+
896.48
896,48
64.89
64,89
3064.10
3064,10
See Also
Format:
“w.d Format” on page 227
Informat:
“NUMXw.d Informat” on page 1081
OCTALw. Format
Converts numeric values to octal representation
Category:
Numeric
Alignment:
left
Syntax
OCTALw.
Syntax Description
w
specifies the width of the output field.
Default: 3
Range:
1–24
Formats
4
PDw.d Format
187
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.;
When x = ...
The Result is ...
----+----1
3592
007010
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
optionally specifies to multiply the number by 10 .
Default: 0
Range: 0–31
188
PDJULGw. Format
4
Chapter 3
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 kind of operating environment that you use to run SAS.
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.;
When x = ...
The Result* is ...
----+----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.
PDJULGw. Format
Writes packed Julian date values in the hexadecimal format yyyydddF for IBM
Category:
Date and Time
Syntax
PDJULGw.
Formats
4
PDJULGw. Format
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
When the SAS Statement is ...
The Result is ...
----+----1
date = ’17mar2005’d;
juldate = put(date,pdjulg4.);
put juldate $hex8.;
2005076F
189
190
PDJULIw. Format
4
Chapter 3
See Also
Formats:
“PDJULIw. Format” on page 190
“JULIANw. Format” on page 167
“JULDAYw. Format” on page 166
Functions:
“JULDATE Function” on page 646
“DATEJUL Function” on page 501
Informats:
“PDJULIw. Informat” on page 1086
“PDJULGw. Informat” on page 1085
“JULIANw. Informat” on page 1073
System Option:
“YEARCUTOFF= System Option” on page 1760
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
Formats
4
PDJULIw. Format
191
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.
Note: SAS interprets a two-digit year as belonging to the 100-year span that is
defined by the YEARCUTOFF= system option. 4
Examples
When the SAS Statement is ...
The Result is ...
----+----1
date = ’17mar2005’d;
juldate = put(date,pdjuli4.);
put juldate $hex8.;
0105076F
date = ’31dec2003’d;
juldate = put(date,pdjuli4.);
put juldate $hex8.;
0103365F
192
PERCENTw.d Format
4
Chapter 3
See Also
Formats:
“PDJULGw. Format” on page 188
“JULIANw. Format” on page 167
“JULDAYw. Format” on page 166
Functions:
“DATEJUL Function” on page 501
“JULDATE Function” on page 646
Informats:
“PDJULGw. Informat” on page 1085
“PDJULIw. Informat” on page 1086
“JULIANw. Informat” on page 1073
System Option:
“YEARCUTOFF= System Option” on page 1760
PERCENTw.d Format
Writes numeric values as percentages
Category:
Numeric
Alignment:
right
Syntax
PERCENTw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range:
4–32
d
optionally 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
PERCENTNw.d Format
193
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. The PERCENTw.d format allows room for a
percent sign and parentheses, even if the value is not negative.
Examples
put @10 gain percent10.;
When gain = ...
The Result is ...
----+----1----+----2
0.1
10%
1.2
120%
-0.05
(
5%)
PERCENTNw.d Format
Produces percentages, using a minus sign for negative values.
Category: Numeric
Alignment:
right
Syntax
PERCENTNw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 4-32
d
optionally 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.
194
4
PIBw.d Format
Chapter 3
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. The PERCENTNw.d format allows
room for a percent sign and a minus sign, even if the value is not negative.
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 192
PIBw.d Format
Writes positive integer binary (fixed-point) values
Category:
Alignment:
See:
Numeric
left
PIBw.d Format in the documentation for your operating environment.
Syntax
PIBw.d
Formats
4
PIBw.d Format
195
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–8
d
d
optionally specifies to multiply the number by 10 .
Default: 0
Range: 0–10
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 77. 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. This 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
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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
196
PIBRw.d Format
4
Chapter 3
Examples
y=put(x,pib1.);
put y $hex2.;
When x = ...
The Result* is ...
----+----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 196
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
optionally specifies to multiply the number by 10 .
Default: 0
Range:
0–10
Formats
4
PIBRw.d Format
197
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 77. 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. This 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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
Examples
y=put(x,pibr2.);
put y $hex4.;
When x = ...
The Result* is ...
----+----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 1090
198
PKw.d Format
4
Chapter 3
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
optionally specifies to multiply the number by 10 .
Default: 0
Range:
1–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.;
When x = ...
The Result* is ...
----+----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.
Formats
4
PVALUEw.d Format
PVALUEw.d Format
Writes p-values
Category: Numeric
Alignment:
right
Syntax
PVALUEw.d
Syntax Description
w
specifies the width of the output field.
Default: 6
Range: 3–32
d
optionally specifies the number of digits to the right of the decimal point in the
numeric value.
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
199
200
4
QTRw. Format
Chapter 3
Examples
put x pvalue6.4;
When x = ...
The Result is ...
----+----1
.05
0.0500
0.000001
<.0001
0
<.0001
.0123456
0.0123
QTRw. Format
Writes date values as the quarter of the year
Category:
Alignment:
Syntax
QTRw.
Date and Time
right
Formats
4
QTRRw. Format
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.
When the SAS Statement is ...
The Result is ...
----+----1
put date qtr.;
1
See Also
Format:
“QTRRw. Format” on page 201
QTRRw. Format
Writes date values as the quarter of the year in Roman numerals
Category: Date and Time
Alignment:
Syntax
QTRRw.
right
201
202
RBw.d Format
4
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 3
3–32
Range:
Examples
The example table uses the input value of 16694, which is the SAS date value that
corresponds to September 15, 2005.
When the SAS Statement is ...
The Result is ...
----+----1
put date qtrr.;
III
See Also
Format:
“QTRw. Format” on page 200
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
Formats
4
RBw.d Format
203
d
d
optionally specifies to multiply the number by 10 .
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 kind 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
COBOL
COMP-1
COMP-2
IBM 370 assembler
E
D
Examples
y=put(x,rb8.);
put y $hex16.;
When x = ...
The Result* is ...
----+---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.
204
ROMANw. Format
4
Chapter 3
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
2–32
Range:
Details
The ROMANw. format truncates a floating-point value to its integer component before
the value is written.
Examples
put @5 year roman10.;
When year = ...
The Result is ...
1998
MCMXCVIII
S370FFw.d Format
Writes native standard numeric data in IBM mainframe format
Category:
Numeric
Syntax
S370FFw.d
Formats
4
S370FFw.d Format
205
Syntax Description
w
specifies the width of the output field.
Default: 12
Range: 1–32
d
optionally specifies the power of 10 by which to divide the value.
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.;
When x= ...
The Result* is ...
----+----1
12345
F1F2F3F4F5
* The result is the hexadecimal representation for the integer.
See Also
Formats:
“$EBCDICw. Format” on page 99
“w.d Format” on page 227
206
S370FIBw.d Format
4
Chapter 3
S370FIBw.d Format
Writes integer binary (fixed-point) values, including negative values, in IBM mainframe format
Category:
Numeric
Alignment:
left
Syntax
S370FIBw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range:
1–8
d
d
optionally specifies to multiply the number by 10 .
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 77. 4
Comparisons
3 If you use SAS on an IBM mainframe, S370FIBw.d and IBw.d are identical.
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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
Formats
4
S370FIBUw.d Format
207
Examples
y=put(x,s370fib4.);
put y $hex8.;
When x = ...
The Result* is ...
----+----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 207
“S370FPIBw.d Format” on page 211
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
optionally specifies to multiply the number by 10 .
Default: 0
Range: 0–10
208
4
S370FIBUw.d Format
Chapter 3
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 77. 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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
Examples
y=put(x,s370fibu1.);
put y $hex2.;
When x = ...
The Result* is ...
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 206
“S370FPIBw.d Format” on page 211
Formats
4
S370FPDw.d Format
209
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
optionally specifies to multiply the number by 10 .
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
210
S370FPDUw.d Format
4
Chapter 3
Examples
y=put(x,s370fpd4.);
put y $hex8.;
When x = ...
The Result* is ...
----+----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
optionally specifies to multiply the number by 10 .
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.
Formats
4
S370FPIBw.d Format
211
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.
Examples
y=put(x,s370fpdu2.);
put y $hex4.;
When x = ...
The Result* is ...
123
123F
-123
123F
* The result is a hexadecimal representation of a binary number written in packed decimal format.
Each two hexadecimal digits 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
optionally specifies to multiply the number by 10 .
Default: 0
Range: 0–10
212
S370FPIBw.d Format
4
Chapter 3
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.
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 77. 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 78.
To view a table that compares integer binary notation in several programming
languages, see Table 3.2 on page 78.
Examples
y=put(x,s370fpib1.);
put y $hex2.;
When x = ...
The Result* is ...
----+----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 206
“S370FIBUw.d Format” on page 207
Formats
4
S370FRBw.d Format
213
S370FRBw.d Format
Writes real binary (floating-point) data in IBM mainframe format
Category: Numeric
Alignment:
left
Syntax
S370FRBw.d
Syntax Description
w
specifies the width of the output field.
Default: 4
Range: 2–8
d
d
optionally specifies to multiply the number by 10 .
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
214
S370FZDw.d Format
4
Chapter 3
Examples
y=put(x,s370frb6.);
put y $hex8.;
When x = ...
The Result* is ...
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.
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
Formats
4
S370FZDw.d Format
215
d
d
optionally specifies to multiply the number by 10 .
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.;
When x = ...
The Result* is ...
123
F1F2C3
-123
F1F2D3
* 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.
216
S370FZDLw.d Format
4
Chapter 3
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
optionally specifies to multiply the number by 10 .
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.
Formats
4
S370FZDSw.d Format
217
Examples
y=put(x,s370fzdl3.);
put y $hex6.;
When x = ...
The Result* is ...
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
Category: Numeric
Alignment:
left
Syntax
S370FZDSw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 2–32
218
S370FZDTw.d Format
4
Chapter 3
d
d
optionally specifies to multiply the number by 10 .
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.;
When x = ...
The Result* is ...
123
4EF1F2F3
-123
60F1F2F3
* 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
Numeric
Alignment: left
Category:
Syntax
S370FZDTw.d
Syntax Description
w
specifies the width of the output field.
Formats
4
S370FZDUw.d Format
219
Default: 8
Range: 2–32
d
d
optionally specifies to multiply the number by 10 .
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.
Examples
y=put (x,s370fzdt4.); ;
put y $hex8.;
When x = ...
The Result* is
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
Category: Numeric
Alignment:
left
Syntax
S370FZDUw.d
220
4
SSNw. Format
Chapter 3
Syntax Description
w
specifies the width of the output field.
Default: 8
Range: 1–32
d
d
optionally specifies to multiply the number by 10 .
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.
Examples
y=put (x,s370fzdu3.);
put y $hex6.;
When x = ...
The Result* is ...
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 digits (such as F1) corresponds to one byte
of binary data, and each byte corresponds to one column of the output field.
SSNw. Format
Writes Social Security numbers
Category:
Alignment:
Syntax
SSNw.
Numeric
none
Formats
4
TIMEw.d Format
221
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.;
When id = ...
The Result is ...
----+----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
222
TIMEw.d Format
4
Chapter 3
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: 8 spaces to the
left of the decimal point, 1 space for the decimal point itself, and 3 spaces for the
decimal fraction of seconds.
Tip:
d
optionally specifies the number of digits to the right of the decimal point in the
seconds value.
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.
Examples
The example table uses the input value of 59083, which is the SAS time value that
corresponds to 4:24:43 PM.
When the SAS Statement is ...
The Result is ...
----+----1
put begin time.;
See Also
Formats:
“HHMMw.d Format” on page 159
“HOURw.d Format” on page 161
16:24:43
Formats
4
TIMEAMPMw.d Format
223
“MMSSw.d Format” on page 172
Functions:
“HOUR Function” on page 611
“MINUTE Function” on page 684
“SECOND Function” on page 880
“TIME Function” on page 922
Informat:
“TIMEw. Informat” on page 1120
TIMEAMPMw.d Format
Writes time 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
optionally specifies the number of digits to the right of the decimal point in the
seconds value.
Default: 0
Range: 0–19
Requirement: must be less than w
Details
The TIMEAMPMw.d format writes SAS time 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.
ss.ss
is the number of seconds to two decimal places.
224
TODw.d Format
4
Chapter 3
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 PM.
When the SAS Statement is ...
The Result is ...
----+----1----+
put begin timeampm3.;
PM
put begin timeampm5.;
4 PM
put begin timeampm7.;
put begin timeampm11.;
4:24 PM
4:24:43 PM
See Also
Format:
“TIMEw.d Format” on page 221
TODw.d Format
Writes the time portion of datetime values in the form hh:mm:ss.ss
Category:
Alignment:
Date and Time
right
Syntax
TODw.d
Syntax Description
w
specifies the width of the output field.
Formats
4
TODw.d Format
Default: 8
Range: 2–20
d
optionally specifies the number of digits to the right of the decimal point in the
seconds value.
Default: 0
Range: 0–19
Requirement:
must be less than w
Details
The TODw.d format writes SAS 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.
Examples
The example table uses the input value of 1472049623, which is the SAS datetime
value that corresponds to August 24, 2006, at 2:20:23 PM.
When the SAS Statement is ...
The Result is ...
----+----1
put begin tod9.2;
14:20:23
See Also
Formats:
“TIMEw.d Format” on page 221
“TIMEAMPMw.d Format” on page 223
Function:
“TIMEPART Function” on page 923
Informat:
“TIMEw. Informat” on page 1120
225
226
VAXRBw.d Format
4
Chapter 3
VAXRBw.d Format
Writes real binary (floating-point) data in VMS format
Category:
Numeric
Alignment:
right
Syntax
VAXRBw.d
Syntax Description
w
specifies the width of the output field.
Default: 8
Range:
2-8
d
optionally specifies the power of 10 by which to divide the value.
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.;
When x= ...
The result* is ...
----+----1
1
8040000000000000
* The result is the hexadecimal representation for the integer.
Formats
4
w.d Format
227
w.d Format
Writes standard numeric data one digit per byte
Category: Numeric
Alignment:
Alias:
See:
right
Fw.d
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
Allow enough space to write the value, the decimal point, and a minus sign, if
necessary.
Tip:
d
optionally specifies the number of digits to the right of the decimal point in the
numeric value.
Range: 0–31
must be less than w
If d is 0 or you omit d, w.d writes the value without a decimal point.
Requirement:
Tip:
Details
The w.d format rounds to the nearest number that fits in the output field. If w.d is too
small, SAS may 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.
228
WEEKDATEw. 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 @7 x 6.3;
When x = ...
The Result is ...
----+----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)
Category:
Date and Time
Alignment:
right
Syntax
WEEKDATEw.
Syntax Description
w
specifies the width of the output field.
Default: 29
Range:
3–37
Formats
4
WEEKDATEw. Format
229
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.
When the SAS Statement is ...
The Result is ...
----+----1----+----2
put date weekdate3.;
put date weekdate9.;
Tue
Tuesday
put date weekdate15.;
Tue, Jun 14, 05
put date weekdate17.;
Tue, Jun 14, 2005
230
WEEKDATXw. Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYw. Format” on page 126
“MMDDYYw. Format” on page 168
“TODw.d Format” on page 224
“WEEKDATXw. Format” on page 230
“YYMMDDw. Format” on page 244
Functions:
“JULDATE Function” on page 646
“MDY Function” on page 680
“WEEKDAY Function” on page 991
Informats:
“DATEw. Informat” on page 1060
“DDMMYYw. Informat” on page 1062
“MMDDYYw. Informat” on page 1074
“YYMMDDw. Informat” on page 1128
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
Formats
4
WEEKDATXw. Format
231
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.
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
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.
When the SAS statement is ...
The result is ...
----+----1----+----2----+----3
put date weekdatx.;
Wednesday, 23 February 2005
See Also
Formats:
“DTWKDATXw. Format” on page 136
“DATEw. Format” on page 121
“DDMMYYw. Format” on page 126
“MMDDYYw. Format” on page 168
“TODw.d Format” on page 224
“WEEKDATEw. Format” on page 228
“YYMMDDw. Format” on page 244
Functions:
“JULDATE Function” on page 646
“MDY Function” on page 680
“WEEKDAY Function” on page 991
232
WEEKDAYw. Format
4
Chapter 3
Informats:
“DATEw. Informat” on page 1060
“DDMMYYw. Informat” on page 1062
“MMDDYYw. Informat” on page 1074
“YYMMDDw. Informat” on page 1128
WEEKDAYw. Format
Writes date values as the day of the week
Date and Time
Alignment: right
Category:
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.
When the SAS Statement is ...
The Result is ...
----+----1
put date weekday.;
4
Formats
4
WEEKWw. Format
233
See Also
Format:
“DOWNAMEw. Format” on page 133
WEEKUw. Format
Writes a week number in decimal format by using the U algorithm
Date and Time
See: The WEEKU format in SAS National Language Support (NLS): User’s Guide
Category:
WEEKVw. Format
Writes a week number in decimal format by using the V algorithm
Date and Time
The WEEKV“WEEKVw. Informat” on page 1127 format in SAS National
Language Support (NLS): User’s Guide
Category:
See:
WEEKWw. Format
Reads the format of the number-of-week value within the year and returns a SAS-date value using
the W algorithm
Date and Time
See: The WEEKW format in SAS National Language Support (NLS): User’s Guide
Category:
234
WORDDATEw. Format
4
Chapter 3
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.
Formats
4
WORDDATXw. Format
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.
When the SAS Statement is ...
The Result is ...
----+----1----+----2
put term worddate3.;
Jun
put term worddate9.;
put term worddate12.;
June
Jun 14, 2005
put term worddate20.;
June 14, 2005
See Also
Format:
“WORDDATXw. Format” on page 235
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.
235
236
4
WORDDATXw. Format
Chapter 3
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.
When the SAS Statement is ...
The Result is ...
----+----1----+----2
put term worddatx.;
See Also
Format:
“WORDDATEw. Format” on page 234
05 March 2005
Formats
4
WORDFw. Format
237
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.;
When price = ...
The Result is ...
----+----1----+
2.5
two and 50/100
238
WORDSw. Format
4
Chapter 3
See Also
Format:
“WORDSw. Format” on page 238
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.
Formats
4
YEARw. Format
Examples
put price words23.;
When price = ...
The Result is ...
----+----1----+----2----+
2.1
two and ten hundredths
See Also
Format:
“WORDFw. Format” on page 237
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
Tip: If w is less than 4, the last two digits of the year print; otherwise, the year
value prints as four digits.
239
240
4
YENw.d Format
Chapter 3
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.
When the SAS Statement is ...
The Result is ...
----+----1
put date year2.;
05
put date year4.;
2005
See Also
Format:
“DTYEARw. Format” on page 137
YENw.d Format
Writes numeric values with yen signs, commas, and decimal points
Numeric
Alignment: right
Category:
See:
The YEN format in SAS National Language Support (NLS): User’s Guide
YYMMw. Format
Writes date values in the form <yy>yyMmm, where M is the separator and the year appears as
either 2 or 4 digits
Category:
Alignment:
Date and Time
right
Formats
4
YYMMw. Format
241
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.
mm
is an integer that represents the month.
Examples
The following examples use the input value of 16734, which is the SAS date value
that corresponds to October 25, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date yymm5.;
put date yymm6.;
05M10
05M10
put date yymm.;
2005M10
put date yymm7.;
2005M10
put date yymm10.;
2005M10
242
YYMMxw. Format
4
Chapter 3
See Also
Format:
“MMYYw. Format” on page 173
“YYMMxw. Format” on page 242
YYMMxw. Format
Writes date values in the form <yy>yymm or <yy>yyXmm, where X represents a specified
separator and the year appears as 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
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a forward slash.
Formats
4
YYMMxw. Format
243
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 16631, which is the SAS date value
that corresponds to July 14, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date yymmc5.;
05:07
put date yymmd.;
2005-07
put date yymmn4.;
0507
put date yymmp8.;
put date yymms10.;
2005.07
2005/07
244
YYMMDDw. Format
4
Chapter 3
See Also
Format:
“MMYYxw. Format” on page 174
“YYMMw. Format” on page 240
YYMMDDw. Format
Writes date values in the form <yy>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.
Formats
4
YYMMDDw. Format
Details
The YYMMDDw. format writes SAS date values in the form <yy>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.
Examples
The following examples use the input value of 16529, which is the SAS date value
that corresponds to April 3, 2005.
When the SAS Statement is ...
The Result is ...
----+----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
245
246
YYMMDDxw. Format
4
Chapter 3
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYw. Format” on page 126
“MMDDYYw. Format” on page 168
“YYMMDDxw. Format” on page 246
Functions:
“DAY Function” on page 503
“MDY Function” on page 680
“MONTH Function” on page 695
“YEAR Function” on page 991
Informats:
“DATEw. Informat” on page 1060
“DDMMYYw. Informat” on page 1062
“MMDDYYw. Informat” on page 1074
YYMMDDxw. Format
Writes date values in the form <yy>yymmdd or <yy>yyXmmXdd, where X represents a specified
separator and the year appears as either 2 or 4 digits
Category:
Alignment:
Date and Time
right
Syntax
YYMMDDxw.
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
Formats
4
YYMMDDxw. Format
247
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 <yy>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.
248
YYMMDDxw. Format
4
Chapter 3
Examples
The following examples use the input value of 16731, which is the SAS date value
that corresponds to October 22, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put day yymmddc5.;
05:10
put day yymmddd8.;
05-10-22
put day yymmddp10.;
2005.10.22
put day yymmddn8.;
20051022
See Also
Formats:
“DATEw. Format” on page 121
“DDMMYYxw. Format” on page 128
“MMDDYYxw. Format” on page 170
“YYMMDDw. Format” on page 244
Functions:
“DAY Function” on page 503
“MDY Function” on page 680
“MONTH Function” on page 695
“YEAR Function” on page 991
Informat:
“YYMMDDw. Informat” on page 1128
Formats
4
YYMONw. Format
YYMONw. Format
Writes date values in the form yymmm or yyyymmm
Category: Date and Time
Alignment:
right
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
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.
When the SAS Statement is ...
The Result is ...
----+----1
put date yymon6.;
05JUN
put date yymon7.;
2005JUN
See Also
Format:
“MMYYw. Format” on page 173
249
250
YYQw. Format
4
Chapter 3
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.
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.
Formats
4
YYQxw. Format
251
Examples
The following examples use the input value of 16601, which is the SAS date value
that corresponds to June 14, 2005.
When the SAS Statement is ...
The Result is ...
----+----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 251
“YYQRw. Format” on page 253
YYQxw. Format
Writes date values in the form <yy>yyq or <yy>yyXq, where X represents a specified 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
YYQxw.
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
252
4
YYQxw. Format
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: 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 16631, which is the SAS date value
that corresponds to July 14, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date yyqc4.;
05:3
put date yyqd.;
2005-3
put date yyqn3.;
053
put date yyqp6.;
2005.3
put date yyqs8.;
2005/3
Formats
4
YYQRw. Format
253
See Also
Formats:
“YYQw. Format” on page 250
“YYQRxw. Format” on page 254
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
Category: Date and Time
Alignment: right
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.
Examples
The following examples use the input value of 16601, which is the SAS date value
that corresponds to June 14, 2005.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date yyqr6.;
05QII
put date yyqr7.;
2005QII
254
YYQRxw. Format
4
Chapter 3
When the SAS Statement is ...
The Result is ...
put date yyqr.;
2005QII
put date yyqr8.;
2005QII
put date yyqr10.;
2005QII
See Also
Format:
“YYQw. Format” on page 250
“YYQRxw. Format” on page 254
YYQRxw. Format
Writes date values in the form <yy>yyqr or <yy>yyXqr, where X represents a specified separator,
the year appears as 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
D
separates with a dash
N
indicates no separator
P
separates with a period
S
separates with a forward slash.
Formats
4
YYQRxw. Format
255
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 16431, which is the SAS date value
that corresponds to December 24, 2004.
When the SAS Statement is ...
The Result is ...
----+----1----+
put date yyqrc6.;
04:IV
put date yyqrd.;
2004-IV
put date yyqrn5.;
04IV
put date yyqrp8.;
2004.IV
put date yyqrs10.;
See Also
Format:
“YYQxw. Format” on page 251
“YYQRw. Format” on page 253
2004/IV
256
Zw.d Format
4
Chapter 3
Zw.d Format
Writes standard numeric data with leading 0s
Numeric
Alignment: right
Category:
Syntax
Zw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
1–32
Tip: Allow enough space to write the value, the decimal point, and a minus sign, if
necessary.
Range:
d
optionally specifies the number of digits to the right of the decimal point in the
numeric value.
Default: 0
0–31
If d is 0 or you omit d, Zw.d writes the value without a decimal point.
Range:
Tip:
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.
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.
Formats
4
ZDw.d Format
Examples
put @5 seqnum z8.;
When seqnum = ...
The Result is ...
----+----1
1350
00001350
ZDw.d Format
Writes numeric data in zoned decimal format
Category: Numeric
Alignment:
See:
left
ZDw.d Format in the documentation for your operating environment.
Syntax
ZDw.d
Syntax Description
w
specifies the width of the output field.
Default: 1
Range: 1–32
d
d
optionally specifies to multiply the number by 10 .
Default: 0
Range: 0–31
257
258
ZDw.d Format
4
Chapter 3
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 kind of operating environment that you use to run
SAS. 4
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.;
When x = ...
The Result* is ...
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.
259
CHAPTER
4
Functions and CALL Routines
Definitions of Functions and CALL Routines 268
Definition of Functions 268
Definition of CALL Routines 269
Syntax 269
Syntax of Functions 269
Syntax of CALL Routines 270
Using Functions 271
Restrictions on Function Arguments 271
Notes on Descriptive Statistic Functions 271
Notes on Financial Functions 271
Special Considerations for Depreciation Functions 272
Using DATA Step Functions within Macro Functions 272
Using Functions to Manipulate Files 273
Using Random-Number Functions and CALL Routines 273
Seed Values 273
Comparison of Random-Number Functions and CALL Routines 274
Examples 274
Example 1: Generating Multiple Streams from a CALL Routine 274
Example 2: Assigning Values from a Single Stream to Multiple Variables 275
Pattern Matching Using SAS Regular Expressions (RX) and Perl Regular Expressions (PRX)
Definition of Pattern Matching and Regular Expressions 276
Definition of SAS Regular Expression (RX) Functions and CALL Routines 276
Definition of Perl Regular Expression (PRX) Functions and CALL Routines 276
Benefits of Using Perl Regular Expressions in the DATA Step 277
Using Perl Regular Expressions in the DATA Step 277
License Agreement 277
Syntax of Perl Regular Expressions 278
Example 1: Validating Data 280
Example 2: Replacing Text 282
Example 3: Extracting a Substring from a String 283
Writing Perl Debug Output to the SAS Log 285
Base SAS Functions for Web Applications 286
Functions and CALL Routines by Category 286
Dictionary 310
ABS Function 310
ADDR Function 311
ADDRLONG Function 312
AIRY Function 313
ANYALNUM Function 314
ANYALPHA Function 316
ANYCNTRL Function 318
276
260
Contents
4
Chapter 4
ANYDIGIT Function 319
ANYFIRST Function 320
ANYGRAPH Function 322
ANYLOWER Function 324
ANYNAME Function 325
ANYPRINT Function 327
ANYPUNCT Function 329
ANYSPACE Function 330
ANYUPPER Function 332
ANYXDIGIT Function 333
ARCOS Function 335
ARSIN Function 335
ATAN Function 336
ATAN2 Function 337
ATTRC Function 338
ATTRN Function 340
BAND Function 344
BETA Function 345
BETAINV Function 346
BLSHIFT Function 347
BNOT Function 348
BOR Function 348
BRSHIFT Function 349
BXOR Function 350
BYTE Function 350
CALL ALLPERM Routine 351
CALL CATS Routine 353
CALL CATT Routine 355
CALL CATX Routine 356
CALL COMPCOST Routine 358
CALL EXECUTE Routine 361
CALL LABEL Routine 361
CALL LOGISTIC Routine 363
CALL MISSING Routine 364
CALL MODULE Routine 365
CALL MODULEI Routine 368
CALL POKE Routine 369
CALL POKELONG Routine 370
CALL PRXCHANGE Routine 371
CALL PRXDEBUG Routine 373
CALL PRXFREE Routine 375
CALL PRXNEXT Routine 376
CALL PRXPOSN Routine 378
CALL PRXSUBSTR Routine 381
CALL RANBIN Routine 383
CALL RANCAU Routine 385
CALL RANEXP Routine 387
CALL RANGAM Routine 389
CALL RANNOR Routine 391
CALL RANPERK Routine 392
CALL RANPERM Routine 394
CALL RANPOI Routine 395
CALL RANTBL Routine 397
CALL RANTRI Routine 399
Functions and CALL Routines
CALL RANUNI Routine 401
CALL RXCHANGE Routine 403
CALL RXFREE Routine 404
CALL RXSUBSTR Routine 405
CALL SCAN Routine 406
CALL SCANQ Routine 408
CALL SET Routine 410
CALL SLEEP Routine 412
CALL SOFTMAX Routine 413
CALL STDIZE Routine 414
CALL STREAMINIT Routine 418
CALL SYMPUT Routine 419
CALL SYMPUTX Routine 420
CALL SYSTEM Routine 422
CALL TANH Routine 423
CALL VNAME Routine 424
CALL VNEXT Routine 425
CAT Function 427
CATS Function 429
CATT Function 430
CATX Function 432
CDF Function 434
CEIL Function 448
CEILZ Function 449
CEXIST Function 450
CHOOSEC Function 451
CHOOSEN Function 452
CINV Function 453
CLOSE Function 455
CNONCT Function 456
COALESCE Function 458
COALESCEC Function 459
COLLATE Function 460
COMB Function 462
COMPARE Function 463
COMPBL Function 466
COMPGED Function 467
COMPLEV Function 472
COMPOUND Function 475
COMPRESS Function 476
CONSTANT Function 480
CONVX Function 484
CONVXP Function 485
COS Function 486
COSH Function 487
COUNT Function 488
COUNTC Function 490
CSS Function 491
CUROBS Function 492
CV Function 493
DACCDB Function 494
DACCDBSL Function 495
DACCSL Function 496
DACCSYD Function 497
4
Contents
261
262
Contents
4
Chapter 4
DACCTAB Function 498
DAIRY Function 499
DATDIF Function 499
DATE Function 501
DATEJUL Function 501
DATEPART Function 502
DATETIME Function 502
DAY Function 503
DCLOSE Function 504
DCREATE Function 505
DEPDB Function 506
DEPDBSL Function 507
DEPSL Function 508
DEPSYD Function 509
DEPTAB Function 511
DEQUOTE Function 512
DEVIANCE Function 515
DHMS Function 519
DIF Function 520
DIGAMMA Function 522
DIM Function 523
DINFO Function 524
DNUM Function 526
DOPEN Function 527
DOPTNAME Function 528
DOPTNUM Function 530
DREAD Function 531
DROPNOTE Function 532
DSNAME Function 533
DUR Function 534
DURP Function 535
ERF Function 536
ERFC Function 537
EUROCURR Function 538
EXIST Function 538
EXP Function 541
FACT Function 541
FAPPEND Function 542
FCLOSE Function 544
FCOL Function 545
FDELETE Function 547
FETCH Function 548
FETCHOBS Function 549
FEXIST Function 551
FGET Function 552
FILEEXIST Function 554
FILENAME Function 555
FILEREF Function 557
FIND Function 558
FINDC Function 560
FINFO Function 565
FINV Function 566
FIPNAME Function 567
FIPNAMEL Function 568
Functions and CALL Routines
FIPSTATE Function 569
FLOOR Function 571
FLOORZ Function 572
FNONCT Function 574
FNOTE Function 576
FOPEN Function 578
FOPTNAME Function 580
FOPTNUM Function 582
FPOINT Function 583
FPOS Function 584
FPUT Function 586
FREAD Function 587
FREWIND Function 588
FRLEN Function 590
FSEP Function 591
FUZZ Function 592
FWRITE Function 593
GAMINV Function 595
GAMMA Function 596
GEOMEAN Function 597
GEOMEANZ Function 598
GETOPTION Function 600
GETVARC Function 602
GETVARN Function 603
HARMEAN Function 605
HARMEANZ Function 606
HBOUND Function 608
HMS Function 610
HOUR Function 611
HTMLDECODE Function 612
HTMLENCODE Function 613
IBESSEL Function 615
IFC Function 616
IFN Function 618
INDEX Function 620
INDEXC Function 621
INDEXW Function 622
INPUT Function 624
INPUTC Function 626
INPUTN Function 628
INT Function 629
INTCK Function 630
INTNX Function 634
INTRR Function 639
INTZ Function 640
IORCMSG Function 642
IQR Function 644
IRR Function 645
JBESSEL Function 645
JULDATE Function 646
JULDATE7 Function 647
KCOMPARE Function 648
KCOMPRESS Function 649
KCOUNT Function 649
4
Contents
263
264
Contents
4
Chapter 4
KCVT Function 649
KINDEX Function 649
KINDEXC Function 650
KLEFT Function 650
KLENGTH Function 650
KLOWCASE Function 650
KREVERSE Function 651
KRIGHT Function 651
KSCAN Function 651
KSTRCAT Function 651
KSUBSTR Function 652
KSUBSTRB Function 652
KTRANSLATE Function 652
KTRIM Function 652
KTRUNCATE Function 653
KUPCASE Function 653
KUPDATE Function 653
KUPDATEB Function 653
KURTOSIS Function 654
KVERIFY Function 654
LAG Function 655
LARGEST Function 658
LBOUND Function 659
LEFT Function 661
LENGTH Function 662
LENGTHC Function 663
LENGTHM Function 664
LENGTHN Function 666
LGAMMA Function 667
LIBNAME Function 668
LIBREF Function 669
LOG Function 670
LOG10 Function 671
LOG2 Function 672
LOGBETA Function 672
LOGCDF Function 673
LOGPDF Function 675
LOGSDF Function 676
LOWCASE Function 677
MAD Function 678
MAX Function 679
MDY Function 680
MEAN Function 681
MEDIAN Function 682
MIN Function 683
MINUTE Function 684
MISSING Function 686
MOD Function 687
MODULEC Function 690
MODULEIC Function 691
MODULEIN Function 692
MODULEN Function 693
MODZ Function 694
MONTH Function 695
Functions and CALL Routines
MOPEN Function 696
MORT Function 699
N Function 700
NETPV Function 701
NLDATE Function 702
NLDATM Function 702
NLTIME Function 703
NLITERAL Function 703
NMISS Function 705
NORMAL Function 705
NOTALNUM Function 706
NOTALPHA Function 707
NOTCNTRL Function 709
NOTDIGIT Function 710
NOTE Function 712
NOTFIRST Function 713
NOTGRAPH Function 715
NOTLOWER Function 717
NOTNAME Function 718
NOTPRINT Function 720
NOTPUNCT Function 721
NOTSPACE Function 724
NOTUPPER Function 726
NOTXDIGIT Function 727
NPV Function 729
NVALID Function 730
OPEN Function 732
ORDINAL Function 734
PATHNAME Function 734
PCTL Function 736
PDF Function 737
PEEK Function 752
PEEKC Function 754
PEEKCLONG Function 757
PEEKLONG Function 758
PERM Function 760
POINT Function 761
POISSON Function 762
PROBBETA Function 763
PROBBNML Function 764
PROBBNRM Function 765
PROBCHI Function 766
PROBF Function 767
PROBGAM Function 768
PROBHYPR Function 769
PROBIT Function 770
PROBMC Function 771
PROBNEGB Function 782
PROBNORM Function 783
PROBT Function 784
PROPCASE Function 784
PRXCHANGE Function 787
PRXMATCH Function 791
PRXPAREN Function 795
4
Contents
265
266
Contents
4
Chapter 4
PRXPARSE Function 796
PRXPOSN Function 798
PTRLONGADD Function 802
PUT Function 803
PUTC Function 805
PUTN Function 807
PVP Function 809
QTR Function 810
QUANTILE Function 811
QUOTE Function 813
RANBIN Function 814
RANCAU Function 815
RAND Function 816
RANEXP Function 830
RANGAM Function 831
RANGE Function 832
RANK Function 833
RANNOR Function 834
RANPOI Function 835
RANTBL Function 836
RANTRI Function 837
RANUNI Function 838
REPEAT Function 839
RESOLVE Function 840
REVERSE Function 841
REWIND Function 842
RIGHT Function 843
RMS Function 844
ROUND Function 845
ROUNDE Function 853
ROUNDZ Function 855
RXMATCH Function 858
RXPARSE Function 859
SAVING Function 874
SCAN Function 875
SCANQ Function 876
SDF Function 878
SECOND Function 880
SIGN Function 881
SIN Function 882
SINH Function 883
SKEWNESS Function 884
SLEEP Function 885
SMALLEST Function 886
SOUNDEX Function 888
SPEDIS Function 889
SQRT Function 892
STD Function 893
STDERR Function 893
STFIPS Function 894
STNAME Function 895
STNAMEL Function 896
STRIP Function 898
SUBPAD Function 900
Functions and CALL Routines
SUBSTR (left of =) Function 901
SUBSTR (right of =) Function 903
SUBSTRN Function 904
SUM Function 908
SYMEXIST Function 909
SYMGET Function 910
SYMGLOBL Function 911
SYMLOCAL Function 912
SYSGET Function 913
SYSMSG Function 914
SYSPARM Function 915
SYSPROCESSID Function 916
SYSPROCESSNAME Function 917
SYSPROD Function 918
SYSRC Function 919
SYSTEM Function 920
TAN Function 921
TANH Function 922
TIME Function 922
TIMEPART Function 923
TINV Function 923
TNONCT Function 925
TODAY Function 926
TRANSLATE Function 927
TRANTAB Function 928
TRANWRD Function 929
TRIGAMMA Function 930
TRIM Function 931
TRIMN Function 933
TRUNC Function 934
UNIFORM Function 935
UPCASE Function 936
URLDECODE Function 937
URLENCODE Function 938
USS Function 939
UUIDGEN Function 940
VAR Function 941
VARFMT Function 942
VARINFMT Function 944
VARLABEL Function 945
VARLEN Function 946
VARNAME Function 948
VARNUM Function 949
VARRAY Function 950
VARRAYX Function 951
VARTRANSCODE Function 953
VARTYPE Function 953
VERIFY Function 955
VFORMAT Function 956
VFORMATD Function 957
VFORMATDX Function 958
VFORMATN Function 959
VFORMATNX Function 960
VFORMATW Function 962
4
Contents
267
268
Definitions of Functions and CALL Routines
4
Chapter 4
VFORMATWX Function 963
VFORMATX Function 964
VINARRAY Function 965
VINARRAYX Function 966
VINFORMAT Function 968
VINFORMATD Function 969
VINFORMATDX Function 970
VINFORMATN Function 971
VINFORMATNX Function 972
VINFORMATW Function 973
VINFORMATWX Function 974
VINFORMATX Function 975
VLABEL Function 977
VLABELX Function 978
VLENGTH Function 979
VLENGTHX Function 981
VNAME Function 982
VNAMEX Function 983
VTRANSCODE Function 984
VTRANSCODEX Function 985
VTYPE Function 985
VTYPEX Function 987
VVALUE Function 988
VVALUEX Function 989
WEEK Function 990
WEEKDAY Function 991
YEAR Function 991
YIELDP Function 992
YRDIF Function 993
YYQ Function 995
ZIPCITY Function 997
ZIPFIPS Function 998
ZIPNAME Function 999
ZIPNAMEL Function 1001
ZIPSTATE Function 1003
References 1005
Definitions of Functions and CALL Routines
Definition of Functions
A SAS function performs a computation or system manipulation on arguments and
returns a value. Most functions use arguments supplied by the user, but a few obtain
their arguments from the operating environment.
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.
Functions and CALL Routines
4
Syntax of Functions
269
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.
All SAS CALL routines are invoked with CALL statements; that is, the name of the
routine must appear after the keyword CALL on the CALL statement.
Syntax
Syntax of Functions
The syntax of a function is
function-name (argument-1< , ...argument-n>)
function-name (OF variable-list)
function-name (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 kind 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);
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);
270
Syntax of CALL Routines
4
Chapter 4
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);
array-name{*}
names a currently defined array. Specifying an array in this way causes SAS to
treat the array as a list of the variables instead of processing only one element of
the array at a time.
Examples:
3
array y{10} y1-y10;
x=sum(of y{*});
Syntax of CALL Routines
The syntax of a CALL routine is
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 kind of arguments that are allowed are described with
individual CALL routines in the dictionary section.
Examples:
3
call rxsubstr(rx,string,position);
3
call set(dsid);
3
call ranbin(Seed_1,n,p,X1);
3
call label(abc{j},lab);
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);
call catt(of item17-item23 pack17-pack23);
Functions and CALL Routines
4
Notes on Financial Functions
271
Using Functions
Restrictions on Function Arguments
If the value of an argument is invalid, SAS prints an error message and sets the
result to a missing value. Here are some common restrictions on 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 Most functions do not permit missing values as arguments. Exceptions include
some of the descriptive statistics functions and financial functions.
3 In general, the allowed range of the arguments is platform-dependent, such as
with the EXP function.
3 For some probability functions, combinations of extreme values can cause
convergence problems.
Notes on Descriptive Statistic Functions
SAS provides functions that return descriptive statistics. Except for the MISSING
function, the functions correspond to the statistics produced by the MEANS procedure.
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 on Financial Functions
SAS provides a group of functions that perform financial calculations. The functions
are grouped into the following types:
Table 4.1 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
INTRR, IRR
calculates the internal rate of return
Parameter calculations
Internal rate of return
272
Using DATA Step Functions within Macro Functions
4
Chapter 4
Function type
Functions
Description
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
Depreciation
Special Considerations for Depreciation Functions
The period argument for depreciation functions can be fractional for all of the
functions except DEPDBSL and DACCDBSL. For fractional arguments, the
depreciation is prorated between the two consecutive time periods preceding and
following the fractional period.
CAUTION:
Verify the depreciation method for fractional periods. You must verify whether this
method is appropriate to use with fractional periods because many depreciation
schedules, specified as tables, have special rules for fractional periods. 4
Using DATA Step Functions within Macro Functions
The macro functions %SYSFUNC and %QSYSFUNC can call 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 on 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(%)%(%’)));
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));
Functions and CALL Routines
4
Seed Values
273
You can use these functions to call all of the DATA step SAS functions except those
that pertain to DATA step variables or processing. These prohibited functions are: DIF,
DIM, HBOUND, INPUT, IORCMSG, LAG, LBOUND, MISSING, PUT, RESOLVE,
SYMGET, and all of the variable information functions (for example, VLABEL).
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.
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 286. For complete descriptions and examples, see the
dictionary section of this book.
Using Random-Number Functions and CALL Routines
Seed Values
Random-number functions and CALL routines generate streams of random numbers
from an initial starting point, called a seed, that either the user or the computer clock
31
supplies. A seed must be a nonnegative integer with a value less than 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 is not
replicable.
Each random-number function and CALL routine generates pseudo-random numbers
from a specific statistical distribution. Every random-number function requires a seed
value expressed as an integer constant or a variable that contains the integer constant.
Every CALL routine calls a variable that contains the seed value. Additionally, every
CALL routine requires a variable that contains the generated random numbers.
The seed variable must be initialized prior to 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. After each iteration
of the CALL routine, however, the seed variable contains the current seed in the stream
that generates the next random number. With a function, it is not possible to control
the seed values, and, therefore, the random numbers after the initialization.
274
Comparison of Random-Number Functions and CALL Routines
4
Chapter 4
Comparison of Random-Number Functions and CALL Routines
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. As an illustration of this control over seed values,
all the random-number CALL routines show an example of interrupting the stream of
random numbers to change the seed value.
With a CALL routine, you can generate multiple streams of 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 random numbers are computationally
independent. With a function, however, you cannot generate more than one stream by
supplying multiple seeds within a DATA step. The following two examples illustrate the
difference.
Examples
Example 1: Generating Multiple Streams from a CALL Routine
This example uses the CALL RANUNI routine to generate three streams of random
numbers from the uniform distribution with ten numbers each. See the results in
Output 4.1.
options nodate pageno=1 linesize=80 pagesize=60;
data multiple(drop=i);
retain Seed_1 1298573062 Seed_2 447801538
Seed_3 631280;
do i=1 to 10;
call ranuni (Seed_1,X1);
call ranuni (Seed_2,X2);
call ranuni (Seed_3,X3);
output;
end;
run;
proc print data=multiple;
title ’Multiple Streams from a CALL Routine’;
run;
Functions and CALL Routines
4
Examples
275
Output 4.1 The CALL Routine Example
Multiple Streams from a CALL Routine
Obs
Seed_1
Seed_2
Seed_3
X1
1
2
3
4
5
6
7
8
9
10
1394231558
1921384255
902955627
440711467
1044485023
2136205611
1028417321
1163276804
176629027
1587189112
512727191
1857602268
422181009
761747298
1703172173
2077746915
1800207034
473335603
1114889939
399894790
367385659
1297973981
188867073
379789529
591320717
870485645
1916469763
753297438
2089210809
284959446
0.64924
0.89471
0.42047
0.20522
0.48638
0.99475
0.47889
0.54169
0.08225
0.73909
1
X2
0.23876
0.86501
0.19659
0.35472
0.79310
0.96753
0.83829
0.22041
0.51916
0.18622
X3
0.17108
0.60442
0.08795
0.17685
0.27536
0.40535
0.89243
0.35078
0.97286
0.13269
Example 2: Assigning Values from a Single Stream to Multiple Variables
Using the same three seeds that were used in Example 1, this example uses a
function to create three variables. The results that are produced are different from
those in Example 1 because the values of all three variables are generated by the first
seed. When you use an individual function more than once in a DATA step, the function
accepts only the first seed value that you supply and ignores the rest.
options nodate pageno=1 linesize=80 pagesize=60;
data single(drop=i);
do i=1 to 3;
Y1=ranuni(1298573062);
Y2=ranuni(447801538);
Y3=ranuni(631280);
output;
end;
run;
proc print data=single;
title ’A Single Stream across Multiple Variables’;
run;
Output 4.2 shows the results. The values of Y1, Y2, and Y3 in this example come
from the same random-number stream generated from the first seed. You can see this
by comparing the values by observation across these three variables with the values of
X1 in Output 4.1.
Output 4.2 The Function Example
A Single Stream across Multiple Variables
Obs
Y1
1
2
3
0.64924
0.20522
0.47889
Y2
0.89471
0.48638
0.54169
Y3
0.42047
0.99475
0.08225
1
276
Pattern Matching Using SAS Regular Expressions (RX) and Perl Regular Expressions (PRX)
4
Chapter 4
Pattern Matching Using SAS Regular Expressions (RX) and Perl Regular
Expressions (PRX)
Definition of Pattern Matching and Regular Expressions
Pattern matching enables you to search for and extract multiple matching patterns
from a character string in one step, as well as to make several substitutions in a string
in one step. The DATA step supports two kinds of pattern-matching functions and
CALL routines:
3 SAS regular expressions (RX)
3 Perl regular expressions (PRX).
Regular expressions are a pattern language which provides fast tools for parsing
large amounts of text. Regular expressions are composed of characters and special
characters that are called metacharacters.
The asterisk (*) and the question mark (?) are two examples of metacharacters. The
asterisk (*) matches zero or more characters, and the question mark (?) matches one or
zero characters. For example, if you issue the ls data*.txt command from a UNIX
shell prompt, UNIX displays all the files in the current directory that begin with the
letters “data” and end with the file extension “txt”.
The asterisk (*) and the question mark (?) are a limited form of regular expressions.
Perl regular expressions build on the asterisk and the question mark to make searching
more powerful and flexible.
Definition of SAS Regular Expression (RX) Functions and CALL Routines
SAS Regular expression (RX) functions and CALL routines refers to a group of
functions and CALL routines that uses SAS’ regular expression pattern matching to
parse character strings. You can search for character strings that have a specific
pattern that you specify, and change a matched substring to a different substring.
SAS regular expressions are part of 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 286.
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 uses a modified version of Perl as a pattern matching
language to parse character strings. You can
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, more quickly
than with SAS regular expressions.
Perl regular expressions are part of 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 286.
Functions and CALL Routines
4
Using Perl Regular Expressions in the DATA Step
277
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
3 validate data
3 replace text
3 extract a substring from a string
3 write Perl debug output to the SAS log.
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. The code without the regular
expressions, however, 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
3 less prone to error
3 easier to maintain
3 clearer to read
3 more efficient in terms of improving system performance.
Using Perl Regular Expressions in the DATA Step
License Agreement
The following paragraph complies with sections 3 (a) and 4 (c) of the artistic license:
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. The
modified and original Perl 5.6.1 files are freely available from the SAS Web site at http:/
/support.sas.com/rnd/base. 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
non-standard 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
3 Perl variables.
3 the regular expression options /c, /g, and /o and the /e option with substitutions.
3 named characters, which use the \N{name} syntax.
3 the metacharacters \pP, \PP, and \X.
3 executing Perl code within a regular expression. This 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}.
3 matching backslashes with m/\\\\/. Instead m/\\/ should be used to match a
backslash.
278
Using Perl Regular Expressions in the DATA Step
4
Chapter 4
Syntax of Perl Regular Expressions
Perl regular expressions are composed 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 when searching for a 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”.
3 If you use /world/, SAS finds the substring “world” in the string “Hello world!”.
The following table contains a short list of Perl regular expression metacharacters
that you can use when you build your code. You can find a complete list of
metacharacters at http://www.perldoc.com/perl5.6.1/pod/perlre.html.
Metacharacter
Description
\
marks the next character as either a special character, a literal, a back
reference, or an octal escape:
3
3
3
3
"n" matches the character "n"
"\n" matches a new line character
"\\" matches "\"
"\(" matches "("
|
specifies the or condition when you compare alphanumeric strings.
^
matches the position at the beginning of the input string.
$
matches the position at the end of the input string.
*
matches the preceding subexpression zero or more times:
3
3
+
"zo+" does not match "z"
+ is equivalent to {1,}
"do(es)?" matches the "do" in "do" or "does"
? is equivalent to {0,1}
n is a non-negative integer that matches exactly n times:
3
3
{n,}
"zo+" matches "zo" and "zoo"
matches the preceding subexpression zero or one time:
3
3
{n}
* is equivalent to {0}
matches the preceding subexpression one or more times:
3
3
3
?
zo* matches "z" and "zoo"
"o{2}" matches the two o’s in "food"
"o{2}" does not match the "o" in "Bob"
n is a non-negative integer that matches n or more times:
3
3
3
3
"o{2,}" matches all the o’s in "foooood"
"o{2,}" does not match the "o" in "Bob"
"o{1,}" is equivalent to "o+"
"o{0,}" is equivalent to "o*"
Functions and CALL Routines
4
Using Perl Regular Expressions in the DATA Step
Metacharacter
Description
{n,m}
m and n are non-negative integers, where n<=m. They match at least
n and at most m times:
3
3
"o{1,3}" matches the first three o’s in "fooooood"
"o{0,1}" is equivalent to "o?"
Note: You cannot put a space between the comma and
the numbers. 4
period (.)
matches any single character except newline. To match any character
including newline, use a pattern such as "[.\n]".
(pattern)
matches a pattern and creates a capture buffer for the match. To
retrieve the position and length of the match that is captured, use
CALL PRXPOSN. To retrieve the value of the capture buffer, use the
PRXPOSN function. To match parentheses characters, use "\(" or "\)".
x|y
matches either x or y:
3
3
[xyz]
"[^a-z]" matches any character that is not in the range "a"
through "z"
matches a word boundary (the position between a word and a space):
3
3
\B
"[a-z]" matches any lowercase alphabetic character in the range
"a" through "z"
specifies a range of characters that does not match any character in
the range:
3
\b
"[^abc]" matches the "p" in "plain"
specifies a range of characters that matches any character in the range:
3
[^a-z]
"[abc]" matches the "a" in "plain"
specifies a negative character set that matches any character that is
not enclosed:
3
[a-z]
"(z|f)ood" matches "zood" or "food"
specifies a character set that matches any one of the enclosed
characters:
3
[^xyz]
"z|food" matches "z" or "food"
"er\b" matches the "er" in "never"
"er\b" does not match the "er" in "verb"
matches a non-word boundary:
3
3
"er\B" matches the "er" in "verb"
"er\B" does not match the "er" in "never"
\d
matches a digit character that is equivalent to [0-9].
\D
matches a non-digit character that is equivalent to [^0-9].
\s
matches any white space character including space, tab, form feed,
and so on, and is equivalent to [\f\n\r\t\v].
279
280
Using Perl Regular Expressions in the DATA Step
4
Chapter 4
Metacharacter
Description
\S
matches any character that is not a white space character and is
equivalent to [^\f\n\r\t\v].
\t
matches a tab character and is equivalent to "\x09".
\w
matches any word character including the underscore and is
equivalent to [A-Za-z0-9_].
\W
matches any non-word character and is equivalent to [^A-Za-z0-9_].
\num
matches num, where num is a positive integer. This is a reference
back to captured matches:
3
"(.)\1" matches two consecutive identical characters.
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
regexp = "/(" || paren || ")|(" || dash || ")/"; x
retain re;
re = prxparse(regexp); y
if missing(re) then U
do;
putlog "ERROR: Invalid regexp " regexp; 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 .
Functions and CALL Routines
4
Using Perl Regular Expressions in the DATA Step
281
Tom Joad 209/963/2764 2099-66-8474
;
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:
\(
matches the open parenthesis in the area code.
[2–9]
matches the digits 2–9. This is the first number in the area
code.
\d
matches a digit. This is the second number in the area code.
\d
matches a digit. This is the third number in the area code.
\)
matches the closed parenthesis in the area code.
?
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.
282
Using Perl Regular Expressions in the DATA Step
4
Chapter 4
The following lines are written to the SAS log:
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
Example 2: Replacing Text
You can use Perl regular expressions to find specific characters within a string. You
can then remove the characters or replace them with other characters. In this example,
the two occurrences of the less-than character (<) are replaced by &lt; and the two
occurrences of the greater-than character (>) are replaced by &gt;.
data _null_; u
if _N_ = 1 then
do;
retain lt_re gt_re;
lt_re = prxparse(’s/</&lt;/’); v
gt_re = prxparse(’s/>/&gt;/’); w
if missing(lt_re) or missing(gt_re) then x
do;
putlog "ERROR: Invalid regexp."; y
stop;
end;
end;
input;
call prxchange(lt_re, -1, _infile_); U
call prxchange(gt_re, -1, _infile_); V
put _infile_;
datalines4;
The bracketing construct ( ... ) creates capture buffers. To refer to
the digit’th buffer use \<digit> within the match. Outside the match
use "$" instead of "\". (The \<digit> notation works in certain
circumstances outside the match. See the warning below about \1 vs $1
for details.) Referring back to another part of the match is called
backreference.
;;;;
The following items correspond to the numbered lines in the DATA step that is
shown above.
u Create a DATA step.
v Use metacharacters to create a substitution syntax for a Perl regular expression,
and compile the expression. The substitution syntax specifies that a less-than
character (<) in the input is replaced by the value &lt; in the output.
w Use metacharacters to create a substitution syntax for a Perl regular expression,
and compile the expression. The substitution syntax specifies that a greater-than
character (>) in the input is replaced by the value &gt; in the output.
Functions and CALL Routines
4
Using Perl Regular Expressions in the DATA Step
283
x Use the MISSING function to check whether the Perl regular expression compiled
without error.
y Use the PUTLOG statement to write an error message to the SAS log if neither of
the regular expressions was found.
U Call the PRXCHANGE routine. Pass the LT_RE pattern-id, and search for and
replace all matching patterns. Put the results in _INFILE_ and write the
observation to the SAS log.
V Call the PRXCHANGE routine. Pass the GT_RE pattern-id, and search for and
replace all matching patterns. Put the results in _INFILE_ and write the
observation to the SAS log.
The following lines are written to the SAS log:
The bracketing construct ( ... ) creates capture buffers. To refer to
the digit’th buffer use \&lt;digit&gt; within the match. Outside the match
use "$" instead of "\". (The \&lt;digit&gt; notation works in certain
circumstances outside the match. See the warning below about \1 vs $1
for details.) Referring back to another part of the match is called a
backreference.
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;
length first last home business $ 16;
length areacode $ 3;
input first last home business;
W
284
Using Perl Regular Expressions in the DATA Step
4
Chapter 4
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
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. This is the first number in the area
code.
\d
matches a digit. This is the second number in the area code.
\d
matches a digit. This 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.
Functions and CALL Routines
4
Writing Perl Debug Output to the SAS Log
285
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.
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.
The following lines are written to the SAS log:
In North Carolina: Jerome Johnson (919)846-2198
In North Carolina: Palinor Kent 704-782-3199
In North Carolina: Takei Ito 704-298-4738
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.
286
Base SAS Functions for Web Applications
Output 4.3
4
Chapter 4
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 373.
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 by Category
Table 4.2 Categories and Descriptions of Functions and CALL Routines
Category
Functions and CALL
Routines
Description
Array
“DIM Function” on page
523
Returns the number of elements in an array
“HBOUND Function” on
page 608
Returns the upper bound of an array
Functions and CALL Routines
Category
Bitwise Logical Operations
Character String Matching
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“LBOUND Function” on
page 659
Returns the lower bound of an array
“BAND Function” on page
344
Returns the bitwise logical AND of two arguments
“BLSHIFT Function” on
page 347
Returns the bitwise logical left shift of two arguments
“BNOT Function” on page
348
Returns the bitwise logical NOT of an argument
“BOR Function” on page
348
Returns the bitwise logical OR of two arguments
“BRSHIFT Function” on
page 349
Returns the bitwise logical right shift of two arguments
“BXOR Function” on page
350
Returns the bitwise logical EXCLUSIVE OR of two
arguments
“CALL PRXCHANGE
Routine” on page 371
Performs a pattern-matching replacement
“CALL PRXDEBUG
Routine” on page 373
Enables Perl regular expressions in a DATA step to send
debug output to the SAS log
“CALL PRXFREE
Routine” on page 375
Frees unneeded memory that was allocated for a Perl
regular expression
“CALL PRXNEXT
Routine” on page 376
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 378
Returns the start position and length for a capture buffer
“CALL PRXSUBSTR
Routine” on page 381
Returns the position and length of a substring that
matches a pattern
“CALL RXCHANGE
Routine” on page 403
Changes one or more substrings that match a pattern
“CALL RXFREE Routine”
on page 404
Frees memory allocated by other regular expression (RX)
functions and CALL routines
“CALL RXSUBSTR
Routine” on page 405
Finds the position, length, and score of a substring that
matches a pattern
“PRXCHANGE Function”
on page 787
Performs a pattern-matching replacement
“PRXMATCH Function” on
page 791
Searches for a pattern match and returns the position at
which the pattern is found
“PRXPAREN Function” on
page 795
Returns the last bracket match for which there is a
match in a pattern
“PRXPARSE Function” on
page 796
Compiles a Perl regular expression (PRX) that can be
used for pattern matching of a character value
“PRXPOSN Function” on
page 798
Returns the value for a capture buffer
287
288
Functions and CALL Routines by Category
Category
Character
4
Chapter 4
Functions and CALL
Routines
Description
“RXMATCH Function” on
page 858
Finds the beginning of a substring that matches a pattern
“RXPARSE Function” on
page 859
Parses a pattern
“ANYALNUM Function”
on page 314
Searches a character string for an alphanumeric
character and returns the first position at which it is
found
“ANYALPHA Function” on
page 316
Searches a character string for an alphabetic character
and returns the first position at which it is found
“ANYCNTRL Function” on
page 318
Searches a character string for a control character and
returns the first position at which it is found
“ANYDIGIT Function” on
page 319
Searches a character string for a digit and returns the
first position at which it is found
“ANYFIRST Function” on
page 320
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 322
Searches a character string for a graphical character and
returns the first position at which it is found
“ANYLOWER Function”
on page 324
Searches a character string for a lowercase letter and
returns the first position at which it is found
“ANYNAME Function” on
page 325
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 327
Searches a character string for a printable character and
returns the first position at which it is found
“ANYPUNCT Function” on
page 329
Searches a character string for a punctuation character
and returns the first position at which it is found
“ANYSPACE Function” on
page 330
Searches a character string for a white-space character
(blank, horizontal and vertical tab, carriage return, line
feed, form feed) and returns the first position at which it
is found
“ANYUPPER Function” on
page 332
Searches a character string for an uppercase letter and
returns the first position at which it is found
“ANYXDIGIT Function” on
page 333
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
350
Returns one character in the ASCII or the EBCDIC
collating sequence
“CALL CATS Routine” on
page 353
Concatenates character strings and removes leading and
trailing blanks
“CALL CATT Routine” on
page 355
Concatenates character strings and removes trailing
blanks
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“CALL CATX Routine” on
page 356
Concatenates character strings, removes leading and
trailing blanks, and inserts separators
“CALL COMPCOST
Routine” on page 358
Sets the costs of operations for later use by the
COMPGED function
“CALL MISSING Routine”
on page 364
Assigns a missing value to the specified character or
numeric variables.
“CALL SCAN Routine” on
page 406
Returns the position and length of a given word from a
character expression
“CALL SCANQ Routine”
on page 408
Returns the position and length of a given word from a
character expression, and ignores delimiters that are
enclosed in quotation marks
“CAT Function” on page
427
Concatenates character strings without removing leading
or trailing blanks
“CATS Function” on page
429
Concatenates character strings and removes leading and
trailing blanks
“CATT Function” on page
430
Concatenates character strings and removes trailing
blanks
“CATX Function” on page
432
Concatenates character strings, removes leading and
trailing blanks, and inserts separators
“CHOOSEC Function” on
page 451
Returns a character value that represents the results of
choosing from a list of arguments
“CHOOSEN Function” on
page 452
Returns a numeric value that represents the results of
choosing from a list of arguments
“COALESCEC Function”
on page 459
Returns the first non-missing value from a list of
character arguments.
“COLLATE Function” on
page 460
Returns an ASCII or EBCDIC collating sequence
character string
“COMPARE Function” on
page 463
Returns the position of the leftmost character by which
two strings differ, or returns 0 if there is no difference
“COMPBL Function” on
page 466
Removes multiple blanks from a character string
“COMPGED Function” on
page 467
Compares two strings by computing the generalized edit
distance
“COMPLEV Function” on
page 472
Compares two strings by computing the Levenshtein edit
distance
“COMPRESS Function” on
page 476
Removes specific characters from a character string
“COUNT Function” on
page 488
Counts the number of times that a specific substring of
characters appears within a character string that you
specify
“COUNTC Function” on
page 490
Counts the number of specific characters that either
appear or do not appear within a character string that
you specify
289
290
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“DEQUOTE Function” on
page 512
Removes matching quotation marks from a character
string that begins with an individual quotation mark and
deletes everything that is to the right of the closing
quotation mark
“FIND Function” on page
558
Searches for a specific substring of characters within a
character string that you specify
“FINDC Function” on page
560
Searches for specific characters that either appear or do
not appear within a character string that you specify
“IFC Function” on page
616
Returns a character value of an expression based on
whether the expression is true, false, or missing
“IFN Function” on page
618
Returns a numeric value of an expression based on
whether the expression is true, false, or missing
“INDEX Function” on page
620
Searches a character expression for a string of characters
“INDEXC Function” on
page 621
Searches a character expression for specific characters
“INDEXW Function” on
page 622
Searches a character expression for a specified string as
a word
“LEFT Function” on page
661
Left aligns a SAS character expression
“LENGTH Function” on
page 662
Returns the length of a non-blank character string,
excluding trailing blanks, and returns 1 for a blank
character string
“LENGTHC Function” on
page 663
Returns the length of a character string, including
trailing blanks
“LENGTHM Function” on
page 664
Returns the amount of memory (in bytes) that is
allocated for a character string
“LENGTHN Function” on
page 666
Returns the length of a non-blank character string,
excluding trailing blanks, and returns 0 for a blank
character string
“LOWCASE Function” on
page 677
Converts all letters in an argument to lowercase
“MISSING Function” on
page 686
Returns a numeric result that indicates whether the
argument contains a missing value
“NLITERAL Function” on
page 703
Converts a character string that you specify to a SAS
name literal (n-literal)
“NOTALNUM Function”
on page 706
Searches a character string for a non-alphanumeric
character and returns the first position at which it is
found
“NOTALPHA Function” on
page 707
Searches a character string for a non-alphabetic
character and returns the first position at which it is
found
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“NOTCNTRL Function” on
page 709
Searches a character string for a character that is not a
control character and returns the first position at which
it is found
“NOTDIGIT Function” on
page 710
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 713
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 715
Searches a character string for a non-graphical character
and returns the first position at which it is found
“NOTLOWER Function”
on page 717
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 718
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 720
Searches a character string for a non-printable character
and returns the first position at which it is found
“NOTPUNCT Function” on
page 721
Searches a character string for a character that is not a
punctuation character and returns the first position at
which it is found
“NOTSPACE Function” on
page 724
Searches a character string for a character that is not a
white-space character (blank, horizontal and vertical tab,
carriage return, line feed, form feed) and returns the first
position at which it is found
“NOTUPPER Function” on
page 726
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 727
Searches a character string for a character that is not a
hexadecimal digit and returns the first position at which
that character is found
“NVALID Function” on
page 730
Checks a character string for validity for use as a SAS
variable name in a SAS statement
“PROPCASE Function” on
page 784
Converts all words in an argument to proper case
“QUOTE Function” on
page 813
Adds double quotation marks to a character value
“RANK Function” on page
833
Returns the position of a character in the ASCII or
EBCDIC collating sequence
“REPEAT Function” on
page 839
Repeats a character expression
“REVERSE Function” on
page 841
Reverses a character expression
291
292
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“RIGHT Function” on page
843
Right aligns a character expression
“SCAN Function” on page
875
Selects a given word from a character expression
“SCANQ Function” on
page 876
Returns the nth word from a character expression,
ignoring delimiters that are enclosed in quotation marks
“SOUNDEX Function” on
page 888
Encodes a string to facilitate searching
“SPEDIS Function” on
page 889
Determines the likelihood of two words matching,
expressed as the asymmetric spelling distance between
the two words
“STRIP Function” on page
898
Returns a character string with all leading and trailing
blanks removed
“SUBPAD Function” on
page 900
Returns a substring that has a length you specify, using
blank padding if necessary
“SUBSTR (left of =)
Function” on page 901
Replaces character value contents
“SUBSTR (right of =)
Function” on page 903
Extracts a substring from an argument
“SUBSTRN Function” on
page 904
Returns a substring, allowing a result with a length of
zero
“TRANSLATE Function”
on page 927
Replaces specific characters in a character expression
“TRANTAB Function” on
page 928
Transcodes a data string by using a translation table
“TRANWRD Function” on
page 929
Replaces or removes all occurrences of a word in a
character string
“TRIM Function” on page
931
Removes trailing blanks from character expressions and
returns one blank if the expression is missing
“TRIMN Function” on page
933
Removes trailing blanks from character expressions and
returns a null string (zero blanks) if the expression is
missing
“UPCASE Function” on
page 936
Converts all letters in an argument to uppercase
“VERIFY Function” on
page 955
Returns the position of the first character that is unique
to an expression
Currency Conversion
“EUROCURR Function” on
page 538
Converts one European currency to another
DBCS
“KCOMPARE Function” on
page 648
Returns the result of a comparison of character strings
“KCOMPRESS Function”
on page 649
Removes specific characters from a character string
Functions and CALL Routines
Category
Date and Time
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“KCOUNT Function” on
page 649
Returns the number of double-byte characters in a string
“KCVT Function” on page
649
Converts data from an encoding code to another encoding
code
“KINDEX Function” on
page 649
Searches a character expression for a string of characters
“KINDEXC Function” on
page 650
Searches a character expression for specific characters
“KLEFT Function” on page
650
Left aligns a character expression by removing
unnecessary leading DBCS blanks and SO/SI
“KLENGTH Function” on
page 650
Returns the length of an argument
“KLOWCASE Function” on
page 650
Converts all letters in an argument to lowercase
“KREVERSE Function” on
page 651
Reverses a character expression
“KRIGHT Function” on
page 651
Right aligns a character expression by trimming trailing
DBCS blanks and SO/SI
“KSCAN Function” on
page 651
Selects a specific word from a character expression
“KSTRCAT Function” on
page 651
Concatenates two or more character strings
“KSUBSTR Function” on
page 652
Extracts a substring from an argument
“KSUBSTRB Function” on
page 652
Extracts a substring from an argument according to the
byte position of the substring in the argument
“KTRANSLATE Function”
on page 652
Replaces specific characters in a character expression
“KTRIM Function” on page
652
Removes trailing DBCS blanks and SO/SI from character
expressions
“KTRUNCATE Function”
on page 653
Truncates a numeric value to a specified length
“KUPCASE Function” on
page 653
Converts all single-byte letters in an argument to
uppercase
“KUPDATE Function” on
page 653
Inserts, deletes, and replaces character value contents
“KUPDATEB Function” on
page 653
Inserts, deletes, and replaces the contents of the
character value according to the byte position of the
character value in the argument
“KVERIFY Function” on
page 654
Returns the position of the first character that is unique
to an expression
“DATDIF Function” on
page 499
Returns the number of days between two dates
293
294
Functions and CALL Routines by Category
Category
4
Chapter 4
Functions and CALL
Routines
Description
“DATE Function” on page
501
Returns the current date as a SAS date value
“DATEJUL Function” on
page 501
Converts a Julian date to a SAS date value
“DATEPART Function” on
page 502
Extracts the date from a SAS datetime value
“DATETIME Function” on
page 502
Returns the current date and time of day as a SAS
datetime value
“DAY Function” on page
503
Returns the day of the month from a SAS date value
“DHMS Function” on page
519
Returns a SAS datetime value from date, hour, minute,
and second
“HMS Function” on page
610
Returns a SAS time value from hour, minute, and second
values
“HOUR Function” on page
611
Returns the hour from a SAS time or datetime value
“INTCK Function” on page
630
Returns the integer count of the number of interval
boundaries between two dates, two times, or two
datetime values
“INTNX Function” on page
634
Increments a date, time, or datetime value by a given
interval or intervals, and returns a date, time, or
datetime value
“JULDATE Function” on
page 646
Returns the Julian date from a SAS date value
“JULDATE7 Function” on
page 647
Returns a seven-digit Julian date from a SAS date value
“MDY Function” on page
680
Returns a SAS date value from month, day, and year
values
“MINUTE Function” on
page 684
Returns the minute from a SAS time or datetime value
“MONTH Function” on
page 695
Returns the month from a SAS date value
“NLDATE Function” on
page 702
Converts the SAS date value to the date value of the
specified locale using the date-format modifiers
“NLDATM Function” on
page 702
Converts the SAS datetime values to the time value of
the specified locale using the datetime format modifiers
“NLTIME Function” on
page 703
Converts the SAS time or datetime value to the time
value of the specified locale using the time-format
modifiers
“QTR Function” on page
810
Returns the quarter of the year from a SAS date value
“SECOND Function” on
page 880
Returns the second from a SAS time or datetime value
Functions and CALL Routines
Category
Descriptive Statistics
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“TIME Function” on page
922
Returns the current time of day
“TIMEPART Function” on
page 923
Extracts a time value from a SAS datetime value
“TODAY Function” on page
926
Returns the current date as a SAS date value
“WEEK Function” on page
990
Returns the week number value
“WEEKDAY Function” on
page 991
Returns the day of the week from a SAS date value
“YEAR Function” on page
991
Returns the year from a SAS date value
“YRDIF Function” on page
993
Returns the difference in years between two dates
“YYQ Function” on page
995
Returns a SAS date value from the year and quarter
“CSS Function” on page
491
Returns the corrected sum of squares
“CV Function” on page 493
Returns the coefficient of variation
“GEOMEAN Function” on
page 597
Returns the geometric mean
“GEOMEANZ Function”
on page 598
Returns the geometric mean, using zero fuzzing
“HARMEAN Function” on
page 605
Returns the harmonic mean
“HARMEANZ Function”
on page 606
Returns the harmonic mean, using zero fuzzing
“IQR Function” on page
644
Returns the interquartile range
“KURTOSIS Function” on
page 654
Returns the kurtosis
“LARGEST Function” on
page 658
Returns the kth largest non-missing value
“MAD Function” on page
678
Returns the median absolute deviation from the median
“MAX Function” on page
679
Returns the largest value
“MEAN Function” on page
681
Returns the arithmetic mean (average)
“MEDIAN Function” on
page 682
Computes median values
“MIN Function” on page
683
Returns the smallest value
295
296
Functions and CALL Routines by Category
Category
External Files
4
Chapter 4
Functions and CALL
Routines
Description
“MISSING Function” on
page 686
Returns a numeric result that indicates whether the
argument contains a missing value
“N Function” on page 700
Returns the number of nonmissing values
“NMISS Function” on page
705
Returns the number of missing values
“ORDINAL Function” on
page 734
Returns any specified order statistic
“PCTL Function” on page
736
Computes percentiles
“RANGE Function” on
page 832
Returns the range of values
“RMS Function” on page
844
Returns the root mean square
“SKEWNESS Function” on
page 884
Returns the skewness
“SMALLEST Function” on
page 886
Returns the kth smallest nonmissing value
“STD Function” on page
893
Returns the standard deviation
“STDERR Function” on
page 893
Returns the standard error of the mean
“SUM Function” on page
908
Returns the sum of the nonmissing arguments
“USS Function” on page
939
Returns the uncorrected sum of squares
“VAR Function” on page
941
Returns the variance
“DCLOSE Function” on
page 504
Closes a directory that was opened by the DOPEN
function
“DCREATE Function” on
page 505
Creates an external directory
“DINFO Function” on page
524
Returns information about a directory
“DNUM Function” on page
526
Returns the number of members in a directory
“DOPEN Function” on
page 527
Opens a directory and returns a directory identifier value
“DOPTNAME Function”
on page 528
Returns directory attribute information
“DOPTNUM Function” on
page 530
Returns the number of information items that are
available for a directory
“DREAD Function” on
page 531
Returns the name of a directory member
Functions and CALL Routines
Category
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“DROPNOTE Function” on
page 532
Deletes a note marker from a SAS data set or an
external file
“FAPPEND Function” on
page 542
Appends the current record to the end of an external file
“FCLOSE Function” on
page 544
Closes an external file, directory, or directory member
“FCOL Function” on page
545
Returns the current column position in the File Data
Buffer (FDB)
“FDELETE Function” on
page 547
Deletes an external file or an empty directory
“FEXIST Function” on
page 551
Verifies the existence of an external file associated with a
fileref
“FGET Function” on page
552
Copies data from the File Data Buffer (FDB) into a
variable
“FILEEXIST Function” on
page 554
Verifies the existence of an external file by its physical
name
“FILENAME Function” on
page 555
Assigns or deassigns a fileref to an external file,
directory, or output device
“FILEREF Function” on
page 557
Verifies that a fileref has been assigned for the current
SAS session
“FINFO Function” on page
565
Returns the value of a file information item
“FNOTE Function” on
page 576
Identifies the last record that was read and returns a
value that FPOINT can use
“FOPEN Function” on
page 578
Opens an external file and returns a file identifier value
“FOPTNAME Function” on
page 580
Returns the name of an item of information about a file
“FOPTNUM Function” on
page 582
Returns the number of information items that are
available for an external file
“FPOINT Function” on
page 583
Positions the read pointer on the next record to be read
“FPOS Function” on page
584
Sets the position of the column pointer in the File Data
Buffer (FDB)
“FPUT Function” on page
586
Moves data to the File Data Buffer (FDB) of an external
file, starting at the FDB’s current column position
“FREAD Function” on
page 587
Reads a record from an external file into the File Data
Buffer (FDB)
“FREWIND Function” on
page 588
Positions the file pointer to the start of the file
“FRLEN Function” on
page 590
Returns the size of the last record read, or, if the file is
opened for output, returns the current record size
297
298
Functions and CALL Routines by Category
Category
External Routines
Financial
4
Chapter 4
Functions and CALL
Routines
Description
“FSEP Function” on page
591
Sets the token delimiters for the FGET function
“FWRITE Function” on
page 593
Writes a record to an external file
“MOPEN Function” on
page 696
Opens a file by directory id and member name, and
returns the file identifier or a 0
“PATHNAME Function” on
page 734
Returns the physical name of a SAS data library or of an
external file, or returns a blank
“SYSMSG Function” on
page 914
Returns the text of error messages or warning messages
from the last data set or external file function execution
“SYSRC Function” on page
919
Returns a system error number
“CALL MODULE Routine”
on page 365
Calls the external routine without any return code
“CALL MODULEI
Routine” on page 368
Calls the external routine without any return code (in
IML environment only)
“MODULEC Function” on
page 690
Calls an external routine and returns a character value
“MODULEIC Function” on
page 691
Calls an external routine and returns a character value
(in IML environment only)
“MODULEIN Function” on
page 692
Calls an external routine and returns a numeric value
(in IML environment only)
“MODULEN Function” on
page 693
Calls an external routine and returns a numeric value
“COMPOUND Function”
on page 475
Returns compound interest parameters
“CONVX Function” on
page 484
Returns the convexity for an enumerated cash flow
“CONVXP Function” on
page 485
Returns the convexity for a periodic cash flow stream,
such as a bond
“DACCDB Function” on
page 494
Returns the accumulated declining balance depreciation
“DACCDBSL Function” on
page 495
Returns the accumulated declining balance with
conversion to a straight-line depreciation
“DACCSL Function” on
page 496
Returns the accumulated straight-line depreciation
“DACCSYD Function” on
page 497
Returns the accumulated sum-of-years-digits
depreciation
“DACCTAB Function” on
page 498
Returns the accumulated depreciation from specified
tables
“DEPDB Function” on
page 506
Returns the declining balance depreciation
Functions and CALL Routines
Category
Hyperbolic
Macro
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“DEPDBSL Function” on
page 507
Returns the declining balance with conversion to a
straight-line depreciation
“DEPSL Function” on page
508
Returns the straight-line depreciation
“DEPSYD Function” on
page 509
Returns the sum-of-years-digits depreciation
“DEPTAB Function” on
page 511
Returns the depreciation from specified tables
“DUR Function” on page
534
Returns the modified duration for an enumerated cash
flow
“DURP Function” on page
535
Returns the modified duration for a periodic cash flow
stream, such as a bond
“INTRR Function” on page
639
Returns the internal rate of return as a fraction
“IRR Function” on page
645
Returns the internal rate of return as a percentage
“MORT Function” on page
699
Returns amortization parameters
“NETPV Function” on
page 701
Returns the net present value as a fraction
“NPV Function” on page
729
Returns the net present value with the rate expressed as
a percentage
“PVP Function” on page
809
Returns the present value for a periodic cash flow stream
with repayment of principal at maturity, such as a bond
“SAVING Function” on
page 874
Returns the future value of a periodic saving
“YIELDP Function” on
page 992
Returns the yield-to-maturity for a periodic cash flow
stream, such as a bond
“COSH Function” on page
487
Returns the hyperbolic cosine
“SINH Function” on page
883
Returns the hyperbolic sine
“TANH Function” on page
922
Returns the hyperbolic tangent
“CALL EXECUTE
Routine” on page 361
Resolves an argument and issues the resolved value for
execution
“CALL SYMPUT Routine”
on page 419
Assigns DATA step information to a macro variable
“CALL SYMPUTX
Routine” on page 420
Assigns a value to a macro variable and removes both
leading and trailing blanks
“RESOLVE Function” on
page 840
Returns the resolved value of an argument after it has
been processed by the macro facility
299
300
Functions and CALL Routines by Category
Category
Mathematical
4
Chapter 4
Functions and CALL
Routines
Description
“SYMEXIST Function” on
page 909
Returns an indication of the existence of a macro variable
“SYMGET Function” on
page 910
Returns the value of a macro variable during DATA step
execution
“SYMGLOBL Function” on
page 911
Returns an indication as to whether a macro variable is
in a global scope to the DATA step during DATA step
execution.
“SYMLOCAL Function” on
page 912
Returns an indication as to whether a macro variable is
in a local scope to the DATA step during DATA step
execution
“ABS Function” on page
310
Returns the absolute value
“AIRY Function” on page
313
Returns the value of the airy function
“BETA Function” on page
345
Returns the value of the beta function
“CALL ALLPERM
Routine” on page 351
Generates all permutations of the values of several
variables
“CALL LOGISTIC
Routine” on page 363
Returns the logistic value
“CALL SOFTMAX
Routine” on page 413
Returns the softmax value
“CALL STDIZE Routine”
on page 414
Standardizes the values of one or more variables
“CALL TANH Routine” on
page 423
Returns the hyperbolic tangent
“CNONCT Function” on
page 456
Returns the noncentrality parameter from a chi-squared
distribution
“COALESCE Function” on
page 458
Returns the first non-missing value from a list of
numeric arguments.
“COMB Function” on page
462
Computes the number of combinations of n elements
taken r at a time
“CONSTANT Function” on
page 480
Computes some machine and mathematical constants
“DAIRY Function” on page
499
Returns the derivative of the AIRY function
“DEVIANCE Function” on
page 515
Computes the deviance
“DIGAMMA Function” on
page 522
Returns the value of the Digamma function
“ERF Function” on page
536
Returns the value of the (normal) error function
Functions and CALL Routines
Category
Probability
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“ERFC Function” on page
537
Returns the value of the complementary (normal) error
function
“EXP Function” on page
541
Returns the value of the exponential function
“FACT Function” on page
541
Computes a factorial
“FNONCT Function” on
page 574
Returns the value of the noncentrality parameter of an F
distribution
“GAMMA Function” on
page 596
Returns the value of the Gamma function
“IBESSEL Function” on
page 615
Returns the value of the modified bessel function
“JBESSEL Function” on
page 645
Returns the value of the bessel function
“LGAMMA Function” on
page 667
Returns the natural logarithm of the Gamma function
“LOG Function” on page
670
Returns the natural (base e) logarithm
“LOG10 Function” on page
671
Returns the logarithm to the base 10
“LOG2 Function” on page
672
Returns the logarithm to the base 2
“LOGBETA Function” on
page 672
Returns the logarithm of the beta function
“MOD Function” on page
687
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
694
Returns the remainder from the division of the first
argument by the second argument, using zero fuzzing
“PERM Function” on page
760
Computes the number of permutations of n items taken r
at a time
“SIGN Function” on page
881
Returns the sign of a value
“SQRT Function” on page
892
Returns the square root of a value
“TNONCT Function” on
page 925
Returns the value of the noncentrality parameter from
the student’s t distribution
“TRIGAMMA Function” on
page 930
Returns the value of the Trigamma function
“CDF Function” on page
434
Computes cumulative distribution functions
“LOGCDF Function” on
page 673
Computes the logarithm of a left cumulative distribution
function
301
302
Functions and CALL Routines by Category
Category
Quantile
4
Chapter 4
Functions and CALL
Routines
Description
“LOGPDF Function” on
page 675
Computes the logarithm of a probability density (mass)
function
“LOGSDF Function” on
page 676
Computes the logarithm of a survival function
“PDF Function” on page
737
Computes probability density (mass) functions
“POISSON Function” on
page 762
Returns the probability from a Poisson distribution
“PROBBETA Function” on
page 763
Returns the probability from a beta distribution
“PROBBNML Function” on
page 764
Returns the probability from a binomial distribution
“PROBBNRM Function”
on page 765
Computes a probability from the bivariate normal
distribution
“PROBCHI Function” on
page 766
Returns the probability from a chi-squared distribution
“PROBF Function” on page
767
Returns the probability from an F distribution
“PROBGAM Function” on
page 768
Returns the probability from a gamma distribution
“PROBHYPR Function” on
page 769
Returns the probability from a hypergeometric
distribution
“PROBMC Function” on
page 771
Computes a probability or a quantile from various
distributions for multiple comparisons of means
“PROBNEGB Function” on
page 782
Returns the probability from a negative binomial
distribution
“PROBNORM Function”
on page 783
Returns the probability from the standard normal
distribution
“PROBT Function” on page
784
Returns the probability from a t distribution
“SDF Function” on page
878
Computes a survival function
“BETAINV Function” on
page 346
Returns a quantile from the beta distribution
“CINV Function” on page
453
Returns a quantile from the chi-squared distribution
“FINV Function” on page
566
Returns a quantile from the F distribution
“GAMINV Function” on
page 595
Returns a quantile from the gamma distribution
“PROBIT Function” on
page 770
Returns a quantile from the standard normal distribution
Functions and CALL Routines
Category
Random Number
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“QUANTILE Function” on
page 811
Computes the quantile from a specified distribution
“TINV Function” on page
923
Returns a quantile from the t distribution
“CALL RANBIN Routine”
on page 383
Returns a random variate from a binomial distribution
“CALL RANCAU Routine”
on page 385
Returns a random variate from a Cauchy distribution
“CALL RANEXP Routine”
on page 387
Returns a random variate from an exponential
distribution
“CALL RANGAM Routine”
on page 389
Returns a random variate from a gamma distribution
“CALL RANNOR Routine”
on page 391
Returns a random variate from a normal distribution
“CALL RANPERK
Routine” on page 392
Randomly permutes the values of the arguments, and
returns a permutation of k out of n values
“CALL RANPERM
Routine” on page 394
Randomly permutes the values of the arguments
“CALL RANPOI Routine”
on page 395
Returns a random variate from a Poisson distribution
“CALL RANTBL Routine”
on page 397
Returns a random variate from a tabled probability
distribution
“CALL RANTRI Routine”
on page 399
Returns a random variate from a triangular distribution
“CALL RANUNI Routine”
on page 401
Returns a random variate from a uniform distribution
“CALL STREAMINIT
Routine” on page 418
Specifies a seed value to use for subsequent random
number generation by the RAND function
“NORMAL Function” on
page 705
Returns a random variate from a normal distribution
“RANBIN Function” on
page 814
Returns a random variate from a binomial distribution
“RANCAU Function” on
page 815
Returns a random variate from a Cauchy distribution
“RAND Function” on page
816
Generates random numbers from a specified distribution
“RANEXP Function” on
page 830
Returns a random variate from an exponential
distribution
“RANGAM Function” on
page 831
Returns a random variate from a gamma distribution
“RANNOR Function” on
page 834
Returns a random variate from a normal distribution
303
304
Functions and CALL Routines by Category
Category
SAS File I/O
4
Chapter 4
Functions and CALL
Routines
Description
“RANPOI Function” on
page 835
Returns a random variate from a Poisson distribution
“RANTBL Function” on
page 836
Returns a random variate from a tabled probability
distribution
“RANTRI Function” on
page 837
Returns a random variate from a triangular distribution
“RANUNI Function” on
page 838
Returns a random variate from a uniform distribution
“UNIFORM Function” on
page 935
Returns a random variate from a uniform distribution
“ATTRC Function” on page
338
Returns the value of a character attribute for a SAS data
set
“ATTRN Function” on page
340
Returns the value of a numeric attribute for the specified
SAS data set
“CEXIST Function” on
page 450
Verifies the existence of a SAS catalog or SAS catalog
entry
“CLOSE Function” on page
455
Closes a SAS data set
“CUROBS Function” on
page 492
Returns the observation number of the current
observation
“DROPNOTE Function” on
page 532
Deletes a note marker from a SAS data set or an
external file
“DSNAME Function” on
page 533
Returns the SAS data set name that is associated with a
data set identifier
“EXIST Function” on page
538
Verifies the existence of a SAS data library member
“FETCH Function” on
page 548
Reads the next nondeleted observation from a SAS data
set into the Data Set Data Vector (DDV)
“FETCHOBS Function” on
page 549
Reads a specified observation from a SAS data set into
the Data Set Data Vector (DDV)
“GETVARC Function” on
page 602
Returns the value of a SAS data set character variable
“GETVARN Function” on
page 603
Returns the value of a SAS data set numeric variable
“IORCMSG Function” on
page 642
Returns a formatted error message for _IORC_
“LIBNAME Function” on
page 668
Assigns or deassigns a libref for a SAS data library
“LIBREF Function” on
page 669
Verifies that a libref has been assigned
“NOTE Function” on page
712
Returns an observation ID for the current observation of
a SAS data set
Functions and CALL Routines
Category
Special
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“OPEN Function” on page
732
Opens a SAS data set
“PATHNAME Function” on
page 734
Returns the physical name of a SAS data library or of an
external file, or returns a blank
“POINT Function” on page
761
Locates an observation identified by the NOTE function
“REWIND Function” on
page 842
Positions the data set pointer at the beginning of a SAS
data set
“SYSMSG Function” on
page 914
Returns the text of error messages or warning messages
from the last data set or external file function execution
“SYSRC Function” on page
919
Returns a system error number
“VARFMT Function” on
page 942
Returns the format assigned to a SAS data set variable
“VARINFMT Function” on
page 944
Returns the informat assigned to a SAS data set variable
“VARLABEL Function” on
page 945
Returns the label assigned to a SAS data set variable
“VARLEN Function” on
page 946
Returns the length of a SAS data set variable
“VARNAME Function” on
page 948
Returns the name of a SAS data set variable
“VARNUM Function” on
page 949
Returns the number of a variable’s position in a SAS
data set
“VARTYPE Function” on
page 953
Returns the data type of a SAS data set variable
“ADDR Function” on page
311
Returns the memory address of a numeric variable on a
32–bit platform
“ADDRLONG Function” on
page 312
Returns the memory address of a character variable on
32-bit and 64-bit platforms
“CALL POKE Routine” on
page 369
Writes a value directly into memory on a 32–bit platform
“CALL POKELONG
Routine” on page 370
Writes a value directly into memory on 32-bit and 64-bit
platforms
“CALL SLEEP Routine” on
page 412
Suspends the execution of a program that invokes this
call routine for a specified period of time
“CALL SYSTEM Routine”
on page 422
Submits an operating environment command for
execution
“DIF Function” on page
520
Returns differences between the argument and its nth lag
“GETOPTION Function”
on page 600
Returns the value of a SAS system or graphics option
305
306
Functions and CALL Routines by Category
Category
State and ZIP Code
4
Chapter 4
Functions and CALL
Routines
Description
“INPUT Function” on page
624
Returns the value produced when a SAS expression that
uses a specified informat expression is read
“INPUTC Function” on
page 626
Enables you to specify a character informat at run time
“INPUTN Function” on
page 628
Enables you to specify a numeric informat at run time
“LAG Function” on page
655
Returns values from a queue
“PEEK Function” on page
752
Stores the contents of a memory address into a numeric
variable on a 32–bit platform
“PEEKC Function” on
page 754
Stores the contents of a memory address in a character
variable on a 32–bit platform
“PEEKCLONG Function”
on page 757
Stores the contents of a memory address in a character
variable on 32-bit and 64-bit platforms
“PEEKLONG Function” on
page 758
Stores the contents of a memory address in a numeric
variable on 32-bit and 64-bit platforms
“PTRLONGADD Function”
on page 802
Returns the pointer address as a character variable on
32-bit and 64-bit platforms
“PUT Function” on page
803
Returns a value using a specified format
“PUTC Function” on page
805
Enables you to specify a character format at run time
“PUTN Function” on page
807
Enables you to specify a numeric format at run time
“SLEEP Function” on page
885
Suspends the execution of a program that invokes this
function for a specified period of time
“SYSGET Function” on
page 913
Returns the value of the specified operating environment
variable
“SYSPARM Function” on
page 915
Returns the system parameter string
“SYSPROCESSID
Function” on page 916
Returns the process id of the current process
“SYSPROCESSNAME
Function” on page 917
Returns the process name associated with a given
process id or the name of the current process
“SYSPROD Function” on
page 918
Determines if a product is licensed
“SYSTEM Function” on
page 920
Issues an operating environment command during a SAS
session and returns the system return code
“UUIDGEN Function” on
page 940
Returns the short or binary form of a Universal Unique
Identifier (UUID)
“FIPNAME Function” on
page 567
Converts two-digit FIPS codes to uppercase state names
Functions and CALL Routines
Category
Trigonometric
Truncation
4
Functions and CALL Routines by Category
Functions and CALL
Routines
Description
“FIPNAMEL Function” on
page 568
Converts two-digit FIPS codes to mixed case state names
“FIPSTATE Function” on
page 569
Converts two-digit FIPS codes to two-character state
postal codes
“STFIPS Function” on
page 894
Converts state postal codes to FIPS state codes
“STNAME Function” on
page 895
Converts state postal codes to uppercase state names
“STNAMEL Function” on
page 896
Converts state postal codes to mixed case state names
“ZIPCITY Function” on
page 997
Returns a city name and the two-character postal code
that corresponds to a ZIP code
“ZIPFIPS Function” on
page 998
Converts ZIP codes to two-digit FIPS codes
“ZIPNAME Function” on
page 999
Converts ZIP codes to uppercase state names
“ZIPNAMEL Function” on
page 1001
Converts ZIP codes to mixed case state names
“ZIPSTATE Function” on
page 1003
Converts ZIP codes to two-character state postal codes
“ARCOS Function” on
page 335
Returns the arccosine
“ARSIN Function” on page
335
Returns the arcsine
“ATAN Function” on page
336
Returns the arc tangent
“ATAN2 Function” on page
337
Returns the arc tangent of two numeric variables
“COS Function” on page
486
Returns the cosine
“SIN Function” on page
882
Returns the sine
“TAN Function” on page
921
Returns the tangent
“CEIL Function” on page
448
Returns the smallest integer that is greater than or
equal to the argument, fuzzed to avoid unexpected
floating-point results
“CEILZ Function” on page
449
Returns the smallest integer that is greater than or
equal to the argument, using zero fuzzing
“FLOOR Function” on
page 571
Returns the largest integer that is less than or equal to
the argument, fuzzed to avoid unexpected floating-point
results
307
308
Functions and CALL Routines by Category
Category
Variable Control
Variable Information
4
Chapter 4
Functions and CALL
Routines
Description
“FLOORZ Function” on
page 572
Returns the largest integer that is less than or equal to
the argument, using zero fuzzing
“FUZZ Function” on page
592
Returns the nearest integer if the argument is within
1E−12
“INT Function” on page
629
Returns the integer value, fuzzed to avoid unexpected
floating-point results
“INTZ Function” on page
640
Returns the integer portion of the argument, using zero
fuzzing
“ROUND Function” on
page 845
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 853
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 855
Rounds the first argument to the nearest multiple of the
second argument, with zero fuzzing
“TRUNC Function” on
page 934
Truncates a numeric value to a specified length
“CALL LABEL Routine”
on page 361
Assigns a variable label to a specified character variable
“CALL SET Routine” on
page 410
Links SAS data set variables to DATA step or macro
variables that have the same name and data type
“CALL VNAME Routine”
on page 424
Assigns a variable name as the value of a specified
variable
“CALL VNEXT Routine”
on page 425
Returns the name, type, and length of a variable that is
used in a DATA step
“VARRAY Function” on
page 950
Returns a value that indicates whether the specified
name is an array
“VARRAYX Function” on
page 951
Returns a value that indicates whether the value of the
specified argument is an array
“VARTRANSCODE
Function” on page 953
Returns the transcode attribute of a SAS data set
variable
“VFORMAT Function” on
page 956
Returns the format that is associated with the specified
variable
“VFORMATD Function” on
page 957
Returns the format decimal value that is associated with
the specified variable
“VFORMATDX Function”
on page 958
Returns the format decimal value that is associated with
the value of the specified argument
“VFORMATN Function” on
page 959
Returns the format name that is associated with the
specified variable
“VFORMATNX Function”
on page 960
Returns the format name 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
“VFORMATW Function”
on page 962
Returns the format width that is associated with the
specified variable
“VFORMATWX Function”
on page 963
Returns the format width that is associated with the
value of the specified argument
“VFORMATX Function” on
page 964
Returns the format that is associated with the value of
the specified argument
“VINARRAY Function” on
page 965
Returns a value that indicates whether the specified
variable is a member of an array
“VINARRAYX Function”
on page 966
Returns a value that indicates whether the value of the
specified argument is a member of an array
“VINFORMAT Function”
on page 968
Returns the informat that is associated with the specified
variable
“VINFORMATD Function”
on page 969
Returns the informat decimal value that is associated
with the specified variable
“VINFORMATDX
Function” on page 970
Returns the informat decimal value that is associated
with the value of the specified argument
“VINFORMATN Function”
on page 971
Returns the informat name that is associated with the
specified variable
“VINFORMATNX
Function” on page 972
Returns the informat name that is associated with the
value of the specified argument
“VINFORMATW Function”
on page 973
Returns the informat width that is associated with the
specified variable
“VINFORMATWX
Function” on page 974
Returns the informat width that is associated with the
value of the specified argument
“VINFORMATX Function”
on page 975
Returns the informat that is associated with the value of
the specified argument
“VLABEL Function” on
page 977
Returns the label that is associated with the specified
variable
“VLABELX Function” on
page 978
Returns the variable label for the value of the specified
argument
“VLENGTH Function” on
page 979
Returns the compile-time (allocated) size of the specified
variable
“VLENGTHX Function” on
page 981
Returns the compile-time (allocated) size for the value of
the specified argument
“VNAME Function” on
page 982
Returns the name of the specified variable
“VNAMEX Function” on
page 983
Validates the value of the specified argument as a
variable name
“VTRANSCODE Function”
on page 984
Returns a value that indicates whether transcoding is on
or off for the specified character variable
“VTRANSCODEX
Function” on page 985
Returns a value that indicates whether transcoding is on
or off for the specified argument
309
310
Dictionary
4
Chapter 4
Category
Web Tools
Functions and CALL
Routines
Description
“VTYPE Function” on page
985
Returns the type (character or numeric) of the specified
variable
“VTYPEX Function” on
page 987
Returns the type (character or numeric) for the value of
the specified argument
“VVALUE Function” on
page 988
Returns the formatted value that is associated with the
variable that you specify
“VVALUEX Function” on
page 989
Returns the formatted value that is associated with the
argument that you specify
“HTMLDECODE
Function” on page 612
Decodes a string containing HTML numeric character
references or HTML character entity references and
returns the decoded string
“HTMLENCODE
Function” on page 613
Encodes characters using HTML character entity
references and returns the encoded string
“URLDECODE Function”
on page 937
Returns a string that was decoded using the URL escape
syntax
“URLENCODE Function”
on page 938
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
is numeric.
Details
The ABS function returns a nonnegative number that is equal in magnitude to that of
the argument.
Functions and CALL Routines
4
ADDR Function
311
Examples
SAS Statements
Results
x=abs(2.4);
2.4
x=abs(-3);
3
ADDR Function
Returns the memory address of a numeric 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 always 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 numerical variable on a 32–bit
platform. ADDRLONG returns the memory address of a character 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
312
ADDRLONG Function
4
Chapter 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 369
Functions:
“PEEK Function” on page 752
“PEEKC Function” on page 754
“ADDRLONG Function” on page 312
ADDRLONG Function
Returns the memory address of a character variable on 32-bit and 64-bit platforms
Category:
Special
Syntax
ADDRLONG(variable)
Arguments
variable
specifies the variable name that points to the memory address.
Details
The return value is a character variable that contains the binary representation of the
pointer. To display this value, use the $HEXw. format to convert the binary value to its
hexadecimal equivalent.
Note: If you used the ADDR function and defined an instance of the pointer as
numeric by using a LENGTH statement in your program, substituting ADDR for
ADDRLONG will fail because ADDRLONG requires a character argument. 4
Examples
The following example returns the pointer address for the variable ITEM, and
formats the value.
Functions and CALL Routines
4
AIRY Function
313
data characterlist;
item=6345;
x=addrlong(item);
put x $hex16.;
run;
The following line is written to the SAS log:
480063B020202020
AIRY Function
Returns the value of the airy function
Category: Mathematical
Syntax
AIRY(x)
Arguments
x
is numeric.
Details
The AIRY function returns the value of the airy function (Abramowitz and Stegun 1964;
Amos, Daniel and Weston 1977) (See “References” on page 1005). It is the solution of
the differential equation
w(2) 0 xw = 0
with the conditions
w (0) =
10 1
3 0 23
2
3
and
w
0
(0) =
0
1
1
33 0
011
3
314
ANYALNUM Function
4
Chapter 4
Examples
SAS Statements
Results
x=airy(2.0);
0.0349241304
x=airy(-2.0);
0.2274074282
ANYALNUM Function
Searches a character string for an alphanumeric character and returns the first position at which it
is found
Category:
Character
Syntax
ANYALNUM(string <,start>)
Arguments
string
specifies the character 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” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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.
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
3 the character that you are searching for is not found
Functions and CALL Routines
4
ANYALNUM Function
315
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;
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;
316
4
ANYALPHA Function
Chapter 4
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 706
ANYALPHA Function
Searches a character string for an alphabetic character and returns the first position at which it is
found
Category:
Character
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.
Details
The results of the ANYALPHA function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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,
Functions and CALL Routines
4
ANYALPHA Function
317
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
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
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
See Also
Function:
“NOTALPHA Function” on page 707
318
ANYCNTRL Function
4
Chapter 4
ANYCNTRL Function
Searches a character string for a control character and returns the first position at which it is found
Character
Category:
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 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
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.
See Also
Function:
“NOTCNTRL Function” on page 709
Functions and CALL Routines
4
ANYDIGIT Function
319
ANYDIGIT Function
Searches a character string for a digit and returns the first position at which it is found
Category: Character
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 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
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.
320
4
ANYFIRST Function
Chapter 4
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;
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 710
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
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.
Functions and CALL Routines
4
ANYFIRST Function
321
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.
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
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
j=2
j=3
j=4
j=8
c=N
c=e
c=x
c=t
c=_
322
ANYGRAPH Function
4
Chapter 4
j=9 c=n
j=10 c=_
j=16 c=E
That’s all
See Also
Function:
“NOTFIRST Function” on page 713
ANYGRAPH Function
Searches a character string for a graphical character and returns the first position at which it is
found
Category:
Character
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” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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.
Functions and CALL Routines
4
ANYGRAPH Function
323
ANYGRAPH returns a value of zero when
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 ANYGRAPH function searches a character string for a graphical character. The
NOTGRAPH function searches a character string for a non-graphical character.
Examples
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
See Also
Function:
“NOTGRAPH Function” on page 715
324
ANYLOWER Function
4
Chapter 4
ANYLOWER Function
Searches a character string for a lowercase letter and returns the first position at which it is found
Category:
Character
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” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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
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 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.
Functions and CALL Routines
4
ANYNAME Function
325
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 717
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: Character
Syntax
ANYNAME(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 ANYNAME function does not depend on the TRANTAB, ENCODING, or LOCALE
options.
326
ANYNAME Function
4
Chapter 4
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
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;
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
Functions and CALL Routines
4
ANYPRINT Function
327
j=16 c=E
j=17 c=3
That’s all
See Also
Function:
“NOTNAME Function” on page 718
ANYPRINT Function
Searches a character string for a printable character and returns the first position at which it is
found
Category: Character
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” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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
3 the character that you are searching for is not found
328
ANYPRINT Function
4
Chapter 4
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
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=+
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
See Also
Function:
“NOTPRINT Function” on page 720
Functions and CALL Routines
4
ANYPUNCT Function
329
ANYPUNCT Function
Searches a character string for a punctuation character and returns the first position at which it is
found
Category: Character
See: ANYPUNCT Function in the documentation for your operating environment.
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.
Details
The results of the ANYPUNCT function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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
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
The following example uses the ANYPUNCT function to search a string for
punctuation characters.
330
4
ANYSPACE Function
Chapter 4
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
See Also
Function:
“NOTPUNCT Function” on page 721
ANYSPACE Function
Searches a character string for a white-space character (blank, horizontal and vertical tab,
carriage return, line feed, form feed) and returns the first position at which it is found
Category:
Character
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.
Functions and CALL Routines
4
ANYSPACE Function
331
Details
The results of the ANYSPACE function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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
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
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
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
332
ANYUPPER Function
4
Chapter 4
See Also
Function:
“NOTSPACE Function” on page 724
ANYUPPER Function
Searches a character string for an uppercase letter and returns the first position at which it is found
Category:
Character
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” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
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:
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
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.
Functions and CALL Routines
4
ANYXDIGIT Function
333
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 726
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
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.
334
ANYXDIGIT Function
4
Chapter 4
Details
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
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 digit. The NOTXDIGIT function searches a character string for a
character that is not a hexadecimal digit.
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);
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
Functions and CALL Routines
4
ARSIN Function
335
See Also
Function:
“NOTXDIGIT Function” on page 727
ARCOS Function
Returns the arccosine
Category: Trigonometric
Syntax
ARCOS (argument)
Arguments
argument
is numeric.
Range: between −1 and 1
Details
The ARCOS function returns the arccosine (inverse cosine) of the argument. The value
returned is in radians.
Examples
SAS Statements
Results
x=arcos(1);
0
x=arcos(0);
1.5707963268
x=arcos(-0.5);
2.0943951024
ARSIN Function
Returns the arcsine
Category: Trigonometric
336
ATAN Function
4
Chapter 4
Syntax
ARSIN (argument)
Arguments
argument
is numeric.
Range:
between −1 and 1
Details
The ARSIN function returns the arcsine (inverse sine) of the argument. The value
returned is in radians.
Examples
SAS Statements
Results
x=arsin(0);
0
x=arsin(1);
1.5707963268
x=arsin(--0.5);
-0.523598776
ATAN Function
Returns the arc tangent
Category:
Trigonometric
Syntax
ATAN (argument)
Arguments
argument
is numeric.
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
Functions and CALL Routines
whose value ranges from -=2 to
missing value.
=2.
4
ATAN2 Function
337
If the argument is missing, then ATAN returns a
Comparisons
The ATAN function is similar to the ATAN2 function except that ATAN2 calculates the
arc tangent of the angle from the values 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 337
ATAN2 Function
Returns the arc tangent of two numeric variables
Category: Trigonometric
Syntax
ATAN2(argument-1, argument-2)
Arguments
argument-1
is numeric.
argument-2
is numeric.
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
338
ATTRC Function
4
Chapter 4
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 336
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.
Functions and CALL Routines
4
ATTRC Function
339
Valid values for use with attr-name are:
CHARSET
returns a value for the character set of the machine 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 data 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.
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.
MTYPE
returns the SAS data 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.
340
ATTRN Function
4
Chapter 4
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 machine 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.";
rc=close(dsid);
run;
See Also
Functions:
“ATTRN Function” on page 340
“OPEN Function” on page 732
ATTRN Function
Returns the value of a numeric attribute for the specified SAS data set
Category:
SAS File I/O
Functions and CALL Routines
4
ATTRN Function
Syntax
ATTRN(data-set-id,attr-name)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
attr-name
is a numeric attribute, as listed in the section below. If the value of attr-name is
invalid, a missing value is returned.
Valid numeric values used with attr-name are:
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
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.
341
342
ATTRN Function
4
Chapter 4
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.
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.
Functions and CALL Routines
4
ATTRN Function
343
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 (those 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 (those 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.
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
size, this can be a time-consuming process.
Tip:
NOBS
specifies the number of physical observations (including those 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.
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.
344
BAND Function
4
Chapter 4
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 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 338
“OPEN Function” on page 732
BAND Function
Returns the bitwise logical AND of two arguments
Category:
Bitwise Logical Operations
Syntax
band(argument-1,argument-2)
Functions and CALL Routines
4
BETA Function
345
Arguments
argument-1,argument-2
are numeric, nonnegative, and nonmissing. Separate the arguments with a comma.
Range: 0 to the largest 32-bit unsigned integer
Examples
SAS Statements
Results
x=band(0Fx,05x);
put x=hex.;
x=00000005;
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)
346
BETAINV Function
4
Chapter 4
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 672
BETAINV Function
Returns a quantile from the beta distribution
Category:
Quantile
Syntax
BETAINV (p,a,b)
Arguments
p
is a numeric probability.
Range: 0 ≤ p ≤ 1
a
is a numeric shape parameter.
Range: a > 0
b
is a numeric shape parameter.
Range: b > 0
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.
Functions and CALL Routines
Note:
BETAINV is the inverse of the PROBBETA function.
Examples
SAS Statements
Results
x=betainv(0.001,2,4);
0.0101017879
BLSHIFT Function
Returns the bitwise logical left shift of two arguments
Category: Bitwise Logical Operations
Syntax
BLSHIFT(argument-1,argument-2)
Arguments
argument-1
is numeric, nonnegative, and nonmissing.
Range: 0 to the largest 32-bit unsigned integer
argument-2
is numeric, nonnegative, and nonmissing.
Range: 0 to 31, inclusive
Examples
SAS Statements
Results
x=blshift(07x,2);
put x=hex.;
x=0000001C
4
4
BLSHIFT Function
347
348
4
BNOT Function
Chapter 4
BNOT Function
Returns the bitwise logical NOT of an argument
Category:
Bitwise Logical Operations
Syntax
BNOT(argument)
Arguments
argument
is numeric, nonnegative, and nonmissing.
Range: 0 to the largest 32-bit unsigned integer
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
are numeric, nonnegative, and nonmissing. Separate the arguments with a comma.
Range: 0 to the largest 32-bit unsigned integer
Functions and CALL Routines
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
Syntax
BRSHIFT(argument-1, argument-2)
Arguments
argument-1
is numeric, nonnegative, and nonmissing.
Range: 0 to the largest 32-bit unsigned integer
argument-2
is numeric, nonnegative, and nonmissing.
Range: 0 to 31, inclusive
Examples
SAS Statements
Results
x=brshift(01Cx,2);
put x=hex.;
x=00000007
4
BRSHIFT Function
349
350
4
BXOR Function
Chapter 4
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
are numeric, nonnegative, and nonmissing. Separate the arguments with a comma.
Range:
0 to the largest 32-bit unsigned integer
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
Category:
See:
Character
BYTE Function in the documentation for your operating environment.
Syntax
BYTE (n)
Arguments
n
specifies an integer that represents a specific ASCII or EBCDIC character.
Range:
0–255
Functions and CALL Routines
4
CALL ALLPERM Routine
351
Details
If the BYTE function returns a value to a variable that has not yet been assigned a
length, by default the variable is assigned a length of 1.
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.
Examples
SAS Statements
x=byte(80);
put x;
Results
ASCII
EBCDIC
----+----1----+----2
----+----1----+----2
P
&
See Also
Functions:
“COLLATE Function” on page 460
“RANK Function” on page 833
CALL ALLPERM Routine
Generates all permutations of the values of several variables
Category: Mathematical
Syntax
CALL ALLPERM(k, variable-1< , variable–2, ...>);
Arguments
k
specifies an integer value that ranges from one to the number of permutations.
352
CALL ALLPERM Routine
4
Chapter 4
variable
specifies 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
Use the CALL ALLPERM routine in a loop where the first argument accepts each
integral value from one 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 of the variables are interchanged. Because each permutation is generated from the
previous permutation by a single interchange, the algorithm is very efficient.
Note: You can compute the number of permutations by using the FACT function.
See “FACT Function” on page 541 for more information. 4
If you use the CALL 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, for example, your result will not be the kth
permutation (except when k is one). To get the kth permutation, you must call the
ALLPERM routine k times, with the first argument having values from 1 through k in
that exact order.
Examples
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;
The following lines are written to the SAS log:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ant
ant
ant
dog
dog
ant
ant
ant
cat
cat
cat
dog
dog
cat
bee
bee
dog
ant
ant
dog
cat
cat
ant
ant
dog
cat
cat
dog
cat
dog
bee
bee
cat
cat
dog
bee
bee
dog
ant
ant
bee
bee
dog
cat
cat
cat
bee
bee
bee
dog
dog
bee
bee
bee
ant
ant
Functions and CALL Routines
15
16
17
18
19
20
21
22
23
24
cat
cat
bee
bee
bee
dog
dog
bee
bee
bee
bee
bee
cat
cat
dog
bee
bee
dog
ant
ant
dog
ant
ant
dog
cat
cat
ant
ant
dog
cat
4
CALL CATS Routine
353
ant
dog
dog
ant
ant
ant
cat
cat
cat
dog
See Also
CALL Routines:
“CALL RANPERK Routine” on page 392
“CALL RANPERM Routine” on page 394
CALL CATS Routine
Concatenates character strings and removes leading and trailing blanks
Category: Character
Syntax
CALL CATS(result <, string-1, ...string-n>);
Arguments
result
specifies a SAS variable.
string
specifies a SAS character string.
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
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 BEST. format.
354
CALL CATS Routine
4
Chapter 4
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.
CALL Routine
Equivalent Statement
CALL CATS(res, OF X1-X4);
res=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:
“CAT Function” on page 427
“CATS Function” on page 429
“CATT Function” on page 430
“CATX Function” on page 432
“CALL CATT Routine” on page 355
“CALL CATX Routine” on page 356
Functions and CALL Routines
4
CALL CATT Routine
355
CALL CATT Routine
Concatenates character strings and removes trailing blanks
Category: Character
Syntax
CALL CATT(result < , string-1, ...string-n>);
Arguments
result
specifies a SAS variable.
string
specifies a SAS character string.
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
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 BEST. 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.
356
CALL CATX Routine
4
Chapter 4
CALL Routine
Equivalent Statement
CALL CATS(res, OF X1-X4);
res=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:
“CAT Function” on page 427
“CATS Function” on page 429
“CATT Function” on page 430
“CATX Function” on page 432
“CALL CATS Routine” on page 353
“CALL CATX Routine” on page 356
CALL CATX Routine
Concatenates character strings, removes leading and trailing blanks, and inserts separators
Category:
Character
Functions and CALL Routines
4
CALL CATX Routine
357
Syntax
CALL CATX(separator, result<, string-1 , ...>string-n);
Arguments
separator
specifies a character string that is used as a separator between concatenated strings.
result
specifies a SAS variable.
string
specifies a SAS character string.
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
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 BEST. 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.
CALL Routine
Equivalent Statement
CALL CATS(res, OF X1-X4);
res=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.
358
CALL COMPCOST Routine
4
Chapter 4
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. ’;
answer=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:
“CAT Function” on page 427
“CATS Function” on page 429
“CATT Function” on page 430
“CATX Function” on page 432
“CALL CATS Routine” on page 353
“CALL CATT Routine” on page 355
CALL COMPCOST Routine
Sets the costs of operations for later use by the COMPGED function
Category:
Character
Restriction:
Use with the COMPGED function
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.
Functions and CALL Routines
4
CALL COMPCOST Routine
359
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 468 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
INSERT=
100
MATCH=
0
PUNCTUATION=
very large
REPLACE=
100
SINGLE=
very large
SWAP=
very large
TRUNCATE=
very large
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=
360
4
CALL COMPCOST Routine
Chapter 4
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.
Output 4.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
See Also
Functions:
“COMPGED Function” on page 467
“COMPARE Function” on page 463
“COMPLEV Function” on page 472
1
Generalized
Edit
Distance
0
10
11
12
Functions and CALL Routines
4
CALL LABEL Routine
361
CALL EXECUTE Routine
Resolves an argument and issues the resolved value for execution
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.
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.
362
CALL LABEL Routine
4
Chapter 4
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.
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 977
Functions and CALL Routines
4
CALL LOGISTIC Routine
363
CALL LOGISTIC Routine
Returns the logistic value
Category: Mathematical
Syntax
CALL LOGISTIC(argument<, argument, ...>)
Arguments
argument
is numeric.
Restriction The CALL LOGISTIC routine only accepts variables as valid
arguments. Do not use a constant or a SAS expression since 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
364
CALL MISSING Routine
4
Chapter 4
CALL MISSING Routine
Assigns a missing value 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.
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=.
Functions and CALL Routines
4
CALL MODULE Routine
365
See Also
Function:
“MISSING Function” on page 686
“How to Set Variable Values to Missing in a Data Step” in SAS Language Reference:
Concepts
CALL MODULE Routine
Calls the external routine without any return code
Category: External Routines
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
366
CALL MODULE Routine
4
Chapter 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.
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.;
Functions and CALL Routines
4
CALL MODULE Routine
367
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);
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
CALL Routine:
“CALL MODULEI Routine” on page 368
Functions:
“MODULEC Function” on page 690
“MODULEIC Function” on page 691
“MODULEIN Function” on page 692
“MODULEN Function” on page 693
368
CALL MODULEI Routine
4
Chapter 4
CALL MODULEI Routine
Calls the external routine without any return code (in IML environment only)
External Routines
Restriction: CALL MODULEI can only be invoked from within the IML procedure
Category:
See:
“CALL MODULE Routine” on page 365
Syntax
CALL MODULEI(<cntl-string,>module-name< ,argument-1, ..., argument-n>);
Details
For details on CALL MODULEI, see “CALL MODULE Routine” on page 365.
See Also
CALL Routine:
“CALL MODULE Routine” on page 365
Functions:
“MODULEC Function” on page 690
“MODULEIC Function” on page 691
“MODULEIN Function” on page 692
“MODULEN Function” on page 693
Functions and CALL Routines
4
CALL POKE Routine
369
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>);
Arguments
source
specifies a SAS expression that contains a value to write into memory.
pointer
specifies a numeric SAS expression that contains the virtual address of the data that
the CALL POKE 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 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: Under z/OS, pointers are 3 or 4 bytes
long, depending on the situation. 4
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.
370
4
CALL POKELONG Routine
Chapter 4
See Also
Functions:
“ADDR Function” on page 311
“PEEK Function” on page 752
“PEEKC Function” on page 754
CALL POKELONG Routine
Writes a value directly into memory on 32-bit and 64-bit platforms
Category:
Special
Syntax
CALL POKELONG(source,pointer< ,length>)
Arguments
source
specifies a character string 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.
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.
Functions and CALL Routines
4
CALL PRXCHANGE Routine
371
CALL PRXCHANGE Routine
Performs a pattern-matching replacement
Category: Character String Matching
Restriction:
Use with the PRXPARSE function.
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 pattern identifier that is returned from the PRXPARSE function.
times
is a numeric value 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 that specifies 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 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 that specifies 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.
372
CALL PRXCHANGE Routine
4
Chapter 4
For more information about pattern matching, see “Pattern Matching Using SAS
Regular Expressions (RX) and Perl Regular Expressions (PRX)” on page 276.
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 286.
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 373
“CALL PRXFREE Routine” on page 375
“CALL PRXNEXT Routine” on page 376
“CALL PRXPOSN Routine” on page 378
“CALL PRXSUBSTR Routine” on page 381
“PRXCHANGE Function” on page 787
“PRXPAREN Function” on page 795
“PRXMATCH Function” on page 791
“PRXPARSE Function” on page 796
“PRXPOSN Function” on page 798
*/
*/
*/
*/
*/
Functions and CALL Routines
4
CALL PRXDEBUG Routine
373
CALL PRXDEBUG Routine
Enables Perl regular expressions in a DATA step to send debug 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.
Syntax
CALL PRXDEBUG (on-off);
Arguments
on-off
specifies a numeric value. 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 SAS
Regular Expressions (RX) and Perl Regular Expressions (PRX)” on page 276.
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 286.
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_’);
/* Turn the debugging option off. */
374
CALL PRXDEBUG Routine
4
Chapter 4
call prxdebug(0);
run;
The following lines are written to the SAS log.
Output 4.5
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 371
“CALL PRXFREE Routine” on page 375
Functions and CALL Routines
4
CALL PRXFREE Routine
375
“CALL PRXNEXT Routine” on page 376
“CALL PRXPOSN Routine” on page 378
“CALL PRXSUBSTR Routine” on page 381
“CALL PRXCHANGE Routine” on page 371
“PRXCHANGE Function” on page 787
“PRXPAREN Function” on page 795
“PRXMATCH Function” on page 791
“PRXPARSE Function” on page 796
“PRXPOSN Function” on page 798
CALL PRXFREE Routine
Frees unneeded memory that was allocated for a Perl regular expression
Category: Character String Matching
Restriction:
Use with the PRXPARSE function
Syntax
CALL PRXFREE (regular-expression-id);
Arguments
regular-expression-id
specifies a numeric 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 SAS
Regular Expressions (RX) and Perl Regular Expressions (PRX)” on page 276.
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 286.
376
CALL PRXNEXT Routine
4
Chapter 4
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 371
“CALL PRXDEBUG Routine” on page 373
“CALL PRXNEXT Routine” on page 376
“CALL PRXPOSN Routine” on page 378
“CALL PRXSUBSTR Routine” on page 381
“CALL PRXCHANGE Routine” on page 371
“PRXCHANGE Function” on page 787
“PRXPAREN Function” on page 795
“PRXPAREN Function” on page 795
“PRXPARSE Function” on page 796
“PRXPOSN Function” on page 798
CALL PRXNEXT Routine
Returns the position and length of a substring that matches a pattern and iterates over multiple
matches within one string
Category:
Restriction:
Character String Matching
Use with the PRXPARSE function
Syntax
CALL PRXNEXT (regular-expression-id, start, stop, source, position, length);
Arguments
regular-expression-id
specifies a numeric identification number that is returned by the PRXPARSE
function.
start
is a numeric value 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 value 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 the character expression that you want to search.
Functions and CALL Routines
4
CALL PRXNEXT Routine
377
position
specifies the numeric position in source at which the pattern begins. If no match is
found, CALL PRXNEXT returns zero.
length
specifies a numeric 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 SAS
Regular Expressions (RX) and Perl Regular Expressions (PRX)” on page 276.
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 286.
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
378
4
CALL PRXPOSN Routine
Chapter 4
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 371
“CALL PRXDEBUG Routine” on page 373
“CALL PRXFREE Routine” on page 375
“CALL PRXPOSN Routine” on page 378
“CALL PRXSUBSTR Routine” on page 381
“CALL PRXCHANGE Routine” on page 371
“PRXCHANGE Function” on page 787
“PRXPAREN Function” on page 795
“PRXMATCH Function” on page 791
“PRXPARSE Function” on page 796
“PRXPOSN Function” on page 798
CALL PRXPOSN Routine
Returns the start position and length for a capture buffer
Character String Matching
Category:
Restriction:
Use with the PRXPARSE function
Syntax
CALL PRXPOSN (regular-expression-id, capture-buffer, start <, length>);
Arguments
regular-expression-id
specifies a numeric pattern identifier that is returned by the PRXPARSE function.
capture-buffer
is a numeric 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 value that specifies 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.
Functions and CALL Routines
4
CALL PRXPOSN Routine
379
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 value that specifies the pattern length of the previous pattern match:
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 SAS
Regular Expressions (RX) and Perl Regular Expressions (PRX)” on page 276.
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 286.
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;
380
CALL PRXPOSN Routine
4
Chapter 4
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
The following example parses time data and writes the results to the SAS log.
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
Functions and CALL Routines
4
CALL PRXSUBSTR Routine
381
See Also
Functions and CALL routines:
“CALL PRXCHANGE Routine” on page 371
“CALL PRXDEBUG Routine” on page 373
“CALL PRXFREE Routine” on page 375
“CALL PRXNEXT Routine” on page 376
“CALL PRXSUBSTR Routine” on page 381
“CALL PRXCHANGE Routine” on page 371
“PRXCHANGE Function” on page 787
“PRXPAREN Function” on page 795
“PRXMATCH Function” on page 791
“PRXPARSE Function” on page 796
“PRXPOSN Function” on page 798
CALL PRXSUBSTR Routine
Returns the position and length of a substring that matches a pattern
Category: Character String Matching
Restriction:
Use with the PRXPARSE function
Syntax
CALL PRXSUBSTR (regular-expression-id, source, position <, length>);
Arguments
regular-expression-id
specifies a numeric identification number that is returned by the PRXPARSE
function.
source
specifies the character expression that you want to search.
position
is a numeric value that specifies the position in source where the pattern begins. If
no match is found, CALL PRXSUBSTR returns zero.
length
specifies a numeric 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 optionally returns the
382
CALL PRXSUBSTR Routine
4
Chapter 4
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 SAS
Regular Expressions (RX) and Perl Regular Expressions (PRX)” on page 276.
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 286.
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
Functions and CALL Routines
4
CALL RANBIN Routine
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 371
“CALL PRXDEBUG Routine” on page 373
“CALL PRXFREE Routine” on page 375
“CALL PRXNEXT Routine” on page 376
“CALL PRXPOSN Routine” on page 378
“PRXCHANGE Function” on page 787
“PRXPAREN Function” on page 795
“PRXMATCH Function” on page 791
“PRXPARSE Function” on page 796
“PRXPOSN Function” on page 798
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:
See:
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 273 for more information about seed values
383
384
CALL RANBIN Routine
4
Chapter 4
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
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.
Comparisons
The CALL RANBIN routine gives greater control of the seed and random number
streams than does the RANBIN function.
Examples
This example uses the CALL RANBIN routine:
options nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
n=2000;
p=.2;
do i=1 to 10;
call ranbin(Seed_1,n,p,X1);
call ranbin(Seed_2,n,p,X2);
X3=ranbin(Seed_3,n,p);
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;
Functions and CALL Routines
4
CALL RANCAU Routine
385
The following output shows the results:
Output 4.6 The RANBIN Example
The SAS System
i
Seed_1
1
2
3
4
5
6
7
8
9
10
1404437564
1445125588
1326029789
1988843719
2137808851
1233028129
50049159
802575599
100573943
414117170
Seed_2
Seed_3
1404437564
1445125588
1326029789
1988843719
18
991271755
1437043694
959908645
1225034217
425626811
45
45
45
45
18
18
18
18
18
18
1
X1
X2
X3
385
399
384
421
430
392
424
371
428
402
385
399
384
421
430
374
384
383
388
403
385
399
384
421
430
392
424
371
428
402
Changing Seed_2 for the CALL RANBIN 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 RANBIN function, however, has no effect.
See Also
Function:
“RANBIN Function” on page 814
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.
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 273 for more information about seed values
x
is a numeric SAS variable. A new value for the random variate x is returned each
time CALL RANCAU is executed.
386
CALL RANCAU Routine
4
Chapter 4
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.
Comparisons
The CALL RANCAU routine gives greater control of the seed and random number
streams than does the RANCAU function.
Examples
This example uses the CALL RANCAU routine:
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;
The following output shows the results:
Functions and CALL Routines
4
CALL RANEXP Routine
387
Output 4.7 The RANCAU Example
The SAS System
i
Seed_1
1
2
3
4
5
6
7
8
9
10
Seed_2
1404437564
1326029789
1988843719
1233028129
50049159
802575599
1233458739
52428589
1216356463
1711885541
1404437564
1326029789
1988843719
1233028129
18
991271755
1437043694
959908645
1225034217
425626811
1
Seed_3
X1
X2
X3
45
45
45
45
18
18
18
18
18
18
-1.14736
-0.23735
-0.15474
4.97935
0.20402
3.43645
6.32808
0.18815
0.80689
0.92971
-1.14736
-0.23735
-0.15474
4.97935
0.20402
4.44427
-1.79200
-1.67610
3.88391
-1.31309
-1.14736
-0.23735
-0.15474
4.97935
0.20402
3.43645
6.32808
0.18815
0.80689
0.92971
Changing Seed_2 for the CALL RANCAU 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 RANCAU function, however, has no effect.
See Also
Function:
“RANCAU Function” on page 815
CALL RANEXP Routine
Returns a random variate from an exponential distribution
Category: Random Number
Syntax
CALL RANEXP(seed,x);
Arguments
seed
is the seed value. A new value for seed is returned each time CALL RANEXP is
executed.
31
Range: seed < 2 - 1
Note:
See:
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 273 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.
388
CALL RANEXP Routine
4
Chapter 4
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.
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 nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
do i=1 to 10;
call ranexp(Seed_1,X1);
call ranexp(Seed_2,X2);
X3=ranexp(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;
The following output shows the results:
Output 4.8
The RANEXP Example
The SAS System
i
1
2
3
4
5
6
7
8
9
10
1
Seed_1
Seed_2
Seed_3
X1
694315054
1404437564
2130505156
1445125588
1013861398
1326029789
932142747
1988843719
516966271
2137808851
694315054
1404437564
2130505156
1445125588
18
417047966
850344656
2067665501
607886093
1550198721
45
45
45
45
18
18
18
18
18
18
1.12913
0.42466
0.00794
0.39610
0.75053
0.48211
0.83457
0.07674
1.42407
0.00452
X2
1.12913
0.42466
0.00794
0.39610
0.75053
0.57102
0.92566
0.16730
0.51513
0.91543
X3
1.12913
0.42466
0.00794
0.39610
0.75053
0.48211
0.83457
0.07674
1.42407
0.00452
Functions and CALL Routines
4
CALL RANGAM Routine
389
Changing Seed_2 for the CALL RANEXP 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 RANEXP function, however, has no effect.
See Also
Function:
“RANEXP Function” on page 830
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 273 for more information about seed values
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 1005). For a 1, an acceptance-rejection method by Fishman is
used (Fishman, 1978; see in “References” on page 1005).
Comparisons
The CALL RANGAM routine gives greater control of the seed and random number
streams than does the RANGAM function.
390
CALL RANGAM Routine
4
Chapter 4
Examples
This example uses the CALL RANGAM routine:
options nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
a=2;
do i=1 to 10;
call rangam(Seed_1,a,X1);
call rangam(Seed_2,a,X2);
X3=rangam(Seed_3,a);
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;
The following output shows the results:
Output 4.9
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
Function:
“RANGAM Function” on page 831
Functions and CALL Routines
4
CALL RANNOR Routine
CALL RANNOR Routine
Returns a random variate from a normal distribution
Category: Random Number
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:
See:
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 273 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.
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 nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
do i=1 to 10;
call rannor(Seed_1,X1);
call rannor(Seed_2,X2);
X3=rannor(Seed_3);
391
392
4
CALL RANPERK Routine
Chapter 4
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;
The following output shows the results:
Output 4.10
The RANNOR Example
The SAS System
i
Seed_1
1
2
3
4
5
6
7
8
9
10
1404437564
1445125588
1326029789
1988843719
2137808851
1233028129
50049159
802575599
100573943
414117170
Seed_2
1404437564
1445125588
1326029789
1988843719
18
991271755
1437043694
959908645
1225034217
425626811
1
Seed_3
X1
X2
X3
45
45
45
45
18
18
18
18
18
18
-0.85252
-0.05865
-0.90628
1.15526
1.68697
-0.47276
1.33423
-1.63511
1.55410
0.10736
-0.85252
-0.05865
-0.90628
1.15526
1.68697
-1.44726
-0.87677
-0.97261
-0.64742
0.14963
-0.85252
-0.05865
-0.90628
1.15526
1.68697
-0.47276
1.33423
-1.63511
1.55410
0.10736
Changing Seed_2 for the CALL RANNOR 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 RANNOR function, however, has no effect.
See Also
Function:
“RANNOR Function” on page 834
CALL RANPERK Routine
Randomly permutes the values of the arguments, and returns a permutation of k out of n values
Category:
Random Number
Syntax
CALL RANPERK(seed, k, variable-1<, variable–2, ...>);
Functions and CALL Routines
4
CALL RANPERK Routine
393
Arguments
seed
is a numeric variable that contains the random number seed. For more information
about seeds, see “Seed Values” on page 273.
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.
Examples
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;
The following lines are written to the SAS log:
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
See Also
Functions:
“CALL ALLPERM Routine” on page 351
“CALL RANPERM Routine” on page 394
394
CALL RANPERM Routine
4
Chapter 4
CALL RANPERM Routine
Randomly permutes the values of the arguments
Category:
Random Number
Syntax
CALL RANPERM(seed, variable-1<, variable–2, ...>);
Arguments
seed
is a numeric variable that contains the random number seed. For more information
about seeds, see “Seed Values” on page 273.
variable
specifies all numeric variables or all character variables that have the same length.
The values of these variables are randomly permuted.
Examples
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;
The following lines are written to the SAS log:
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
Functions and CALL Routines
4
CALL RANPOI Routine
395
See Also
CALL Routines:
“CALL ALLPERM Routine” on page 351
“CALL RANPERK Routine” on page 392
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.
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 273 for more information about seed values
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 1005). 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).
Comparisons
The CALL RANPOI routine gives greater control of the seed and random number
streams than does the RANPOI function.
396
CALL RANPOI Routine
4
Chapter 4
Examples
This example uses the CALL RANPOI routine:
options nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
m=120;
do i=1 to 10;
call ranpoi(Seed_1,m,X1);
call ranpoi(Seed_2,m,X2);
X3=ranpoi(Seed_3,m);
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;
The following output shows the results:
Output 4.11
The RANPOI Example
The SAS System
i
Seed_1
1
2
3
4
5
6
7
8
9
10
1404437564
1445125588
1326029789
1988843719
2137808851
1233028129
50049159
802575599
100573943
414117170
Seed_2
1404437564
1445125588
1326029789
1988843719
18
991271755
1437043694
959908645
1225034217
425626811
1
Seed_3
X1
X2
X3
45
45
45
45
18
18
18
18
18
18
111
119
110
133
138
115
135
102
137
121
111
119
110
133
138
104
110
109
113
122
111
119
110
133
138
115
135
102
137
121
Changing Seed_2 for the CALL RANPOI 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 RANPOI function, however, has no effect.
See Also
Function:
“RANPOI Function” on page 835
Functions and CALL Routines
4
CALL RANTBL Routine
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
Note:
See:
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 273 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 =1
X
if
n
pi
i =1
pi
1
397
398
CALL RANTBL Routine
4
Chapter 4
If, for some index j<n,
X
j
=1
pi
1
i
RANTBL returns only the indices 1 through j, with the probability of occurrence of the
index j equal to
01
X
0
i
j
1
=1
p
i
Comparisons
The CALL RANTBL routine gives greater control of the seed and random number
streams than does the RANTBL function.
Examples
This example uses the CALL RANTBL routine:
options nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
input p1-p9;
do i=1 to 10;
call rantbl(Seed_1,of p1-p9,X1);
call rantbl(Seed_2,of p1-p9,X2);
X3=rantbl(Seed_3,of p1-p9);
if i=5 then
do;
Seed_2=18;
Seed_3=18;
end;
output;
end;
datalines;
.02 .04 .06 .08 .1 .12 .14 .16 .18
;
proc print;
id i;
var Seed_1-Seed_3 X1-X3;
run;
Functions and CALL Routines
4
CALL RANTRI Routine
399
The following output shows the results:
Output 4.12
The RANTBL Example
i
Seed_1
1
2
3
4
5
6
7
8
9
10
694315054
1404437564
2130505156
1445125588
1013861398
1326029789
932142747
1988843719
516966271
2137808851
The SAS System
Seed_2
Seed_3
694315054
1404437564
2130505156
1445125588
18
707222751
991271755
422705333
1437043694
1264538018
45
45
45
45
18
18
18
18
18
18
1
X1
X2
X3
6
8
10
8
7
8
7
10
5
10
6
8
10
8
7
6
7
4
8
8
6
8
10
8
7
8
7
10
5
10
Changing Seed_2 for the CALL RANTBL statement, when I=5, forces the stream of
variates for X2 to deviate from the stream of variates for X1. Changing Seed_3 on the
RANTBL function, however, has no effect.
See Also
Function:
“RANTBL Function” on page 836
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 273 for more information about seed values
h
is a numeric SAS value.
Range: 0<h<1
400
CALL RANTRI Routine
4
Chapter 4
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.
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 nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
h=.2;
do i=1 to 10;
call rantri(Seed_1,h,X1);
call rantri(Seed_2,h,X2);
X3=rantri(Seed_3,h);
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;
The following output shows the results:
Functions and CALL Routines
Output 4.13
4
CALL RANUNI Routine
401
The RANTRI Example
The SAS System
i
Seed_1
Seed_2
1
2
3
4
5
6
7
8
9
10
694315054
1404437564
2130505156
1445125588
1013861398
1326029789
932142747
1988843719
516966271
2137808851
Seed_3
694315054
1404437564
2130505156
1445125588
18
707222751
991271755
422705333
1437043694
1264538018
45
45
45
45
18
18
18
18
18
18
1
X1
0.26424
0.47388
0.92047
0.48848
0.35015
0.44681
0.32713
0.75690
0.22063
0.93997
X2
0.26424
0.47388
0.92047
0.48848
0.35015
0.26751
0.34371
0.19841
0.48555
0.42648
X3
0.26424
0.47388
0.92047
0.48848
0.35015
0.44681
0.32713
0.75690
0.22063
0.93997
Changing Seed_2 for the CALL RANTRI 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 RANTRI function has, however, no effect.
See Also
Function:
“RANTRI Function” on page 837
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
Note
See:
If seed ≤ 0, the time of day is used to initialize the seed stream.
“Seed Values” on page 273 for more information about seed values
x
is a numeric variable. A new value for the random variate x is returned each time
CALL RANUNI is executed.
402
CALL RANUNI Routine
4
Chapter 4
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 1005).
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.
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 nodate pageno=1 linesize=80 pagesize=60;
data case;
retain Seed_1 Seed_2 Seed_3 45;
do i=1 to 10;
call ranuni(Seed_1,X1);
call ranuni(Seed_2,X2);
X3=ranuni(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;
The following output shows the results:
Output 4.14
The RANUNI Example
The SAS System
i
1
2
3
4
5
6
7
8
9
10
Seed_1
694315054
1404437564
2130505156
1445125588
1013861398
1326029789
932142747
1988843719
516966271
2137808851
Seed_2
694315054
1404437564
2130505156
1445125588
18
707222751
991271755
422705333
1437043694
1264538018
1
Seed_3
X1
45
45
45
45
18
18
18
18
18
18
0.32332
0.65399
0.99209
0.67294
0.47212
0.61748
0.43406
0.92613
0.24073
0.99549
X2
0.32332
0.65399
0.99209
0.67294
0.47212
0.32933
0.46160
0.19684
0.66918
0.58885
X3
0.32332
0.65399
0.99209
0.67294
0.47212
0.61748
0.43406
0.92613
0.24073
0.99549
Functions and CALL Routines
4
CALL RXCHANGE Routine
403
Changing Seed_2 for the CALL RANUNI 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 RANUNI function, however, has no effect.
See Also
Function:
“RANUNI Function” on page 838
CALL RXCHANGE Routine
Changes one or more substrings that match a pattern
Category: Character String Matching
Restriction:
Use with the RXPARSE function
Syntax
CALL RXCHANGE (rx,times,old-string< ,new-string>);
Arguments
rx
specifies a numeric value that is returned from the RXPARSE function.
The value of rx points to an expression that is parsed by RXPARSE. CALL
RXCHANGE uses the expression to find and change a matching substring.
Tip:
times
is a numeric value that specifies the maximum number of times to change matching
substrings.
Restriction: Maximum value of times is 2,147,483,647.
old-string
specifies the character expression to be searched and changed as a result of the
change operation.
new-string
is a character variable that contains the result of the change operation.
Details
If old-string is a character variable, new-string is optional. If new-string is omitted,
old-string is changed in place.
If old-string is an expression that is not a character variable, you must specify
new-string.
404
CALL RXFREE Routine
4
Chapter 4
Comparisons
The regular expression (RX) functions and CALL routines work together to manipulate
strings that match patterns. Use the RXPARSE function to parse a pattern you specify.
Use the RXMATCH function and the CALL RXCHANGE and CALL RXSUBSTR
routines to match or modify your data. Use the CALL RXFREE routine to free allocated
space.
Example
See the RXPARSE function “Examples” on page 871.
See Also
Functions and CALL routines:
“CALL RXFREE Routine” on page 404
“CALL RXSUBSTR Routine” on page 405
“RXMATCH Function” on page 858
“RXPARSE Function” on page 859
CALL RXFREE Routine
Frees memory allocated by other regular expression (RX) functions and CALL routines
Category:
Restriction:
Character String Matching
Use with the RXPARSE function
Syntax
CALL RXFREE (rx);
Arguments
rx
specifies a numeric value that is returned from the RXPARSE function.
Comparisons
The regular expression (RX) functions and CALL routines work together to manipulate
strings that match patterns. Use the RXPARSE function to parse a pattern you specify.
Use the RXMATCH function and the CALL RXCHANGE and CALL RXSUBSTR
routines to match or modify your data. Use the CALL RXFREE routine to free allocated
space.
Example
See the RXPARSE function “Examples” on page 871.
Functions and CALL Routines
4
CALL RXSUBSTR Routine
405
See Also
Functions and CALL routines:
“CALL RXCHANGE Routine” on page 403
“CALL RXSUBSTR Routine” on page 405
“RXMATCH Function” on page 858
“RXPARSE Function” on page 859
CALL RXSUBSTR Routine
Finds the position, length, and score of a substring that matches a pattern
Category: Character String Matching
Restriction:
Use with the RXPARSE function
Syntax
CALL RXSUBSTR (rx, string, position);
CALL RXSUBSTR (rx, string, position, length);
CALL RXSUBSTR (rx, string, position, length, score);
Arguments
rx
specifies a numeric value that is returned from the RXPARSE function.
string
specifies the character expression to be searched.
position
specifies a numeric position in a string where the substring that is matched by the
pattern begins. If there is no match, the result is zero.
length
specifies a numeric value that is the length of the substring that is matched by the
pattern.
score
specifies an integer value based on the number of matches for a particular pattern in
a substring.
Details
CALL RXSUBSTR searches the variable string for the pattern from RXPARSE, returns
the position of the start of the string, indicates the length of the matched string, and
returns a score value. By default, when a pattern matches more than one substring
beginning at a specific position, the longest substring is selected.
406
CALL SCAN Routine
4
Chapter 4
Comparisons
CALL RXSUBSTR performs the same matching as RXMATCH, but CALL RXSUBSTR
additionally allows you to use the length and score arguments to receive more
information about the match.
The regular expression (RX) functions and CALL routines work together to
manipulate strings that match patterns. Use the RXPARSE function to parse a pattern
you specify. Use the RXMATCH function and the CALL RXCHANGE and CALL
RXSUBSTR routines to match or modify your data. Use the CALL RXFREE routine to
free allocated space.
Example
See the RXPARSE function “Examples” on page 871.
See Also
Functions and CALL routines:
“CALL RXCHANGE Routine” on page 403
“CALL RXFREE Routine” on page 404
“RXMATCH Function” on page 858
“RXPARSE Function” on page 859
CALL SCAN Routine
Returns the position and length of a given word from a character expression
Category:
Character
Syntax
CALL SCAN(string, n, position, length <,delimiters>);
Arguments
string
specifies a character constant, variable, or expression.
n
is a numeric constant, variable, or expression that specifies the number of the word
in the character string that you want the CALL SCAN routine to select. The
following rules apply:
3 If n is positive, CALL SCAN counts words from left to right.
3 If n is negative, CALL SCAN counts words from right to left.
3 If n is zero, or |n| is greater than the number of words in the character string,
CALL SCAN returns a position and length of zero.
Functions and CALL Routines
4
CALL SCAN Routine
407
position
specifies a numeric variable in which the position of the word is returned.
length
specifies a numeric variable in which the length of the word is returned.
delimiters
is a character constant, variable, or expression that specifies the characters that you
want CALL SCAN to use to separate words in the character string.
Default: If you omit delimiters in an ASCII environment, SAS uses the following
characters:
blank . < ( + & ! $ * ); ^ – / , % |
In ASCII environments without the ^ character, SCAN uses the ~ character
instead.
If you omit delimiters in an EBCDIC environment, SAS uses the following
characters:
blank . < ( + | & ! $ * ); – / , % | ¢
Tip: If you represent delimiters as a constant, enclose delimiters in quotation marks.
Details
In the context of the CALL SCAN routine, “word” refers to a substring that
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.
Delimiters that are located before the first word or after the last word in the
character string do not affect the CALL SCAN routine. If two or more contiguous
delimiters exist, CALL SCAN treats them as one.
To retrieve the designated word as a character string after the call to CALL SCAN,
use the following function:
substrn(string, position, length)
Comparisons
The CALL SCANQ routine ignores delimiters that are enclosed in quotation marks.
CALL SCAN does not.
Examples
The following example shows how you can use the CALL SCAN routine.
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;
408
CALL SCANQ Routine
4
Chapter 4
Picasso Toulouse-Lautrec Turner "Van Gogh" Velazquez
;
proc print data=artists;
run;
Output 4.15
SAS Output from the CALL SCAN Routine
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
See Also
Functions and CALL Routines:
“SCAN Function” on page 875
“SCANQ Function” on page 876
“CALL SCANQ Routine” on page 408
CALL SCANQ Routine
Returns the position and length of a given word from a character expression, and ignores
delimiters that are enclosed in quotation marks
Category:
Character
Syntax
CALL SCANQ(string, n, position, length <,delimiters>);
Arguments
string
specifies a character constant, variable, or expression.
n
is a numeric constant, variable, or expression that specifies the number of the word
in the character string that you want the CALL SCANQ routine to select. The
following rules apply:
3 If n is positive, CALL SCANQ counts words from left to right.
Functions and CALL Routines
4
CALL SCANQ Routine
409
3 If n is negative, CALL SCANQ counts words from right to left.
3 If n is zero, or |n| is greater than the number of words in the character string,
CALL SCANQ returns a position and length of zero.
position
specifies a numeric variable in which the position of the word is returned.
length
specifies a numeric variable in which the length of the word is returned.
delimiters
is a character constant, variable, or expression that specifies the characters that you
want CALL SCANQ to use to separate words in the character string.
Default: If you omit delimiters CALL SCANQ uses white space characters (blank,
horizontal and vertical tab, carriage return, line feed, and form feed) as delimiters.
Restriction: You cannot use single or double quotation marks as delimiters.
Details
In the context of the CALL SCANQ routine, “word” refers to a substring that
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 those that are enclosed in quotation marks.
If the value of the character string contains quotation marks, CALL SCANQ ignores
delimiters inside the strings in quotation marks. If the value of the character string
contains unmatched quotation marks, then scanning from left to right will produce
different words than scanning from right to left.
Delimiters that are located before the first word or after the last word in the
character string do not affect the CALL SCANQ routine. If two or more contiguous
delimiters exist, CALL SCANQ treats them as one.
To retrieve the designated word as a character string after the call to CALL SCANQ,
use the following function:
substrn(string, position, length)
Comparisons
The CALL SCANQ routine ignores delimiters that are enclosed in quotation marks.
CALL SCAN does not.
Examples
The following example shows how you can use the CALL SCANQ routine.
options pageno=1 nodate ls=80 ps=64;
data artists2;
input string $60.;
drop string;
do i=1 to 99;
call scanq(string, i, position, length);
if not position then leave;
Name=substrn(string, position, length);
output;
end;
410
CALL SET Routine
4
Chapter 4
datalines;
Picasso Toulouse-Lautrec Turner "Van Gogh" Velazquez
;
proc print data=artists2;
run;
Output 4.16
SAS Output from the CALL SCANQ Routine
The SAS System
Obs
i
position
length
1
2
3
4
5
1
2
3
4
5
1
9
26
33
44
7
16
6
10
9
1
Name
Picasso
Toulouse-Lautrec
Turner
"Van Gogh"
Velazquez
See Also
Functions and CALL Routines:
“SCAN Function” on page 875
“SCANQ Function” on page 876
“CALL SCAN Routine” on page 406
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
Functions and CALL Routines
4
CALL SET Routine
411
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
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 548
“FETCHOBS Function” on page 549
“GETVARC Function” on page 602
“GETVARN Function” on page 603
412
CALL SLEEP Routine
4
Chapter 4
CALL SLEEP Routine
Suspends the execution of a program that invokes this call routine for a specified period of time
Special
See: CALL SLEEP Routine in the documentation for your operating environment.
Category:
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
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;
Functions and CALL Routines
4
CALL SOFTMAX Routine
413
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 885
CALL SOFTMAX Routine
Returns the softmax value
Category: Mathematical
Syntax
CALL SOFTMAX(argument<,argument,…>);
Arguments
argument
is numeric.
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.
414
CALL STDIZE Routine
4
Chapter 4
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 STDIZE Routine
Standardizes the values of one or more variables
Category:
Mathematical
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.
Default: STD
Restriction: Use a separate argument for each option because you cannot specify
more than one option in a single argument.
Character expressions can end with an equal sign that is followed by another
argument that is a numeric constant, variable, or expression.
Tip:
Functions and CALL Routines
4
CALL STDIZE Routine
415
See Also: PROC STDIZE in SAS/STAT User’s Guide, Volumes 1, 2, and 3 for
information about formulas and other details. The options that are used in CALL
STDIZE are the same as those used in PROC STDIZE.
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.
416
4
CALL STDIZE Routine
Chapter 4
SUM
specifies the result that you obtain when you add numbers.
USTD
unstandardizes variables when you also specify the METHOD=IN option.
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.
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.
Default: DF
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.
Functions and CALL Routines
4
CALL STDIZE Routine
417
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, Volumes 1, 2, and 3.
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
418
4
CALL STREAMINIT Routine
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.
Range:
< 231 0 1
seed
If you specify a nonpositive seed, then CALL STREAMINIT is ignored. Any
subsequent random number generation seeds itself from the system clock.
Tip:
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 273.
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.17
4
CALL SYMPUT Routine
419
Random 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
Function:
“RAND Function” on page 816
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 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.
420
4
CALL SYMPUTX Routine
Chapter 4
See Also
Function:
“SYMGET Function” on page 910
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.
Functions and CALL Routines
4
CALL SYMPUTX Routine
421
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 might be the global symbol table.
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
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!;
’,
422
CALL SYSTEM Routine
4
Chapter 4
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” on page 910
“CALL SYMPUT Routine” on page 419
CALL SYSTEM Routine
Submits an operating environment command for execution
Special
See: CALL SYSTEM Routine in the documentation for your operating environment.
Category:
Syntax
CALL SYSTEM(command);
Arguments
command
specifies any of the following: a system command that is enclosed in quotation marks
(explicit 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 on 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 920
Functions and CALL Routines
4
CALL TANH Routine
423
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.
Details
The subroutine TANH replaces each argument by the tanh of that argument. For
example xj is replaced by
tanh (xj ) =
exj
exj
0 e0x
+ e0x
j
j
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 922
424
CALL VNAME Routine
4
Chapter 4
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.
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;
Functions and CALL Routines
4
CALL VNEXT Routine
425
See Also
Functions:
“VNAME Function” on page 982
“VNAMEX Function” on page 983
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>>);
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.
426
CALL VNEXT Routine
4
Chapter 4
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;
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
;
The following lines are written to the SAS log:
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_
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
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
Functions and CALL Routines
i=15 _N_
i=16
4
CAT Function
427
type=N length=8
type= length=0
CAT Function
Concatenates character strings without removing leading or trailing blanks
Category: Character
Syntax
CAT(string-1 <, ... string-n>)
Arguments
string
specifies a SAS character string.
Details
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 a length of up to
3 200 characters in WHERE clauses and in PROC SQL
3 32767 characters in the DATA step except in WHERE clauses
3 65534 characters when string 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
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 BEST. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
those that are produced by certain combinations of the concatenation operator (||) and
the TRIM and LEFT functions. However, 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.
428
CAT 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 separator,
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 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;
’;
The following line is written to the SAS 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:
“CATS Function” on page 429
“CATT Function” on page 430
“CATX Function” on page 432
“CALL CATS Routine” on page 353
“CALL CATT Routine” on page 355
“CALL CATX Routine” on page 356
Functions and CALL Routines
4
CATS Function
429
CATS Function
Concatenates character strings and removes leading and trailing blanks
Category: Character
Syntax
CATS(string-1 <, ...string-n>)
Arguments
string
specifies a SAS character string.
Details
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 a length of up to
3 200 characters in WHERE clauses and in PROC SQL
3 32767 characters in the DATA step except in WHERE clauses
3 65534 characters when string 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
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 BEST. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
those that are produced by certain combinations of the concatenation operator (||) and
the TRIM and LEFT functions. However, 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 separator,
such as a blank or comma.
430
CATT 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 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:
“CAT Function” on page 427
“CATX Function” on page 432
“CATT Function” on page 430
“CALL CATS Routine” on page 353
“CALL CATT Routine” on page 355
“CALL CATX Routine” on page 356
CATT Function
Concatenates character strings and removes trailing blanks
Category:
Character
Syntax
CATT(string-1 <, ...string-n>)
Functions and CALL Routines
4
CATT Function
431
Arguments
string
specifies a SAS character string.
Details
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 a length of up to
3 200 characters in WHERE clauses and in PROC SQL
3 32767 characters in the DATA step except in WHERE clauses
3 65534 characters when string 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
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 BEST. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
those that are produced by certain combinations of the concatenation operator (||) and
the TRIM and LEFT functions. However, 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 separator,
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))
432
CATX Function
4
Chapter 4
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:
“CAT Function” on page 427
“CATS Function” on page 429
“CATX Function” on page 432
“CALL CATS Routine” on page 353
“CALL CATT Routine” on page 355
“CALL CATX Routine” on page 356
CATX Function
Concatenates character strings, removes leading and trailing blanks, and inserts separators
Category:
Character
Syntax
CATX(separator, string-1 <, ...string-n>)
Arguments
separator
specifies a character string that is used as a separator between concatenated strings.
string
specifies a SAS character string.
Details
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 a length of up to
Functions and CALL Routines
4
CATX Function
433
3 200 characters in WHERE clauses and in PROC SQL
3 32767 characters in the DATA step except in WHERE clauses
3 65534 characters when string 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.
If the length of the variable or the buffer is not large enough to contain the result of
the concatenation, SAS
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 CATX function removes leading and trailing blanks from numeric arguments
after it formats the numeric value with the BEST. format.
Comparisons
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to
those that are produced by certain combinations of the concatenation operator (||) and
the TRIM and LEFT functions. However, 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 separator,
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 CATX function concatenates strings.
data _null_;
separator=’%%$%%’;
x=’The Olympic ’;
y=’
Arts Festival ’;
z=’
includes works by ’;
a=’Dale Chihuly.’;
result=catx(separator,x,y,z,a);
434
CDF Function
4
Chapter 4
put result $char.;
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.
See Also
Functions and CALL Routines:
“CAT Function” on page 427
“CATT Function” on page 430
“CATS Function” on page 429
“CALL CATS Routine” on page 353
“CALL CATT Routine” on page 355
“CALL CATX Routine” on page 356
CDF Function
Computes cumulative distribution functions
Category:
Probability
Syntax
CDF (’dist’,quantile,<,parm-1, ... ,parm-k>)
Arguments
’dist’
is a character string 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’
Functions and CALL Routines
Distribution
Argument
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’
Wald (inverse Gaussian)
’WALD’|’IGAUSS’
Weibull
’WEIBULL’
4
CDF Function
435
Note: Except for T, F, and NORMALMIX, you can minimally identify any
distribution by its first four characters. 4
quantile
is a numeric random variable.
parm-1, ... ,parm-k
are optional shape, location, or scale parameters appropriate for the specific
distribution.
See: “Details” on page 435 for complete information about these parameters
Details
The CDF function computes the left cumulative distribution function from various
continuous and discrete distributions.
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 =
0
(0
1
1
0p
x<0
0x<1
x1
436
CDF Function
4
Chapter 4
Note:
There are no location or scale parameters for this distribution.
4
Beta Distribution
CDF(’BETA’,x,a,b<,l,r>)
where
x
is a numeric random variable.
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 x. The following equation describes the CDF function of the beta distribution:
00
1
CDF BETA ; x; a; b; l; r =
0
8
0
>
<
Rx (x01)a01 (r0x)b01
1
dx
a+b01
(a;b)
(r 0l )
>
:
l
1
where
(a; b) =
0 ( a) 0 ( b)
0 ( a + b)
and
Z1
0 ( a) =
0
xa01 e0x dx
x1
l<xr
x>r
Functions and CALL Routines
4
CDF Function
437
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.
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 i
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 CAUCHY ; x; ; 0
=
1
1
+ tan01
2 x0
438
CDF Function
4
Chapter 4
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
non-integer degrees of freedom. If nc is omitted or equal to zero, the value returned is
from the central chi-square distribution. The following equation describes the CDF
function of the chi-square distribution:
(0
P
x<0
1
j
(
)
CDF CHISQ ; x; ; =
e0 j Pc (x; + 2j ) x 0
00
1
0
j
2
=0
2
!
where Pc(.,.) denotes the probability from the central chi-square distribution:
x a
Pc (x; a) = Pg ;
2 2
and where Pg(y,b) is the probability from the Gamma distribution given by
Pg (y; b) =
Zy
Exponential Distribution
CDF(’EXPONENTIAL’,x < , >)
where
x
is a numeric random variable.
is a scale parameter.
Default: 1
Range:
>0
b
0( )
0
e0v vb0 dv
Functions and CALL Routines
4
CDF Function
439
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
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. The following
equation describes the CDF function of the F distribution:
00
1
CDF F 0 ; x; v1 ; v2 ; =
(0
1
P
()
e0 2 2j ! Pf (f; v1 + 2j; v2 )
j =0
j
x<0
x0
where Pf(f,u1,u2) is the probability from the central F distribution with
Pf (f; u1 ; u2 ) = PB
u1 f u1 u2
; ;
u1 f + u 2 2 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
440
CDF Function
4
Chapter 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:
00
CDF GAMMA ; x; a; 0
1
=
(
0
Rx a01 0 v
1
e dv
a
0(a) v
0
x<0
x0
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
8
<0
jP
m
p (1
:
j=0
m<0
0 p)j m 0
There are no location or scale parameters for this distribution.
4
Functions and CALL Routines
4
CDF Function
441
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:
00
1
CDF 8HY P ER ; x; N; R; n; o =
0
0
>
>
>
>
>
>
<
>
>
>
>
>
>
:
x
P
P
i =0
m in(R;n)
j=max(0;R+n
R N 0R
i n0i
0N )
R
j
x < max (0; R + n 0 N )
oi
N 0R
n0j
o
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
max (0; R + n 0 N ) x min (R; n)
j
x > min (R; n)
442
CDF Function
4
Chapter 4
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 ; x; ; 0
1
=
(
)
1 e (x0
2
( x0 )
1 12 e(0 )
0
x>0
x
0
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:
00
1
CDF LOGIST IC ; x; ; 0
=
1
1 + e0
x 0
Lognormal Distribution
CDF(’LOGNORMAL’,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 lognormal distribution returns the probability that an
observation from a lognormal distribution, with the location parameter and the scale
parameter , is less than or equal to x. The equation follows:
00
1
CDF LOGN 0 ; x; ; =
8
<0
: p2
1
logR(x)
o
exp
0 (v20)
2
2
x0
dv
x>0
Functions and CALL Routines
4
CDF Function
443
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:
00
1
CDF NEGB ; m; p; n =
0
8
<0
m
nP
p
:
j =0
n+j01
j
(1
0 p)
j
m<0
m0
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
Normal Mixture Distribution
CDF(’NORMALMIX’,x,n,p,m,s)
= p
1
2
Zx
01
exp
2
0 202)
(v
!
dv
444
CDF Function
4
Chapter 4
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
P
i=n
i=1
p
i
= 1.
Range: p = 0, 1, ...
m
is the n means
m1 ; m 2 ; . . . ; m
n.
s
is the n standard deviations s1 ; s2 ; . . . ; sn .
s>0
Range:
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:
C DF
00
0
N ORM ALM I X ; x; n; p; m; s
1
i=n
X
=
i
p C DF
i=1
00
0
i i
N ORM AL ; x; m ; s
1
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:
C DF
00
0
P ARE T O ; x; a; k
1
=
0
1
0
0 k 1a
x
x < k
x
k
Functions and CALL Routines
4
CDF Function
445
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 =
Note:
0
(
0
n
P
i=0
0
i
exp ( m) mi!
n<0
n0
There are no location or scale parameters for the Poisson distribution.
4
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. The
equation follows:
00
1
CDF T ; t; v; =
Note:
0
Z1
2(
1
2v
0) 0
0v1
2
0
xv01e0 2 x
1 2
p12
ptx
Zv
01
e0 2 (u0) dudx
1
2
There are no location or scale parameters for the T distribution.
Uniform Distribution
CDF(’UNIFORM’,x< ,l,r>)
4
446
CDF Function
4
Chapter 4
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
x<l
lx<r
xr
x0l
r
1
0
l
The default values for l and r are 0 and 1, respectively.
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 ALD0 ; x; d =
(
0 8 (x
0 1)
q d
x
+ e2d 8
0 (x + 1)
q d
x
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.
Weibull Distribution
CDF(’WEIBULL’,x,a<, >)
where
x
is a numeric random variable.
4
Functions and CALL Routines
4
CDF Function
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 EIBULL ; x; a; =
0
n
0
1
x<0
0 e0( x ) x 0
a
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
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
447
448
CEIL Function
4
Chapter 4
CEIL Function
Returns the smallest integer that is greater than or equal to the argument, fuzzed to avoid
unexpected floating-point results
Category:
Truncation
Syntax
CEIL (argument)
Arguments
argument
is numeric.
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
Functions and CALL Routines
SAS Statements
Results
g=ceil(763);
put g;
763
h=ceil(-223.456);
put h;
-223
4
CEILZ Function
See Also
Functions:
“CEILZ Function” on page 449
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
449
450
CEXIST Function
4
Chapter 4
SAS Statements
Results
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
Functions:
“CEIL Function” on page 448
“FLOOR Function” on page 571
“FLOORZ Function” on page 572
“INT Function” on page 629
“INTZ Function” on page 640
“ROUND Function” on page 845
“ROUNDE Function” on page 853
“ROUNDZ Function” on page 855
CEXIST Function
Verifies the existence of a SAS catalog or SAS catalog entry
Category:
SAS File I/O
Syntax
CEXIST(entry< ,’U’>)
Arguments
entry
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 threeor four-level name to test for the existence of an entry within a catalog.
’U’
tests whether the catalog can be opened for updating.
Functions and CALL Routines
4
CHOOSEC Function
451
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
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
Function:
“EXIST Function” on page 538
CHOOSEC Function
Returns a character value that represents the results of choosing from a list of arguments
Category: Character
Syntax
CHOOSEC (index-expression, selection-1 <,…selection-n>)
Arguments
index-expression
specifies a numeric expression.
452
CHOOSEN Function
4
Chapter 4
selection
specifies a character expression that is returned.
Details
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 452
CHOOSEN Function
Returns a numeric value that represents the results of choosing from a list of arguments
Category:
Character
Syntax
CHOOSEN (index-expression, selection-1 <,…selection-n>)
Functions and CALL Routines
4
CINV Function
Arguments
index-expression
specifies a numeric expression.
selection
specifies a numeric expression that is returned.
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 451
CINV Function
Returns a quantile from the chi-squared distribution
Category: Quantile
Syntax
CINV (p,df<,nc>)
453
454
CINV Function
4
Chapter 4
Arguments
p
is a numeric probability.
Range: 0 ≤ p < 1
df
is a numeric degrees of freedom parameter.
df > 0
Range:
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.
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
4
Functions and CALL Routines
4
CLOSE Function
455
CLOSE Function
Closes a SAS data set
Category: SAS File I/O
Syntax
CLOSE(data-set-id)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
Details
CLOSE returns 0 if the operation was successful, ≠0 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
3 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));
456
CNONCT Function
4
Chapter 4
3 This example opens the SAS data set MYDATA within a DATA step. MYDATA is
closed automatically at the end of the DATA step. You do not need to use CLOSE
to close the file.
data _null_;
dsid=open(’mydata’,’i’);
if dsid > 0 then do;
...more statements...
end;
run;
See Also
Function:
“OPEN Function” on page 732
CNONCT Function
Returns the noncentrality parameter from a chi-squared 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.
Range: df > 0
Functions and CALL Routines
4
CNONCT Function
457
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
t
a01 e0t dt
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;
458
COALESCE Function
4
Output 4.18
Distribution
Chapter 4
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
is numeric. argument can be one of the following items:
3 a numeric value
3 a missing numeric value
3 the name of a numeric variable.
Details
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.
Functions and CALL Routines
4
COALESCEC Function
459
Examples
SAS Statements
Results
x = COALESCE(42, .);
42
y = COALESCE(.A, .B, .C);
.
z = COALESCE(., 7, ., ., 42);
7
See Also
Function:
“COALESCEC Function” on page 459
COALESCEC Function
Returns the first non-missing value from a list of character arguments.
Category: Character
Syntax
COALESCEC(argument-1<..., argument-n>)
Arguments
argument
a character value. argument can be one of the following items:
3 a character value
3 a missing character value
3 the name of a character variable.
Details
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. If all the values of all arguments are missing, then
the COALESCEC function returns a missing value.
460
COLLATE Function
4
Chapter 4
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
See Also
Function:
“COALESCE Function” on page 458
COLLATE Function
Returns an ASCII or EBCDIC collating sequence character string
Category:
See:
Character
COLLATE Function in the documentation for your operating environment.
Syntax
COLLATE (start-position<,end-position>) | (start-position<,,length>)
Functions and CALL Routines
4
COLLATE Function
461
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.
Details
If the COLLATE function returns a value to a variable that has not yet been assigned a
length, by default the variable is assigned a length of 200.
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.
462
COMB Function
4
Chapter 4
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 350
“RANK Function” on page 833
COMB Function
Computes the number of combinations of n elements taken r at a time
Category:
Mathematical
Functions and CALL Routines
4
COMPARE Function
463
Syntax
COMB(n, r)
Arguments
n
is an integer that represents the total number of elements from which the sample is
chosen.
r
is an 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.
Examples
SAS Statements
Results
x=comb(5,1);
5
See Also
Functions:
“FACT Function” on page 541
“PERM Function” on page 760
COMPARE Function
Returns the position of the leftmost character by which two strings differ, or returns 0 if there is no
difference
Category: Character
464
COMPARE Function
4
Chapter 4
Syntax
COMPARE(string–1, string–2<,modifiers>)
Arguments
string–1
specifies a character constant, variable, or expression.
string–2
specifies a character constant, variable, or expression.
modifiers
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 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. 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 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 n-literals.
3 “NL” first removes quotation marks from n-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
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.
Examples
Example 1: Understanding the Order of Comparisons When Comparing Two Strings
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;
The
Functions and CALL Routines
4
COMPARE Function
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.19
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
Example 2: Truncating Strings Using the COMPARE Function
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;
result
0
-1
-3
1
-2
0
-1
0
2
-3
1
0
-1
1
0
The following example
465
466
COMPBL Function
4
Chapter 4
proc print data=test2 noobs;
run;
The following output shows the results.
Output 4.20
Results of Using the Truncation Modifier
The SAS System
pad1
0
1
pad2
truncate1
truncate2
-4
0
0
blank
-1
See Also
Functions and CALL Routines:
“COMPGED Function” on page 467
“COMPLEV Function” on page 472
“CALL COMPCOST Routine” on page 358
COMPBL Function
Removes multiple blanks from a character string
Category:
Character
Syntax
COMPBL(source)
Arguments
source
specifies the source string to compress.
Details
If the COMPBL function returns a value to a variable that has not yet been assigned a
length, by default the variable length is determined by the length of the first argument.
The COMPBL function removes multiple blanks in a character string by translating
each occurrence of two or more consecutive blanks into a single blank.
The default length of the value that COMPBL returns is the same as the length of
the argument.
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
Functions and CALL Routines
4
COMPGED Function
467
COMPRESS function is similar to the COMPBL function. However, the COMPRESS
function removes all blanks from the source string, while the COMPBL function
compresses multiple blanks to a single blank and has no affect 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 476
COMPGED Function
Compares two strings by computing the generalized edit distance
Category: Character
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 acutal generalized edit distance
is greater than the value of cutoff, the value that is returned is equal to the value of
cutoff.
468
COMPGED Function
4
Chapter 4
Using a small value of cutoff improves the efficiency of COMPGED if the
values of string–1 and string–2 are long.
Tip:
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.
The operations and their costs are described in the following table.
Functions and CALL Routines
4
COMPGED Function
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.
469
470
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 kinds 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 kinds 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
471
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
472
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.21
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 463
“CALL COMPCOST Routine” on page 358
“COMPLEV Function” on page 472
COMPLEV Function
Compares two strings by computing the Levenshtein edit distance
Category:
Character
1
Functions and CALL Routines
4
COMPLEV Function
473
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.
cuttoff
specifies a numeric constant, variable, or expression. If the acutal 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 COMPGED 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.
474
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.22
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
1
modifiers
i
l
n
result
0
1
1
1
2
3
4
6
1
0
2
0
6
1
Functions and CALL Routines
See Also
Functions and CALL Routines:
“COMPARE Function” on page 463
“COMPGED Function” on page 467
“CALL COMPCOST Routine” on page 358
COMPOUND Function
Returns compound interest parameters
Category: Financial
Syntax
COMPOUND(a,f,r,n)
Arguments
a
is numeric, the initial amount.
Range: a ≥ 0
f
is numeric, the future amount (at the end of n periods).
Range: f ≥ 0
r
is numeric, the periodic interest rate expressed as a fraction.
Range: r ≥ 0
n
is an integer, the number of compounding periods.
Range: n ≥ 0
4
COMPOUND Function
475
476
COMPRESS Function
4
Chapter 4
Details
The COMPOUND function returns the missing argument in the list of four arguments
from a compound interest calculation. The arguments are related by
f
= a (1 + r)n
One missing argument must be provided. It is then calculated from the remaining
three. No adjustment is made to convert the results to round numbers.
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
Removes specific characters from a character string
Category:
Character
Syntax
COMPRESS(< source><, chars>< , modifiers>)
Arguments
source
specifies a source string that contains characters to remove.
Functions and CALL Routines
4
COMPRESS Function
477
chars
specifies a character string that initializes a list of characters. By default, the
characters in this list are removed from the source. If you specify the “K” modifier in
the third argument, then only the characters in this list are kept in the result.
Tip: You can add more characters to this list by using other modifiers in the third
argument.
Tip: Enclose a literal string of characters in quotation marks.
modifiers
specifies a character string in which each character modifies the action of the
COMPRESS function. Blanks are ignored. These are the characters that can be used
as modifiers:
a or A
adds letters of the Latin alphabet (A - Z, a - z) to the list of
characters.
c or C
adds control characters to the list of characters.
d or D
adds numerals to the list of characters.
f or F
adds the underscore character and letters of the Latin alphabet
(A - Z, a - z) to the list of characters.
g or G
adds graphic characters 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 (a - z) to the list of characters.
n or N
adds numerals, the underscore character, and letters of the Latin
alphabet (A - Z, a - z) 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 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 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 first and second arguments.
u or U
adds uppercase letters (A - Z) to the list of characters.
w or W
adds printable characters to the list of characters (“W” for
writable, because “P” is used for punctuation).
x or X
adds hexadecimal characters to the list of characters.
478
COMPRESS Function
4
Chapter 4
Details
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:
If you call the COMPRESS function with…
The result is…
only the first argument, source
The argument with 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 modifiers
The “k” or “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” or “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 could use either of the following
function calls:
COMPRESS(source, "1234567890+-");
COMPRESS(source, "+-", "d");
If the COMPRESS function returns a value to a variable that has not yet been
assigned a length, then by default the variable length is determined by the length of
the first argument.
Examples
Example 1: Compressing Blanks
SAS Statements
Results
----+----1
a=’AB C D ’;
b=compress(a);
put b;
ABCD
Functions and CALL Routines
4
COMPRESS Function
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
Example 3: Compressing Tab 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;
See Also
Functions:
“COMPBL Function” on page 466
“LEFT Function” on page 661
“TRIM Function” on page 931
ABA
479
480
CONSTANT Function
4
Chapter 4
CONSTANT Function
Computes some machine and mathematical constants
Category:
Mathematical
Syntax
CONSTANT(constant<, parameter>)
Arguments
constant
is a character string that identifies the constant. Valid constants are as follows:
Constant
Argument
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’
Functions and CALL Routines
4
CONSTANT Function
481
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
The natural base
CONSTANT(’E’)
The natural base is described by the following equation:
1
!
lim (1 +
x 0
x) x
:
2 71828182 8459045
Euler constant
CONSTANT(’EULER’)
Euler’s constant is described by the following equation:
8=
<X 1
0
n !1 :
=
j
n
j
1
lim
j
9
=
;
log (n )
0:577215664901532860
Pi
CONSTANT(’PI’)
Pi is the well-known constant in trigonometry that 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
482
CONSTANT Function
4
Chapter 4
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 log with respect to base of BIG
CONSTANT(’LOGBIG’ <, 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 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.
Functions and CALL Routines
4
CONSTANT Function
483
The log with respect to base 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 machine.
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’)
20j
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. A number n1 is
considered larger than another number n2 if the (8-byte) representation of n1 + n2 is
identical to n1. This constant can be used in summing series to implement a machine
dependent stopping criterion.
=
The log with respect to base 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’).
484
CONVX Function
4
Chapter 4
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
PK k k
C=
k=1
(
P
+ f)
c(k )
2
(1 + fy )
where
X
K
P
=
k
(1+f y ) f
c (k )
k
f
k=1 (1 + f y )
Functions and CALL Routines
4
CONVXP Function
485
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:
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
486
COS Function
4
Chapter 4
y
specifies the nominal per-period yield-to-maturity, expressed as a fraction.
Range:
y>0
Details
The CONVXP function returns the value
1
C= 2
n
where
0 PK
c(k )
tk (tk + 1)
B
(1+ )
B
k=1 0
B
1
@ P 1 + ny 2
y tk
n
0
tk = nk0 + k 1
c (k) = nc A f or k = 1; . . . ; K
c (K) = 1 + nc A
0
1
1
C
C
C
A
01
and where
P =
K
X
k=1
01 c+(k)y 1t
n
k
Examples
The following example demonstrates the use of CONVXP with a face value of 1000,
an annual coupon rate of 0.01, 4 coupons per year, 14 remaining coupons, time from
settlement date to next coupon is 0.165, and the price with accrued interest is 800.
data _null_;
y=convxp(1000,.01,4,14,.33/2,800);
put y;
run;
The value returned is 11.6023.
COS Function
Returns the cosine
Category:
Trigonometric
Syntax
COS (argument)
Functions and CALL Routines
4
COSH Function
Arguments
argument
is numeric and is specified in radians.
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
is numeric.
Details
The COSH function returns the hyperbolic cosine of the argument, given by
0 argument
e
+ e0argument
1
=2
Examples
SAS Statements
Results
x=cosh(0);
1
x=cosh(-5.0);
74.209948525
x=cosh(0.5);
1.1276259652
487
488
COUNT Function
4
Chapter 4
COUNT Function
Counts the number of times that a specific substring of characters appears within a character
string that you specify
Category:
Character
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 that evaluates to one or more constants.
Tip:
Details
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, inconsistent results will
be returned. For example, COUNT(’boobooboo’, ’booboo’) might return either a 1 or a
2. 4
Comparisons
The COUNT function counts substrings of characters in a character string, whereas the
COUNTC function counts individual characters in a character string.
Functions and CALL Routines
4
COUNT Function
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:
“COUNTC Function” on page 490
“FIND Function” on page 558
“INDEX Function” on page 620
“RXMATCH Function” on page 858
489
490
COUNTC Function
4
Chapter 4
COUNTC Function
Counts the number of specific characters that either appear or do not appear within a character
string that you specify
Category:
Character
Syntax
COUNTC(string,characters<,modifiers>)
Arguments
string
specifies a character constant, variable, or expression in which characters are to be
counted.
Tip: Enclose a literal string of characters in quotation marks.
characters
is a character constant, variable, or expression that specifies one or more 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, COUNTC only counts characters with the same case as
the characters in characters.
o
processes characters and modifiers only once, at the first call to
this instance of COUNTC. Consequently, if you change the value
of characters or modifiers in subsequent calls, the change is
ignored by COUNTC.
t
trims trailing blanks from string and characters.
v
counts only the characters that do not appear in characters.
Tip: 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 that evaluates to one or more constants.
Details
The COUNTC function searches string for all occurrences of the specified characters
and returns the count for all of those characters. If none are found, COUNTC returns a
value of 0.
Functions and CALL Routines
4
CSS Function
491
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 SAS statements produce these results:
SAS Statements
Results
xyz=’Baboons Eat Bananas
howmanya=countc(xyz,’a’);
put howmanya;
’;
xyz=’Baboons Eat Bananas
howmanyb=countc(xyz,’b’);
put howmanyb;
’;
5
howmanyb_i=countc(’Baboons Eat Bananas
put howmanyb_i;
1
’,’b’,’i’);
3
xyz=’Baboons Eat Bananas
’;
howmanyab_i=countc(xyz,’ab’,’i’);
put howmanyab_i;
8
variable1=’Baboons Eat Bananas
’;
variable2=’ab’;
variable3=’iv’;
howmanyab_iv=countc(variable1,variable2,variable3);
put howmanyab_iv;
16
expression1=’Baboons ’||’Eat Bananas
’;
expression2=trim(’ab
’);
expression3=compress(’i
’||’v’||’
t’);
howmanyab_ivt=countc(expression1,expression2,expression3);
put howmanyab_ivt;
11
See Also
Functions:
“COUNT Function” on page 488
“FINDC Function” on page 560
“INDEXC Function” on page 621
“VERIFY Function” on page 955
CSS Function
Returns the corrected sum of squares
Category: Descriptive Statistics
492
CUROBS Function
4
Chapter 4
Syntax
CSS(argument-1< ,argument-n>)
Arguments
argument
is numeric. 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
Syntax
CUROBS(data-set-id)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
Details
CAUTION:
Use this function only with an uncompressed SAS data set that is accessed using a native
library engine. 4
If the engine being used does not support observation numbers, the function returns
a missing value.
Functions and CALL Routines
4
CV Function
493
With a SAS data view, the function returns the relative observation number, that is,
the number of the observation within the SAS data 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 549
“OPEN Function” on page 732
CV Function
Returns the coefficient of variation
Category: Descriptive Statistics
Syntax
CV(argument,argument, ...)
Arguments
argument
is numeric. At least two arguments are required. The argument list may 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
494
DACCDB Function
4
Chapter 4
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
DACCDB(p
; v;
y; r
)=
(0
v
1
0 1 0 yr
int(p) 1
0 (p 0 int (p)) yr
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.
Functions and CALL Routines
4
DACCDBSL Function
495
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
DACCDBSL (p
; v; y; r
X
) = DEPDBSL (
p
i=1
i; v; y; r
)
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.
496
DACCSL Function
4
Chapter 4
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
DACCSL (p
; v; y
80
0
< p
)=: y 0py
v
p>y
p <
v
The p and y arguments must be expressed by using the same units of time.
Example
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.
Functions and CALL Routines
4
DACCSYD Function
497
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
8
<0
)=:
v
v
0 nt p 0 )+(p0int(p))(y0int(p))
int(y)(y0 int y 0 )+(y0int(y))
int(p)(y
i
( ) 1
2
( ) 1
2
2
p <
0
0
py
p>y
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.
498
DACCTAB Function
4
Chapter 4
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 + t2 + ::: + tint(p) + (p
v
0 int (p)) t
int(p)+1
1
p 0
0<p<n
p n
For a given p, only the arguments t1 ; t2 ; . . . ; tk need to be specified with k=ceil(p).
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.
Functions and CALL Routines
4
DATDIF Function
DAIRY Function
Returns the derivative of the AIRY function
Category: Mathematical
Syntax
DAIRY(x)
Arguments
x
is numeric.
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
Category: Date and Time
Syntax
DATDIF(sdate,edate,basis)
499
500
DATDIF Function
4
Chapter 4
Arguments
sdate
specifies a SAS date value that identifies the starting date.
edate
specifies a SAS date value that identifies the ending date.
basis
identifies a character constant or variable that describes how SAS calculates the date
difference. The following character strings are valid:
’30/360’
specifies a 30 day month and a 360 day year. Each month is considered to have 30
days, and each year 360 days, regardless of the actual number of days in each
month or year.
Alias: ’360’
Tip: If either date falls at the end of a month, SAS treats the date as if it were the
last day of a 30-day month.
’ACT/ACT’
uses the actual number of days between dates.
Alias: ’Actual’
Examples
In the following example, DATDIF returns the actual number of days between two
dates, and the number of days based on a 30-month and 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
See Also
Functions:
“YRDIF Function” on page 993
Functions and CALL Routines
4
DATEJUL Function
DATE Function
Returns the current date as a SAS date value
Category: Date and Time
Alias:
See:
TODAY
“TODAY Function” on page 926
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:
SAS Statements
Xstart=datejul(94365);
put Xstart / Xstart date9.;
Xend=datejul(2001001);
put Xend / Xend date9.;
Results
12783
31DEC1994
14976
01JAN2001
501
502
DATEPART Function
4
Chapter 4
See Also
Function:
“JULDATE Function” on page 646
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:
“DATETIME Function” on page 502
“TIMEPART Function” on page 923
DATETIME Function
Returns the current date and time of day as a SAS datetime value
Category:
Date and Time
Functions and CALL Routines
4
DAY Function
503
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 501
“TIME Function” on page 922
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.
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
504
DCLOSE Function
4
Chapter 4
See Also
Functions:
“MONTH Function” on page 695
“YEAR Function” on page 991
DCLOSE Function
Closes a directory that was opened by the DOPEN function
Category:
External Files
Syntax
DCLOSE(directory-id)
Argument
directory-id
specifies the identifier that was assigned when the directory was opened, generally
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
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. */
Functions and CALL Routines
4
DCREATE Function
505
%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 527
“FCLOSE Function” on page 544
“FOPEN Function” on page 578
“MOPEN Function” on page 696
DCREATE Function
Creates an external directory
Category: External Files
Syntax
new-directory=DCREATE(directory-name<,parent-directory>)
Arguments
new-directory
contains the complete pathname of the new directory, or contains an empty string if
the directory cannot be created.
506
DEPDB Function
4
Chapter 4
directory-name
specifies the name of the directory to create. This value cannot include a pathname.
parent-directory
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.
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)
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.
Functions and CALL Routines
4
DEPDBSL Function
507
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)
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
508
DEPSL Function
4
Chapter 4
Details
The DEPDBSL function returns the depreciation by using the declining balance method
with conversion to a straight-line depreciation, which is given by
DEPDBSL (p
; v; y; r
80
>
>
< 1 0 01
) = > (10 )
>
: 0
r
v
y
v
0
(y
r
y
t
t)
r
y
p
p <
0
p
t
p > t
p > y
where
t
=
int
y
0 +1
y
r
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 returned is 87.00. The first and the third arguments are expressed in
years.
DEPSL Function
Returns the straight-line depreciation
Category:
Financial
Syntax
DEPSL(p,v,y)
Functions and CALL Routines
4
DEPSYD Function
509
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
Category: Financial
510
DEPSYD Function
4
Chapter 4
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.
Functions and CALL Routines
4
DEPTAB Function
511
DEPTAB Function
Returns the depreciation from specified tables
Category: Financial
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
512
DEQUOTE Function
4
Chapter 4
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 an individual
quotation mark and deletes everything that is to the right of the closing quotation mark
Category:
Character
Syntax
DEQUOTE(string)
Arguments
string
specifies a character constant, variable, or expression.
Functions and CALL Routines
4
DEQUOTE Function
513
Details
If the DEQUOTE function returns a value to a variable that has not yet been assigned
a length, then by default the variable length is determined by the length of the first
argument.
The value that is returned by the DEQUOTE function depends on the first character
or the first two characters in string:
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, 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. All paired single
quotation marks are reduced to one single quotation mark. The first non-paired
single 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. All paired double
quotation marks are reduced to one double quotation mark. The first non-paired
double 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
514
DEQUOTE Function
4
Chapter 4
Examples
This example demonstrates the use of DEQUOTE within a DATA step.
data test;
input string $60.;
result = dequote(string);
datalines;
No quotes, no change
No "leading" quote, no change
"" returns a string with length zero
"Matching double quotes are removed"
’Matching single quotes are removed’
"Paired ""quotes"" are reduced"
’Paired ’’ quotes’’ are reduced’
"Single ’quotes’ inside ’’ double’’ quotes are unchanged"
’Double "quotes" inside ""single"" quotes are unchanged’
"No matching quote, no problem
Don’t remove this apostrophe
"Text after the matching quote" is "deleted"
;
proc print noobs;
title ’Input Strings and Output Results from DEQUOTE’;
run;
Output 4.23
Removing Matching Quotation Marks with the DEQUOTE Function
Input Strings and Output Results from DEQUOTE
string
No quotes, no change
No "leading" quote, no change
"" returns a string with length zero
"Matching double quotes are removed"
’Matching single quotes are removed’
"Paired ""quotes"" are reduced"
’Paired ’’ quotes’’ are reduced’
"Single ’quotes’ inside ’’ double’’ quotes are unchanged"
’Double "quotes" inside ""single"" quotes are unchanged’
"No matching quote, no problem
Don’t remove this apostrophe
"Text after the matching quote" is "deleted"
result
No quotes, no change
No "leading" quote, no change
Matching double quotes are removed
Matching single quotes are removed
Paired "quotes" are reduced
Paired ’ quotes’ are reduced
Single ’quotes’ inside ’’ double’’ quotes are unchanged
Double "quotes" inside ""single"" quotes are unchanged
No matching quote, no problem
Don’t remove this apostrophe
Text after the matching quote
1
Functions and CALL Routines
4
DEVIANCE Function
515
DEVIANCE Function
Computes the deviance
Category: Mathematical
Syntax
DEVIANCE(distribution, variable, shape-parameter(s)<, " >)
Arguments
distribution
is a character string that identifies the distribution. Valid distributions are
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 random variable.
shape-parameter(s)
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–".
516
4
DEVIANCE Function
Chapter 4
"
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:
(
02 log (1 0 p) x = 0
DEVIANCE BERN ; variable; p; = 02 log (p)
x=1
:
otherwise
00
1
0
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.
: x < 0
DEVIANCE BINO ; x ; ; n = 2 x log x + (n 0 x ) log nn 00x
0x n
x >n
00
0
1
(
:
Functions and CALL Routines
4
DEVIANCE Function
517
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 GAMMA ; x ; = 2 0 log x + x 0 00
0
1
:
x <0
x ; 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
0
0
IGAUSS ; x ; 0
1
=
:
2
(x 0)
2 x
x <0
x
; 518
DEVIANCE Function
4
Chapter 4
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:
00
DEVIANCE NORMAL x
0
;
;
1
= (x 0 )2
The Poisson Distribution
DEVIANCE(’POISSON’, variable, <, " >)
where
variable
is a numeric random variable.
Range: variable ≥ 0
is a numeric mean parameter.
Range:
≥"
"
is an optional positive numeric value that is used to bound . Any value of
the interval 0 ≤ ≤ " is replaced by ".
in
Functions and CALL Routines
4
DHMS Function
519
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
DEVIANCE POISSON x
0
;
;
1
x
0
= 2 x log x 0 (x 0 ) x 0 :
<
;
DHMS Function
Returns a SAS datetime value from date, hour, minute, and second
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.
520
DIF Function
4
Chapter 4
Examples
The following SAS statements produce these results:
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
01JAN02: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 610
DIF Function
Returns differences between the argument and its nth lag
Category:
Special
Syntax
DIF< n>(argument)
Functions and CALL Routines
4
DIF Function
Arguments
n
specifies the number of lags.
argument
is numeric.
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
D
.
1
4
- 2
3
521
522
DIGAMMA Function
4
Chapter 4
See Also
Function:
“LAG Function” on page 655
DIGAMMA Function
Returns the value of the Digamma function
Category:
Mathematical
Syntax
DIGAMMA(argument)
Arguments
argument
is numeric.
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.
Example
SAS Statements
Results
x=digamma(1.0);
-0.577215665
Functions and CALL Routines
4
DIM Function
523
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.
bound-n
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
524
DINFO Function
4
Chapter 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 608
“LBOUND Function” on page 659
Statements:
“ARRAY Statement” on page 1187
“Array Reference Statement” on page 1191
“Array Processing” in SAS Language Reference: Concepts
DINFO Function
Returns information about a directory
External Files
See: DINFO Function in the documentation for your operating environment.
Category:
Functions and CALL Routines
4
DINFO Function
525
Syntax
DINFO(directory-id,info-item)
Arguments
directory-id
specifies the identifier that was assigned when the directory was opened, generally
by the DOPEN function.
info-item
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. This is a character value.
Details
Use DOPTNAME to determine the names of the available system-dependent directory
information items. Use DOPTNUM to determine the number of directory information
items 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));
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;
526
DNUM Function
4
Chapter 4
See Also
Functions:
“DOPEN Function” on page 527
“DOPTNAME Function” on page 528
“DOPTNUM Function” on page 530
“FINFO Function” on page 565
“FOPTNAME Function” on page 580
“FOPTNUM Function” on page 582
DNUM Function
Returns the number of members in a directory
Category:
External Files
Syntax
DNUM(directory-id)
Argument
directory-id
specifies the identifier that was assigned when the directory was opened, generally
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));
Functions and CALL Routines
4
DOPEN Function
527
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 527
“DREAD Function” on page 531
DOPEN Function
Opens a directory and returns a directory identifier value
Category: External Files
See:
DOPEN Function in the documentation for your operating environment.
Syntax
DOPEN(fileref)
Argument
fileref
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. 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.
Operating Environment Information: The term directory 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, MACLIB,
or partitioned data set. For details, see the SAS documentation for your operating
environment. 4
528
DOPTNAME Function
4
Chapter 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
This example opens a directory for
processing within a DATA step.
data _null_;
drop rc did;
rc=filename("mydir","physical-name");
did=dopen("mydir");
if did > 0 then do;
...more statements...
end;
run;
See Also
Functions:
“DCLOSE Function” on page 504
“DOPTNUM Function” on page 530
“FOPEN Function” on page 578
“MOPEN Function” on page 696
DOPTNAME Function
Returns directory attribute information
External Files
See: DOPTNAME Function in the documentation for your operating environment.
Category:
Syntax
DOPTNAME(directory-id,nval)
Functions and CALL Routines
4
DOPTNAME Function
529
Arguments
directory-id
specifies the identifier that was assigned when the directory was opened, generally
by the DOPEN function.
Restriction: The directory must have been previously opened by using DOPEN.
nval
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
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;
530
4
DOPTNUM Function
Chapter 4
See Also
Functions:
“DINFO Function” on page 524
“DOPEN Function” on page 527
“DOPTNUM Function” on page 530
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)
Argument
directory-id
specifies the identifier that was assigned when the directory was opened, generally
by the DOPEN function.
Restriction: The directory must have been previously opened by using DOPEN.
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));
Functions and CALL Routines
4
DREAD Function
Example 2: Using DOPTNUM within a DATA Step
531
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 524
“DOPEN Function” on page 527
“DOPTNAME Function” on page 528
DREAD Function
Returns the name of a directory member
Category: External Files
Syntax
DREAD(directory-id,nval)
Arguments
directory-id
specifies the identifier that was assigned when the directory was opened, generally
by the DOPEN function.
Restriction: The directory must have been previously opened by using DOPEN.
nval
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.
532
DROPNOTE Function
4
Chapter 4
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 526
“DOPEN Function” on page 527
DROPNOTE Function
Deletes a note marker from a SAS data set or an external file
Category:
SAS File I/O
Category:
External Files
Syntax
DROPNOTE(data-set-id|file-id,note-id)
Arguments
data-set-id|file-id
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
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.
Functions and CALL Routines
4
DSNAME Function
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 548
“FNOTE Function” on page 576
“FOPEN Function” on page 578
“FPOINT Function” on page 583
“NOTE Function” on page 712
“OPEN Function” on page 732
“POINT Function” on page 761
DSNAME Function
Returns the SAS data set name that is associated with a data set identifier
Category: SAS File I/O
Syntax
DSNAME(data-set-id)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
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.
533
534
DUR Function
4
Chapter 4
%let dsid=%sysfunc(open(sasuser.houses,i));
%put The current open data set
is %sysfunc(dsname(&dsid)).;
See Also
Function:
“OPEN Function” on page 732
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
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
PK k k=1
C=
c(k)
k
(1+fy ) f
P
(1 + y )
K
X
c (k )
where
P
=
k
f
k=1 (1 + f y )
Functions and CALL Routines
4
DURP Function
535
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 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
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
536
ERF Function
4
Chapter 4
Details
The DURP function returns the value
PK tk
c(k) t
y k
1 k =1 (1+ n )
1
0
1 + ny
D=n P
where
tk = nk0 + k 0 1
k = 1; . . . ;K 0 1
c (k) = nc0A for
1
c
c (K ) = 1 + n A
and where
P=
K
X
ck
( )
0
y 1tk
1
+
k=1
n
Examples
data _null_;
d=durp(1000,1/100,4,14,.33/2,.10);
put d;
run;
The value returned is 3.26496.
ERF Function
Returns the value of the (normal) error function
Category:
Mathematical
Syntax
ERF(argument)
Arguments
argument
is numeric.
Functions and CALL Routines
4
ERFC Function
537
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)
Arguments
argument
is numeric.
Details
The ERFC function returns the complement to the ERF function (that is, 1 −
ERF(argument)).
538
EUROCURR Function
4
Chapter 4
Examples
SAS Statements
Results
x=erfc(1.0);
0.1572992071
x=erfc(-1.0);
.8427007929
EUROCURR Function
Converts one European currency to another
Currency Conversion
See: The EUROCURR function in SAS National Language Support (NLS): User’s Guide
Category:
EXIST Function
Verifies the existence of a SAS data library member
Category:
SAS File I/O
Syntax
EXIST(member-name<,member-type<, generation>>)
Arguments
member-name
specifies the SAS data 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
specifies the type of SAS data library member. A few common member types are
ACCESS, CATALOG, DATA, and VIEW. If you do not specify a member-type, then the
member type DATA is assumed.
generation
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.
Functions and CALL Routines
4
EXIST Function
539
Details
EXIST returns 1 if the library member exists, or 0 if member-name does not exist or
member-type is invalid. Use CEXIST 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 data 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;
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);
540
EXIST Function
4
Chapter 4
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
test=0
test=0
See Also
Functions:
“CEXIST Function” on page 450
“FEXIST Function” on page 551
“FILEEXIST Function” on page 554
Functions and CALL Routines
4
FACT Function
541
EXP Function
Returns the value of the exponential function
Category: Mathematical
Syntax
EXP(argument)
Arguments
argument
is numeric.
Details
The EXP function raises the constant e, which is approximately given by 2.71828, to the
power that is supplied by the argument. The result is limited by the maximum value of
a floating-point decimal value on the computer.
Examples
SAS Statements
Results
x=exp(1.0);
2.7182818285
x=exp(0);
1
FACT Function
Computes a factorial
Category: Mathematical
Syntax
FACT(n)
542
FAPPEND Function
4
Chapter 4
Arguments
n
is an integer that represents the number of elements for which the factorial is
computed.
Details
The mathematical representation of the FACT function is given by the following
equation:
FACT (n) = n !
with n ≥ 0.
If the expression cannot be computed, a missing value is returned.
Examples
SAS Statements
Results
x=fact(5);
120
See Also
Functions:
“COMB Function” on page 462
“PERM Function” on page 760
FAPPEND Function
Appends the current record to the end of an external file
Category:
External Files
Syntax
FAPPEND(file-id< ,cc>)
Functions and CALL Routines
4
FAPPEND Function
543
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
cc
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 terminal 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;
544
FCLOSE Function
4
Chapter 4
See Also
Functions:
“DOPEN Function” on page 527
“FCLOSE Function” on page 544
“FGET Function” on page 552
“FOPEN Function” on page 578
“FPUT Function” on page 586
“FWRITE Function” on page 593
“MOPEN Function” on page 696
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
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: On some operating environments you must close
the file with the FCLOSE function at the end of the DATA step. For details, 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
545
%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 504
“DOPEN Function” on page 527
“FOPEN Function” on page 578
“FREAD Function” on page 587
“MOPEN Function” on page 696
FCOL Function
Returns the current column position in the File Data Buffer (FDB)
Category: External Files
Syntax
FCOL(file-id)
Argument
file-id
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).
546
FCOL Function
4
Chapter 4
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file. If the file is successfully opened, indicated by a positive value in the variable FID,
it puts more data into the FDB relative to position POS, writes the record, and closes
the file:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf,o));
%if (&fid > 0) %then
%do;
%let record=This is data for the record.;
%let rc=%sysfunc(fput(&fid,&record));
%let pos=%sysfunc(fcol(&fid));
%let rc=%sysfunc(fpos(&fid,%eval(&pos+1)));
%let rc=%sysfunc(fput(&fid,more data));
%let rc=%sysfunc(fwrite(&fid));
%let rc=%sysfunc(fclose(&fid));
%end;
%let rc=%sysfunc(filename(filrf));
The new record written to the external file is
This is data for the record. more data
See Also
Functions:
“FCLOSE Function” on page 544
“FOPEN Function” on page 578
“FPOS Function” on page 584
“FPUT Function” on page 586
“FWRITE Function” on page 593
“MOPEN Function” on page 696
Functions and CALL Routines
4
FDELETE Function
547
FDELETE Function
Deletes an external file or an empty directory
Category: External Files
See:
FDELETE Function in the documentation for your operating environment.
Syntax
FDELETE(fileref | directory)
Argument
fileref
specifies the fileref that you assigned to the external file. You can assign filerefs by
using the FILENAME statement or the FILENAME external file access function.
Restriction: The fileref that you use with FDELETE cannot be a concatenation.
Operating Environment Information: In some operating environments, you can
specify a fileref that was assigned with an environment variable. You can also assign
filerefs using system commands. For details, see the SAS documentation for your
operating environment. 4
directory
specifies an empty directory that you want to delete.
Restriction: You must have authorization to delete the directory.
Details
FDELETE returns 0 if the operation was successful or ≠0 if it was not successful.
Examples
Example 1: Deleting an External File
This example generates a fileref for an external
file in the variable FNAME. Then it calls FDELETE to delete the file and calls the
FILENAME function again to deassign the fileref.
data _null_;
fname="tempfile";
rc=filename(fname,"physical-filename");
if rc = 0 and fexist(fname) then
rc=fdelete(fname);
rc=filename(fname);
run;
548
FETCH Function
4
Chapter 4
Example 2: Deleting a Directory
This example uses FDELETE to delete an empty
directory to which you have write access. If the directory is not empty, the optional
SYSMSG function returns an error message stating that SAS is unable to delete the file.
filename testdir ’physical-filename’;
data _null_;
rc=fdelete(’testdir’);
put rc=;
msg=sysmsg();
put msg=;
run;
See Also
Functions:
“FEXIST Function” on page 551
“FILENAME Function” on page 555
Statement:
“FILENAME Statement” on page 1257
FETCH Function
Reads the next nondeleted observation from a SAS data set into the Data Set Data Vector (DDV)
Category:
SAS File I/O
Syntax
FETCH(data-set-id <,’NOSET’>)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
’NOSET’
prevents the automatic passing of SAS data set variable values to macro or DATA
step variables even if the SET routine has been called.
Details
FETCH returns a 0 if the operation was successful, ≠0 if it was not successful, and − 1
if the end of the data set is reached. FETCH skips observations marked for deletion.
If the SET routine has been called previously, the values for any data set variables
are automatically passed from the DDV to the corresponding DATA step or macro
variables. To override this behavior temporarily so that fetched values are not
automatically copied to the DATA step or macro variables, use the NOSET option.
Functions and CALL Routines
4
FETCHOBS Function
549
Examples
This example fetches the next observation from the SAS data set MYDATA. If the
end of the data set is reached or if an error occurs, SYSMSG retrieves the appropriate
message and writes it to the SAS log. Note that in a macro statement you do not
enclose character strings in quotation marks.
%let dsid=%sysfunc(open(mydata,i));
%let rc=%sysfunc(fetch(&dsid));
%if &rc ne 0 %then
%put %sysfunc(sysmsg());
%else
%do;
...more macro statements...
%end;
%let rc=%sysfunc(close(&dsid));
See Also
CALL Routine:
“CALL SET Routine” on page 410
Functions:
“FETCHOBS Function” on page 549
“GETVARC Function” on page 602
“GETVARN Function” on page 603
FETCHOBS Function
Reads a specified observation from a SAS data set into the Data Set Data Vector (DDV)
Category: SAS File I/O
Syntax
FETCHOBS(data-set-id,obs-number< ,options>)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
550
FETCHOBS Function
4
Chapter 4
obs-number
specifies the number of the observation to read. FETCHOBS treats the observation
value as a relative observation number unless you specify the ABS option. The
relative observation number may or may not coincide with the physical observation
number on disk, because the function skips observations marked for deletion. When
a WHERE clause is active, the function counts only observations that meet the
WHERE condition.
Default: FETCHOBS skips deleted observations.
options
names one or more options, separated by blanks and enclosed in quotation marks:
’ABS’
specifies that the value of obs-number is absolute; that is, deleted
observations are counted.
’NOSET’
prevents the automatic passing of SAS data set variable values to
DATA step or macro variables even if the SET routine has been
called.
Details
FETCHOBS returns 0 if the operation was successful, ≠0 if it was not successful, and
−1 if the end of the data set is reached. To retrieve the error message that is associated
with a non-zero return code, use the SYSMSG function. If the SET routine has been
called previously, the values for any data set variables are automatically passed from
the DDV to the corresponding DATA step or macro variables. To override this behavior
temporarily, use the NOSET option.
If obs-number is less than 1, the function returns an error condition. If obs-number is
greater than the number of observations in the SAS data set, the function returns an
end-of-file condition.
Examples
This example fetches the tenth observation from the SAS data set MYDATA. If an
error occurs, the SYSMSG function retrieves the error message and writes it to the SAS
log. Note that in a macro statement you do not enclose character strings in quotation
marks.
%let rc
%if &rc
%put
%if &rc
= %sysfunc(fetchobs(&mydataid,10));
= −1 %then
End of data set has been reached.;
> 0 %then %put %sysfunc(sysmsg());
See Also
CALL Routine:
“CALL SET Routine” on page 410
Functions:
“FETCH Function” on page 548
“GETVARC Function” on page 602
“GETVARN Function” on page 603
Functions and CALL Routines
4
FEXIST Function
551
FEXIST Function
Verifies the existence of an external file associated with a fileref
Category: External Files
See:
FEXIST Function in the documentation for your operating environment.
Syntax
FEXIST(fileref)
Argument
fileref
specifies the fileref assigned to an external file.
Restriction: The fileref must have been previously assigned.
Operating Environment Information: In some operating environments, you can specify
a fileref that was assigned with an environment variable. For details, see the SAS
documentation for your operating environment. 4
Details
FEXIST returns 1 if the external file that is associated with fileref exists, and 0 if the
file does not exist. You can assign filerefs by using the FILENAME statement or the
FILENAME external file access function. In some operating environments, you can also
assign filerefs by using system commands.
Comparison
FILEEXIST verifies the existence of a file based on its physical name.
Examples
This example verifies the existence of an external file and writes the result to the
SAS log:
%if %sysfunc(fexist(&fref)) %then
%put The file identified by the fileref
&fref exists.;
%else
%put %sysfunc(sysmsg());
552
FGET Function
4
Chapter 4
See Also
Functions:
“EXIST Function” on page 538
“FILEEXIST Function” on page 554
“FILENAME Function” on page 555
“FILEREF Function” on page 557
Statement:
“FILENAME Statement” on page 1257
FGET Function
Copies data from the File Data Buffer (FDB) into a variable
Category:
External Files
Syntax
FGET(file-id,variable< ,length>)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
variable
in a DATA step, specifies a character variable to hold the data. In a macro, specifies
a macro variable to hold the data. If variable is a macro variable and it does not
exist, it is created.
length
specifies the number of characters to retrieve from the FDB. If length is specified,
only the specified number of characters is retrieved (or the number of characters
remaining in the buffer if that number is less than length). If length is omitted, all
characters in the FDB from the current column position to the next delimiter are
returned. The default delimiter is a blank. The delimiter is not retrieved.
See:
The “FSEP Function” on page 591 for more information about delimiters.
Details
FGET returns 0 if the operation was successful, or −1 if the end of the FDB was
reached or no more tokens were available.
After FGET is executed, the column pointer moves to the next read position in the
FDB.
Functions and CALL Routines
4
FGET Function
553
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file. If the file is opened successfully, it reads the first record into the File Data Buffer,
retrieves the first token of the record and stores i t in the variable MYSTRING, 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));
%if &fid > 0 %then
%do;
%let rc=%sysfunc(fread(&fid));
%let rc=%sysfunc(fget(&fid,mystring));
%put &mystring;
%let rc=%sysfunc(fclose(&fid));
%end;
%let rc=%sysfunc(filename(filrf));
See Also
Functions:
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FOPEN Function” on page 578
“FPOS Function” on page 584
“FREAD Function” on page 587
“FSEP Function” on page 591
“MOPEN Function” on page 696
554
FILEEXIST Function
4
Chapter 4
FILEEXIST Function
Verifies the existence of an external file by its physical name
External Files
Category:
See:
FILEEXIST Function in the documentation for your operating environment.
Syntax
FILEEXIST(file-name)
Argument
file-name
specifies a fully qualified physical filename of the external file in the operating
environment. In a DATA step, file-name can be a character expression, a string in
quotation marks, or a DATA step variable. In a macro, file-name can be any
expression.
Details
FILEEXIST returns 1 if the external file exists and 0 if the external file does not exist.
The specification of the physical name for file-name varies according to the operating
environment.
Although your operating environment utilities may recognize partial physical
filenames, you must always use fully qualified physical filenames with FILEEXIST.
Examples
This example verifies the existence of an external file. If the file exists, FILEEXIST
opens the file. If the file does not exist, FILEEXIST displays a message in the SAS log.
Note that in a macro statement you do not enclose character strings in quotation marks.
%if %sysfunc(fileexist(&myfilerf)) %then
%let fid=%sysfunc(fopen(&myfilerf));
%else
%put The external file &myfilerf does not exist.;
See Also
Functions:
“EXIST Function” on page 538
“FEXIST Function” on page 551
“FILENAME Function” on page 555
“FILEREF Function” on page 557
“FOPEN Function” on page 578
Functions and CALL Routines
4
FILENAME Function
555
FILENAME Function
Assigns or deassigns a fileref to an external file, directory, or output device
Category: External Files
See:
FILENAME Function in the documentation for your operating environment.
Syntax
FILENAME(fileref, file-name < ,device-type <,host-options <,dir-ref>>>)
Arguments
fileref
in a DATA step, specifies the fileref to assign to the external file. In a macro (for
example, in the %SYSFUNC function), fileref is the name of a macro variable
(without an ampersand) whose value contains the fileref to assign to the external file.
Tip: A blank fileref (’’) causes an error. If the fileref is a DATA step character
variable with a blank value and a minimum length of eight characters, or if a
macro variable named in fileref has a null value, then a fileref is generated for you.
file-name
specifies the external file. Specifying a blank file-name deassigns one that was
assigned previously.
device-type
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:
DISK
specifies that the device is a disk drive.
Tip: When you assign a fileref to a file on disk, you are not
required to specify DISK.
Alias: BASE
DUMMY
specifies that the output to the file is discarded.
Tip: Specifying DUMMY can be useful for testing.
GTERM
indicates that the output device type is a graphics device that will
be receiving graphics data.
PIPE
specifies an unnamed pipe.
Note:
Some operating environments do not support pipes.
4
PLOTTER
specifies an unbuffered graphics output device.
PRINTER
specifies a printer or printer spool file.
TAPE
specifies a tape drive.
TEMP
creates a temporary file that exists only as long as the filename is
assigned. The temporary file can be accessed only through the
logical name and is available only while the logical name exists.
Restriction: Do not specify a physical pathname. If you do, SAS
returns an error.
556
FILENAME Function
4
Chapter 4
Tip: Files that are manipulated by the TEMP device can have the
same attributes and behave identically to DISK files.
TERMINAL
specifies the user’s terminal.
UPRINTER
specifies a Universal Printing printer definition name.
Operating Environment Information: The FILENAME function also supports
operating environment-specific devices. For details, see the SAS documentation for
your operating environment. 4
host-options
specifies host-specific details such as file attributes and processing attributes. For
details, see the SAS documentation for your operating environment.
dir-ref
specifies the fileref that was assigned to the directory or partitioned data set in which
the external file resides.
Details
FILENAME returns 0 if the operation was successful; ≠0 if it was not successful. The
name that is associated with the file or device is called a fileref (file reference name).
Other system functions that manipulate external files and directories require that the
files be identified by fileref rather than by physical filename.
Operating Environment Information: The term directory in this description refers to
an aggregate grouping of files that are managed by the operating environment.
Different operating environments identify these groupings with different names, such
as directory, subdirectory, MACLIB, or partitioned data set. For details, see the SAS
documentation for your operating environment.
Under some operating environments, you can also assign filerefs by using system
commands. Depending on the operating environment, FILENAME might be unable to
change or deassign filerefs that are assigned outside SAS. 4
The association between a fileref and a physical file lasts only for the duration of the
current SAS session or until you change or discontinue the association by using
FILENAME. You can deassign filerefs by specifying a null string for the file-name
argument in FILENAME.
Examples
Example 1: Assigning a Fileref to an External File
This example assigns the fileref
MYFILE to an external file, then deassigns the fileref. 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));
%if &rc ne 0 %then
%put %sysfunc(sysmsg());
%let rc=%sysfunc(filename(filrf));
Functions and CALL Routines
4
FILEREF Function
557
Example 2: Assigning a System-Generated Fileref
This example assigns a
system-generated fileref to an external file. The fileref is stored in the variable FNAME.
Note that in a macro statement you do not enclose character strings in quotation marks.
%let rc=%sysfunc(filename(fname, physical-filename));
%if &rc %then
%put %sysfunc(sysmsg());
%else
%do;
more macro statements
%end;
Example 3: Assigning a Fileref to a Pipe File
This example assigns the fileref
MYPIPE to a pipe file with the output from the UNIX command LS, which lists the files
in the directory /u/myid. Note that in a macro statement you do not enclose character
strings in quotation marks.
%let filrf=mypipe;
%let rc=%sysfunc(filename(filrf, %str(ls /u/myid), pipe));
See Also
Functions:
“FEXIST Function” on page 551
“FILEEXIST Function” on page 554
“FILEREF Function” on page 557
“SYSMSG Function” on page 914
FILEREF Function
Verifies that a fileref has been assigned for the current SAS session
Category: External Files
See:
FILEREF Function in the documentation for your operating environment.
Syntax
FILEREF(fileref)
Argument
fileref
specifies the fileref to be validated.
Range: 1 to 8 characters
558
FIND Function
4
Chapter 4
Details
A negative return code indicates that the fileref exists but the physical file associated
with the fileref does not exist. A positive value indicates that the fileref is not assigned.
A value of zero indicates that the fileref and external file both exist.
A fileref can be assigned to an external file by using the FILENAME statement or
the FILENAME function.
Operating Environment Information: Under some operating environments, filerefs can
also be assigned by using system commands. For details, see the SAS documentation
for your operating environment. 4
Examples
Example 1: Verifying that a Fileref is Assigned
This example tests whether the fileref
MYFILE is currently assigned to an external file. A system error message is issued if
the fileref is not currently assigned:
%if %sysfunc(fileref(myfile))>0 %then
%put MYFILE is not assigned;
Example 2: Verifying that Both a Fileref and a File Exist
This example tests for a zero
value to determine if both the fileref and the file exist:
%if %sysfunc(fileref(myfile)) ne 0 %then
%put %sysfunc(sysmsg());
See Also
Functions:
“FEXIST Function” on page 551
“FILEEXIST Function” on page 554
“FILENAME Function” on page 555
“SYSMSG Function” on page 914
Statement:
“FILENAME Statement” on page 1257
FIND Function
Searches for a specific substring of characters within a character string that you specify
Category:
Character
Syntax
FIND(string,substring< ,modifiers>< ,startpos>)
FIND(string,substring< ,startpos><,modifiers>)
Functions and CALL Routines
4
FIND Function
559
Arguments
string
specifies a character constant, variable, or expression that will be searched for
substrings.
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 search for 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 search. If this modifier is not
specified, FIND only searches for character substrings with the
same case as the characters in substring.
t
trims trailing blanks from string and substring.
Tip: 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 that evaluates to one or more constants.
startpos
is an integer that specifies the position at which the search should start and the
direction of the search.
Details
The FIND function searches string for the first occurrence of the specified substring,
and returns the position of that substring. If the substring is not found in string, FIND
returns a value of 0.
If startpos is not specified, FIND starts the search at the beginning of the string and
searches the string from left to right. If startpos is specified, the absolute value of
startpos determines the position at which to start the search. The sign of startpos
determines the direction of the search.
When startpos is …
then FIND …
greater than 0
starts the search at position startpos and the direction of the
search is to the right. If startpos is greater than the length of
string, FIND returns a value of 0.
less than 0
starts the search at position –startpos and the direction of the
search is to the left. If –startpos is greater than the length of
string, the search starts at the end of string.
equal to 0
returns a value of 0.
Comparisons
3 The FIND function searches for substrings of characters in a character string,
whereas the FINDC function searches for individual characters in a character
string.
560
FINDC Function
4
Chapter 4
3 The FIND function and the INDEX function both search for substrings of
characters in a character string; however, the INDEX function does not have the
modifiers nor the startpos arguments.
Examples
SAS Statements
Results
whereisshe=find(’She sells seashells? Yes, she does.’,’she ’);
put whereisshe;
27
variable1=’She sells seashells? Yes, she does.’;
variable2=’she ’;
variable3=’i’;
whereisshe_i=find(variable1,variable2,variable3);
put whereisshe_i;
1
expression1=’She sells seashells? ’||’Yes, she does.’;
expression2=kscan(’he or she’,3)||’ ’;
expression3=trim(’t
’);
whereisshe_t=find(expression1,expression2,expression3);
put whereisshe_t;
14
xyz=’She sells seashells? Yes, she does.’;
startposvar=22
whereisshe_22=find(xyz,’she’,startposvar);
put whereisshe_22;
27
xyz=’She sells seashells? Yes, she does.’;
startposexp=1-23;
whereisShe_ineg22=find(xyz,’She’,’i’,startposexp);
put whereisShe_ineg22;
14
See Also
Functions:
“COUNT Function” on page 488
“FINDC Function” on page 560
“INDEX Function” on page 620
“RXMATCH Function” on page 858
FINDC Function
Searches for specific characters that either appear or do not appear within a character string that
you specify
Category:
Character
Syntax
FINDC(string,characters< ,modifiers><,startpos>)
Functions and CALL Routines
4
FINDC Function
561
FINDC(string,characters<,startpos>< ,modifiers>)
Arguments
string
specifies a character constant, variable, or expression that will be searched for
characters.
Tip: Enclose a literal string of characters in quotation marks.
characters
is a character constant, variable, or expression that specifies one or more characters
to search for 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 search. If this modifier is not
specified, FINDC only searches for character substrings with the
same case as the characters in characters.
o
processes characters and modifiers only once, at the first call to
this instance of FINDC. Consequently, if you change the value of
characters or modifiers in subsequent calls, the change is ignored
by FINDC.
t
trims trailing blanks from string and characters.
v
counts only the characters that do not appear in characters.
Tip: 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 that evaluates to one or more constants.
startpos
is an integer that specifies the position at which the search should start and the
direction of the search.
Details
The FINDC function searches string for the first occurrence of the specified characters,
and returns the position of the first character found. If the characters are not found in
string, FINDC returns a value of 0.
If startpos is not specified, FINDC starts the search at the beginning of the string
and searches the string from left to right. If startpos is specified, the absolute value of
startpos determines the position at which to start the search. The sign of startpos
determines the direction of the search.
562
FINDC Function
4
Chapter 4
When startpos is …
then FINDC …
greater than 0
starts the search at position startpos and the direction of the
search is to the right. If startpos is greater than the length of
string, FINDC returns a value of 0.
less than 0
starts the search at position –startpos and the direction of the
search is to the left. If –startpos is greater than the length of
string, the search starts at the end of string.
equal to 0
returns a value of 0.
Comparisons
3 The FINDC function searches for individual characters in a character string,
whereas the FIND function searches for substrings of characters in a character
string.
3 The FINDC function and the INDEXC function both search for individual
characters in a character string; however, the INDEXC function does not have the
modifiers nor the startpos arguments.
3 The FINDC function searches for individual characters in a character string,
whereas the VERIFY function searches for the first character that is unique to an
expression. The VERIFY function does not have the modifiers nor the startpos
arguments.
Examples
Example 1: Searching for the Characters h, i, and Blank
This example searches for
the three characters h, i, and blank. The characters h and i are in lowercase. The
uppercase characters H and I are ignored in this search.
data _null_;
whereishi=0;
do until(whereishi=0);
whereishi=findc(’Hi there, Ian!’,’hi ’,whereishi+1);
if whereishi=0 then put ‘‘The End’’;
else do;
whatfound=substr(’Hi there, Ian!’,whereishi,1);
put whereishi= whatfound=;
end;
end;
run;
Functions and CALL Routines
4
FINDC Function
The following lines are written to the SAS log:
whereishi=2 whatfound=i
whereishi=3 whatfound=
whereishi=5 whatfound=h
whereishi=10 whatfound=
The End
Example 2: Searching for the Characters h and i While Ignoring Case
This example
searches for the four characters h, i, H, and I. FINDC with the i modifier ignores
character case during the search.
data _null_;
whereishi_i=0;
do until(whereishi_i=0);
variable1=’Hi there, Ian!’;
variable2=’hi’;
variable3=’i’;
whereishi_i=findc(variable1,variable2,variable3,whereishi_i+1);
if whereishi_i=0 then put ‘‘The End’’;
else do;
whatfound=substr(variable1,whereishi_i,1);
put whereishi_i= whatfound=;
end;
end;
run;
The following lines are written to the SAS log:
whereishi_i=1 whatfound=H
whereishi_i=2 whatfound=i
whereishi_i=5 whatfound=h
whereishi_i=11 whatfound=I
The End
Example 3: Searching for the Characters h and i with Trailing Blanks Trimmed
This
example searches for the two characters h and i. FINDC with the t modifier trims
trailing blanks from the string argument and the characters argument.
data _null_;
whereishi_t=0;
do until(whereishi_t=0);
expression1=’Hi there, ’||’Ian!’;
expression2=kscan(’bye or hi’,3)||’ ’;
expression3=trim(’t
’);
whereishi_t=findc(expression1,expression2,expression3,whereishi_t+1);
if whereishi_t=0 then put ‘‘The End’’;
else do;
whatfound=substr(expression1,whereishi_t,1);
put whereishi_t= whatfound=;
end;
end;
run;
563
564
FINDC Function
4
Chapter 4
The following lines are written to the SAS log:
whereishi_t=2 whatfound=i
whereishi_t=5 whatfound=h
The End
Example 4: Searching for all Characters, Excluding h, i, H, and I
This example
searches for all of the characters in the string, excluding the characters h, i, H, and I.
FINDC with the v modifier counts only the characters that do not appear in the
characters argument. This example also includes the i modifier and therefore ignores
character case during the search.
data _null_;
whereishi_iv=0;
do until(whereishi_iv=0);
xyz=’Hi there, Ian!’;
whereishi_iv=findc(xyz,’hi’,whereishi_iv+1,’iv’);
if whereishi_iv=0 then put ‘‘The End’’;
else do;
whatfound=substr(xyz,whereishi_iv,1);
put whereishi_iv= whatfound=;
end;
end;
run;
The following lines are written to the SAS log:
whereishi_iv=3 whatfound=
whereishi_iv=4 whatfound=t
whereishi_iv=6 whatfound=e
whereishi_iv=7 whatfound=r
whereishi_iv=8 whatfound=e
whereishi_iv=9 whatfound=,
whereishi_iv=10 whatfound=
whereishi_iv=12 whatfound=a
whereishi_iv=13 whatfound=n
whereishi_iv=14 whatfound=!
The End
See Also
Functions:
“COUNTC Function” on page 490
“FIND Function” on page 558
“INDEXC Function” on page 621
“VERIFY Function” on page 955
Functions and CALL Routines
4
FINFO Function
565
FINFO Function
Returns the value of a file information item
Category: External Files
See:
FINFO Function in the documentation for your operating environment.
Syntax
FINFO(file-id,info-item)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
info-item
specifies the name of the file information item to be retrieved. This is a character
value.
Details
FINFO returns the value of a system-dependent information item for an external file.
FINFO returns a blank if the value given for info-item is invalid.
Operating Environment Information: The information available on files depends on the
operating environment. 4
Comparisons
3 FOPTNAME determines the names of the available file information items.
3 FOPTNUM determines the number of system-dependent information items
available.
Examples
This example stores information items about an external file in a SAS data set:
data info;
length infoname infoval $60;
drop rc fid infonum i close;
rc=filename(’abc’,’physical-filename’);
fid=fopen(’abc’);
infonum=foptnum(fid);
do i=1 to infonum;
infoname=foptname(fid,i);
infoval=finfo(fid,infoname);
output;
end;
close=fclose(fid);
566
FINV Function
4
Chapter 4
run;
See Also
Functions:
“FCLOSE Function” on page 544
“FOPTNUM Function” on page 582
“MOPEN Function” on page 696
FINV Function
Returns a quantile from the F distribution
Quantile
Category:
Syntax
FINV (p, ndf, ddf <,nc>)
Arguments
p
is a numeric probability.
Range: 0 ≤ p < 1
ndf
is a numeric numerator degrees of freedom parameter.
Range: ndf > 0
ddf
is a numeric denominator degrees of freedom parameter.
Range: ddf > 0
nc
is an optional numeric noncentrality parameter.
Range: nc ≥ 0
Details
th
The FINV function returns the p quantile from the F distribution with numerator
degrees of freedom ndf, denominator degrees of freedom ddf, and noncentrality
parameter nc. The probability that an observation from the F distribution is less than
the quantile is p. This function accepts noninteger degrees of freedom parameters ndf
and ddf.
If the optional parameter nc is not specified or has the value 0, the quantile from the
central F distribution is returned. The noncentrality parameter nc is defined such that
if X and Y are normal random variables with means and 0, respectively, and variance
2
1, then 2 = Y 2 has a noncentral F distribution with nc = .
X
Functions and CALL Routines
4
FIPNAME Function
567
CAUTION:
For large values of nc,the algorithm could fail; in that case, a missing value is
returned. 4
Note:
FINV is the inverse of the PROBF function.
4
Examples
th
These statements compute the 95 quantile value of a central F distribution with 2
and 10 degrees of freedom and a noncentral F distribution with 2 and 10.3 degrees of
freedom and a noncentrality parameter equal to 2:
SAS Statements
Results
q1=finv(.95,2,10);
4.1028210151
q2=finv(.95,2,10.3,2);
7.583766024
FIPNAME Function
Converts two-digit FIPS codes to uppercase state names
Category: State and ZIP Code
Syntax
FIPNAME(expression)
Arguments
expression
specifies a numeric expression that represents a U.S. FIPS code.
Details
If the FIPNAME function returns a value to a variable that has not yet been assigned a
length, by default the variable is assigned a length of 20.
The FIPNAME function converts a U.S. Federal Information Processing Standards
(FIPS) code to the corresponding state or U.S. territory name in uppercase, returning a
value of up to 20 characters.
Comparisons
The FIPNAME, FIPNAMEL, and FIPSTATE functions take the same argument but
return different values. FIPNAME returns uppercase state names. FIPNAMEL returns
mixed case state names. FIPSTATE returns a two-character state postal code (or
world-wide GSA geographic code for U.S. territories) in uppercase.
568
FIPNAMEL Function
4
Chapter 4
Examples
The examples show the differences when using FIPNAME, FIPNAMEL, and
FIPSTATE.
SAS Statements
Results
x=fipname(37);
put x;
NORTH CAROLINA
x=fipnamel(37);
put x;
North Carolina
x=fipstate(37);
put x;
NC
See Also
Functions:
“FIPNAMEL Function” on page 568
“FIPSTATE Function” on page 569
“STFIPS Function” on page 894
“STNAME Function” on page 895
“STNAMEL Function” on page 896
FIPNAMEL Function
Converts two-digit FIPS codes to mixed case state names
Category:
State and ZIP Code
Syntax
FIPNAMEL(expression)
Arguments
expression
specifies a numeric expression that represents a U.S. FIPS code.
Details
If the FIPNAMEL function returns a value to a variable that has not yet been assigned
a length, by default the variable is assigned a length of 20.
The FIPNAMEL function converts a U.S. Federal Information Processing Standards
(FIPS) code to the corresponding state or U.S. territory name in mixed case, returning a
value of up to 20 characters.
Functions and CALL Routines
4
FIPSTATE Function
569
Comparisons
The FIPNAME, FIPNAMEL, and FIPSTATE functions take the same argument but
return different values. FIPNAME returns uppercase state names. FIPNAMEL returns
mixed case state names. FIPSTATE returns a two-character state postal code (or
world-wide GSA geographic code for U.S. territories) in uppercase.
Examples
The examples show the differences when using FIPNAME, FIPNAMEL, and
FIPSTATE.
SAS Statements
Results
x=fipname(37);
put x;
NORTH CAROLINA
x=fipnamel(37);
put x;
North Carolina
x=fipstate(37);
put x;
NC
See Also
Functions:
“FIPNAME Function” on page 567
“FIPSTATE Function” on page 569
“STFIPS Function” on page 894
“STNAME Function” on page 895
“STNAMEL Function” on page 896
FIPSTATE Function
Converts two-digit FIPS codes to two-character state postal codes
Category: State and ZIP Code
Syntax
FIPSTATE(expression)
570
FIPSTATE Function
4
Chapter 4
Arguments
expression
specifies a numeric expression that represents a U.S. FIPS code.
Details
If the FIPSTATE function returns a value to a variable that has not yet been assigned a
length, by default the variable is assigned a length of 20.
The FIPSTATE function converts a U.S. Federal Information Processing Standards
(FIPS) code to a two-character state postal code (or world-wide GSA geographic code for
U.S. territories) in uppercase.
Comparisons
The FIPNAME, FIPNAMEL, and FIPSTATE functions take the same argument but
return different values. FIPNAME returns uppercase state names. FIPNAMEL returns
mixed case state names. FIPSTATE returns a two-character state postal code (or
world-wide GSA geographic code for U.S. territories) in uppercase.
Examples
The examples show the differences when using FIPNAME, FIPNAMEL, and
FIPSTATE.
SAS Statements
Results
x=fipname(37);
put x;
NORTH CAROLINA
x=fipnamel(37);
put x;
North Carolina
x=fipstate(37);
put x;
NC
See Also
Functions:
“FIPNAME Function” on page 567
“FIPNAMEL Function” on page 568
“STFIPS Function” on page 894
“STNAME Function” on page 895
“STNAMEL Function” on page 896
Functions and CALL Routines
4
FLOOR Function
571
FLOOR Function
Returns the largest integer that is less than or equal to the argument, fuzzed to avoid unexpected
floating-point results
Category: Truncation
Syntax
FLOOR (argument)
Arguments
argument
is numeric.
Details
If the argument is within 1E-12 of an integer, the function returns that integer.
Comparisons
Unlike the FLOORZ function, the FLOOR function fuzzes the result. If the argument is
within 1E-12 of an integer, the FLOOR function fuzzes the result to be equal to that
integer. The FLOORZ function does not fuzz the result. Therefore, with the FLOORZ
function you might get unexpected results.
Examples
The following SAS statements produce these results.
SAS Statements
Results
var1=2.1;
a=floor(var1);
put a;
2
var2=-2.4;
b=floor(var2);
put b;
-3
c=floor(-1.6);
put c;
-2
d=floor(1.-1.e-13);
put d;
1
e=floor(763);
put e;
763
f=floor(-223.456);
put f;
-224
572
FLOORZ Function
4
Chapter 4
See Also
Functions:
“FLOORZ Function” on page 572
FLOORZ Function
Returns the largest integer that is less than or equal to the argument, using zero fuzzing
Category:
Truncation
Syntax
FLOORZ (argument)
Arguments
argument
is a numeric constant, variable, or expression.
Comparisons
Unlike the FLOOR function, the FLOORZ function uses zero fuzzing. If the argument
is within 1E-12 of an integer, the FLOOR function fuzzes the result to be equal to that
integer. The FLOORZ function does not fuzz the result. Therefore, with the FLOORZ
function you might get unexpected results.
Functions and CALL Routines
Examples
The following SAS statements produce these results.
SAS Statements
Results
var1=2.1;
a=floorz(var1);
put a;
2
var2=-2.4;
b=floorz(var2);
put b;
-3
c=floorz(-1.6);
put c;
-2
var6=(1.-1.e-13);
d=floorz(1-1.e-13);
put d;
0
e=floorz(763);
put e;
763
f=floorz(-223.456);
put f;
-224
See Also
Functions:
“FLOOR Function” on page 571
4
FLOORZ Function
573
574
4
FNONCT Function
Chapter 4
FNONCT Function
Returns the value of the noncentrality parameter of an F distribution
Category:
Mathematical
Syntax
FNONCT(x,ndf,ddf,prob)
Arguments
x
is a numeric random variable.
Range:
x≥0
ndf
is a numeric numerator degrees-of-freedom parameter.
Range:
ndf > 0
ddf
is a numeric denominator degrees-of-freedom parameter.
Range:
ddf > 0
prob
is a probability.
Range:
0 < prob < 1
Details
The FNONCT function returns the nonnegative noncentrality parameter from a
noncentral F distribution whose parameters are x, ndf, ddf, and nc. If prob is greater
than the probability from the central F distribution whose parameters are x, ndf, and
ddf, 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
Pf (xjndf; ddf; nc) 0 prob = 0
where
Pf (xjndf; ddf; nc) = e
0nc
2
X1
=
j 0
0 nc 1j
2
j!
I
(ndf )x
ddf +(ndf )x
ddf
2
+
j;
ddf
2
Functions and CALL Routines
4
FNONCT Function
where I (. . .) is the probability from the beta distribution that is given by
Zx
Ix (a; b) =
ta01 (1
0(a)0(b)
0(a+b) 0
0 t)b01 dt
If the algorithm fails to converge to a fixed point, a missing value is returned.
Examples
data work;
x=2;
df=4;
ddf=5;
do nc=1 to 3 by .5;
prob=probf(x,df,ddf,nc);
ncc=fnonct(x,df,ddf,prob);
output;
end;
run;
proc print;
run;
Output 4.24
FNONCT Example Output
OBS
1
2
3
4
5
x
2
2
2
2
2
df
4
4
4
4
4
ddf
5
5
5
5
5
nc
1.0
1.5
2.0
2.5
3.0
prob
0.69277
0.65701
0.62232
0.58878
0.55642
ncc
1.0
1.5
2.0
2.5
3.0
575
576
FNOTE Function
4
Chapter 4
FNOTE Function
Identifies the last record that was read and returns a value that FPOINT can use
Category:
External Files
Syntax
FNOTE(file-id)
Argument
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
Details
You can use FNOTE like a bookmark, marking the position in the file so that your
application can later return to that position using FPOINT. The value returned by
FNOTE is required by the FPOINT function to reposition the file pointe r on a specific
record.
To free the memory associated with each FNOTE identifier, use DROPNOTE.
Functions and CALL Routines
4
FNOTE Function
577
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,
then it reads the records, stores in the variable NOTE 3 the position of the third record
read, and then later uses FPOINT to point back to NOTE3 to update the file. After
updating the record, it closes the file:
%let
fref=MYFILE;
%let rc=%sysfunc(filename(fref,
physical-filename));
%let fid=%sysfunc(fopen(&fref,u));
%if &fid > 0 %then
%do;
%let rc=%sysfunc(fread(&fid));
/* Read second record. */
%let rc=%sysfunc(fread(&fid));
/* Read third record. */
%let rc=%sysfunc(fread(&fid));
/* Note position of third record. */
%let note3=%sysfunc(fnote(&fid));
/* Read fourth record. */
%let rc=%sysfunc(fread(&fid));
/* Read fifth record. */
%let rc=%sysfunc(fread(&fid));
/* Point to third record. */
%let rc=%sysfunc(fpoint(&fid,&note3));
/* Read third record. */
%let rc=%sysfunc(fread(&fid));
/* Copy new text to FDB. */
%let rc=%sysfunc(fput(&fid,New text));
/* Update third record */
/* with data in FDB. */
%let rc=%sysfunc(fwrite(&fid));
/* Close file. */
%let rc=%sysfunc(fclose(&fid));
%end;
%let rc=%sysfunc(filename(fref));
578
FOPEN Function
4
Chapter 4
See Also
Functions:
“DROPNOTE Function” on page 532
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FOPEN Function” on page 578
“FPOINT Function” on page 583
“FPUT Function” on page 586
“FREAD Function” on page 587
“FREWIND Function” on page 588
“FWRITE Function” on page 593
“MOPEN Function” on page 696
FOPEN Function
Opens an external file and returns a file identifier value
Category:
See:
External Files
FOPEN Function in the documentation for your operating environment.
Syntax
FOPEN(fileref< ,open-mode< ,record-length<,record-format>>>)
Arguments
fileref
specifies the fileref assigned to the external file.
open-mode
specifies the type of access to the file:
A
APPEND mode allows writing new records after the current end
of the file.
I
INPUT mode allows reading only (default).
O
OUTPUT mode defaults to the OPEN mode specified in the
operating environment option in the FILENAME statement or
function. If no operating environment option is specified, it allows
writing new records at the beginning of the file.
S
Sequential input mode is used for pipes and other sequential
devices such as hardware ports.
U
UPDATE mode allows both reading and writing.
Default: I
Functions and CALL Routines
4
FOPEN Function
579
record-length
specifies the logical record length of the file. To use the existing record length for the
file, specify a length of 0, or do not provide a value here.
record-format
specifies the record format of the file. To use the existing record format, do not
specify a value here. Valid values are:
B
data are to be interpreted as binary data.
D
use default record format.
E
use editable record format.
F
file contains fixed length records.
P
file contains printer carriage control in operating
environment-dependent record format. Note: For z/OS data sets
with FBA or VBA record format, specify ‘P’ for the record-format
argument.
V
file contains variable length records.
Details
CAUTION:
Use OUTPUT mode with care. Opening an existing file for output overwrites the
current contents of the file without warning. 4
The FOPEN function opens an external file for reading or updating and returns a file
identifier value that is used to identify the open file to other functions. You must
associate a fileref with the external file before calling the FOPEN function. FOPEN
returns a 0 if the file could not be opened. You can assign filerefs by using the
FILENAME statement or the FILENAME external file access function. Under some
operating environments, you can also assign filerefs by using system comman ds.
Operating Environment Information: On some operating environments you must close
the file at the end of the DATA step using the FCLOSE function. For details, see the
SAS documentation for your operating environment. 4
Examples
Example 1: Opening a File Using Defaults
This example assigns the fileref MYFILE to
an external file and attempts to open the file for input using all defaults. 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));
Example 2: Opening a File without Using Defaults
This example attempts to open a
file for input without using defaults. Note that in a macro statement you do not enclose
character strings in quotation marks.
%let fid=%sysfunc(fopen(file2,o,132,e));
580
FOPTNAME Function
4
Chapter 4
See Also
Functions:
“DOPEN Function” on page 527
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FILEREF Function” on page 557
“MOPEN Function” on page 696
Statement:
“FILENAME Statement” on page 1257
FOPTNAME Function
Returns the name of an item of information about a file
Category:
See:
External Files
FOPTNAME Function in the documentation for your operating environment.
Syntax
FOPTNAME(file-id,nval)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
nval
specifies the number of the information item.
Details
FOPTNAME returns a blank if an error occurred.
Operating Environment Information: The number, value, and type of information
items that are available depend on the operating environment. 4
Examples
Example 1: Retrieving File Information Items and Writing Them to the Log
This
example retrieves the system-dependent file information items that are available and
writes them to the log:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
Functions and CALL Routines
4
FOPTNAME Function
581
%let fid=%sysfunc(fopen(&filrf));
%let infonum=%sysfunc(foptnum(&fid));
%do j=1 %to &infonum;
%let name=%sysfunc(foptname(&fid,&j));
%let value=%sysfunc(finfo(&fid,&name));
%put File attribute &name equals &value;
%end;
%let rc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(filrf));
Example 2: Creating a Data Set with Names and Values of File Attributes
This example
creates a data set that contains the name and value of the available file attributes:
data fileatt;
length name $ 20 value $ 40;
drop rc fid j infonum;
rc=filename("myfile","physical-filename");
fid=fopen("myfile");
infonum=foptnum(fid);
do j=1 to infonum;
name=foptname(fid,j);
value=finfo(fid,name);
put ’File attribute ’ name
’has a value of ’ value;
output;
end;
rc=filename("myfile");
run;
See Also
Functions:
“DINFO Function” on page 524
“DOPTNAME Function” on page 528
“DOPTNUM Function” on page 530
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FINFO Function” on page 565
“FOPEN Function” on page 578
“FOPTNUM Function” on page 582
“MOPEN Function” on page 696
582
4
FOPTNUM Function
Chapter 4
FOPTNUM Function
Returns the number of information items that are available for an external file
External Files
Category:
See:
FOPTNUM Function in the documentation for your operating environment.
Syntax
FOPTNUM(file-id)
Argument
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
Details
Operating Environment Information: The number, value, and type of information
items that are available depend on the operating environment. 4
Comparisons
3 Use FOPTNAME to determine the names of the items that are available for a
particular operating environment.
3 Use FINFO to retrieve the value of a particular information item.
Examples
This example opens the external file with the fileref MYFILE and determines the
number of system-dependent file information items available:
%let fid=%sysfunc(fopen(myfile));
%let infonum=%sysfunc(foptnum(&fid));
See Also
Functions:
“DINFO Function” on page 524
“DOPTNAME Function” on page 528
“DOPTNUM Function” on page 530
“FINFO Function” on page 565
“FOPEN Function” on page 578
“FOPTNAME Function” on page 580
“MOPEN Function” on page 696
See the “Examples” on page 580 in the FOPTNAME Function.
Functions and CALL Routines
4
FPOINT Function
583
FPOINT Function
Positions the read pointer on the next record to be read
Category: External Files
Syntax
FPOINT(file-id,note-id)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
note-id
specifies the identifier that was assigned by the FNOTE function.
Details
FPOINT returns 0 if the operation was successful, or ≠0 if it was not successful.
FPOINT determines only the record to read next. It has no impact on which record is
written next. When you open the file for update, FWRITE writes to the most recently
read record.
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file. If the file is opened successfully, it reads the records and uses NOTE3 to store the
position of the third record read. Later, it points back to NOTE3 to update the file, and
closes the file afterward:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf,u));
%if &fid > 0 %then
%do;
/* Read first record. */
%let rc=%sysfunc(fread(&fid));
/* Read second record. */
%let rc=%sysfunc(fread(&fid));
/* Read third record. */
%let rc=%sysfunc(fread(&fid));
/* Note position of third record. */
%let note3=%sysfunc(fnote(&fid));
/* Read fourth record. */
%let rc=%sysfunc(fread(&fid));
/* Read fifth record. */
%let rc=%sysfunc(fread(&fid));
584
FPOS Function
4
Chapter 4
/* Point to third record. */
%let rc=%sysfunc(fpoint(&fid,&note3));
/* Read third record. */
%let rc=%sysfunc(fread(&fid));
/* Copy new text to FDB. */
%let rc=%sysfunc(fput(&fid,New text));
/* Update third record */
/* with data in FDB. */
%let rc=%sysfunc(fwrite(&fid));
/* Close file. */
%let rc=%sysfunc(fclose(&fid));
%end;
%let rc=%sysfunc(filename(filrf));
See Also
Functions:
“DROPNOTE Function” on page 532
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FNOTE Function” on page 576
“FOPEN Function” on page 578
“FPUT Function” on page 586
“FREAD Function” on page 587
“FREWIND Function” on page 588
“FWRITE Function” on page 593
“MOPEN Function” on page 696
FPOS Function
Sets the position of the column pointer in the File Data Buffer (FDB)
Category:
External Files
Syntax
FPOS(file-id,nval)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
nval
specifies the column at which to set the pointer.
Functions and CALL Routines
4
FPOS Function
585
Details
FPOS returns 0 if the operation was successful, ≠0 if it was not successful. If the
specified position is past the end of the current record, the size of the record is
increased appropriately. However, in a fixed block or VBA file, if you specify a column
position beyond the end of the record, the record size does not change and the text
string is not written to the file.
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,
it places data into the file’s buffer at column 12, writes the record, and closes the file:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf,o));
%if (&fid > 0) %then
%do;
%let dataline=This is some data.;
/* Position at column 12 in the FDB. */
%let rc=%sysfunc(fpos(&fid,12));
/* Put the data in the FDB. */
%let rc=%sysfunc(fput(&fid,&dataline));
/* Write the record. */
%let rc=%sysfunc(fwrite(&fid));
/* Close the file. */
%let rc=%sysfunc(fclose(&fid));
%end;
%let rc=%sysfunc(filename(filrf));
See Also
Functions:
“FCLOSE Function” on page 544
“FCOL Function” on page 545
“FILENAME Function” on page 555
“FOPEN Function” on page 578
“FPUT Function” on page 586
“FWRITE Function” on page 593
“MOPEN Function” on page 696
586
FPUT Function
4
Chapter 4
FPUT Function
Moves data to the File Data Buffer (FDB) of an external file, starting at the FDB’s current column
position
Category:
External Files
Syntax
FPUT(file-id,cval)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
cval
specifies the file data. In a DATA step, cval can be a character string in quotation
marks or a DATA step variable. In a macro, cval is a macro variable.
Details
FPUT returns 0 if the operation was successful, ≠0 if it was not successful. The number
of bytes moved to the FDB is determined by the length of the variable. The value of the
column pointer is then increased to one position pas t the end of the new text.
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file in APPEND mode. If the file is opened successfully, indicated by a positive value in
the variable FID, it moves data to the FDB using FPUT, appends a record using
FWRITE, 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 mystring=This is some data.;
%let rc=%sysfunc(fput(&fid,&mystring));
%let rc=%sysfunc(fwrite(&fid));
%let rc=%sysfunc(fclose(&fid));
%end;
%else
%put %sysfunc(sysmsg());
%let rc=%sysfunc(filename(filrf));
Functions and CALL Routines
4
FREAD Function
587
See Also
Functions:
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FNOTE Function” on page 576
“FOPEN Function” on page 578
“FPOINT Function” on page 583
“FPOS Function” on page 584
“FWRITE Function” on page 593
“MOPEN Function” on page 696
“SYSMSG Function” on page 914
FREAD Function
Reads a record from an external file into the File Data Buffer (FDB)
Category: External Files
Syntax
FREAD(file-id)
Argument
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
Details
FREAD returns 0 if the operation was successful, ≠0 if it was not successful. The
position of the file pointer is updated automatically after the read operation so that
successive FREAD functions read successive file records.
To position the file pointer explicitly, use FNOTE, FPOINT, and FREWIND.
588
FREWIND Function
4
Chapter 4
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file. If the file opens successfully, it lists all of the file’s records in the log:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf));
%if &fid > 0 %then
%do %while(%sysfunc(fread(&fid)) = 0);
%let rc=%sysfunc(fget(&fid,c,200));
%put &c;
%end;
%let rc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(filrf));
See Also
Functions:
“FCLOSE Function” on page 544
“FGET Function” on page 552
“FILENAME Function” on page 555
“FNOTE Function” on page 576
“FOPEN Function” on page 578
“FREWIND Function” on page 588
“FREWIND Function” on page 588
“MOPEN Function” on page 696
FREWIND Function
Positions the file pointer to the start of the file
Category:
External Files
Syntax
FREWIND(file-id)
Functions and CALL Routines
4
FREWIND Function
589
Argument
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
Details
FREWIND returns 0 if the operation was successful, ≠0 if it was not successful.
FREWIND has no effect on a file opened with sequential access.
Examples
This example assigns the fileref MYFILE to an external file. Then it opens the file
and reads the records until the end of the file is reached. The FREWIND function then
repositions the pointer to the beginning of the file. The first record is read again and
stored in the File Data Buffer (FDB). The first token is retrieved and stored in the
macro variable VAL:
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf));
%let rc=0;
%do %while (&rc ne −1);
/* Read a record. */
%let rc=%sysfunc(fread(&fid));
%end;
/* Reposition pointer to beginning of file. */
%if &rc = −1 %then
%do;
%let rc=%sysfunc(frewind(&fid));
/* Read first record. */
%let rc=%sysfunc(fread(&fid));
/* Read first token */
/* into macro variable VAL. */
%let rc=%sysfunc(fget(&fid,val));
%put val=&val;
%end;
%else
%put Error on fread=%sysfunc(sysmsg());
%let rc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(filrf));
590
FRLEN Function
4
Chapter 4
See Also
Functions:
“FCLOSE Function” on page 544
“FGET Function” on page 552
“FILENAME Function” on page 555
“FOPEN Function” on page 578
“FREAD Function” on page 587
“MOPEN Function” on page 696
“SYSMSG Function” on page 914
FRLEN Function
Returns the size of the last record read, or, if the file is opened for output, returns the current
record size
Category:
External Files
Syntax
FRLEN(file-id)
Argument
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
Examples
This example opens the file that is identified by the fileref MYFILE. It determines
the minimum and maximum length of records in the external file and writes the results
to the log:
%let fid=%sysfunc(fopen(myfile));
%let min=0;
%let max=0;
%if (%sysfunc(fread(&fid)) = 0) %then
%do;
%let min=%sysfunc(frlen(&fid));
%let max=&min;
%do %while(%sysfunc(fread(&fid)) = 0);
%let reclen=%sysfunc(frlen(&fid));
%if (&reclen > &max) %then
%let max=&reclen;
%if (&reclen < &min) %then
%let min=&reclen;
Functions and CALL Routines
4
FSEP Function
591
%end;
%end;
%let rc=%sysfunc(fclose(&fid));
%put max=&max min=&min;
See Also
Functions:
“FCLOSE Function” on page 544
“FOPEN Function” on page 578
“FREAD Function” on page 587
“MOPEN Function” on page 696
FSEP Function
Sets the token delimiters for the FGET function
Category: External Files
Syntax
FSEP(file-id,character(s))
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
character
specifies one or more delimiters that separate items in the File Data Buffer (FDB).
Each character listed is a delimiter. That is, if character is #@, either # or @ can
separate items. Multiple consecutive delimiters, such as @#@, are treated as a single
delimiter.
Default: blank
Details
FSEP returns 0 if the operation was successful, ≠0 if it was not successful.
592
FUZZ Function
4
Chapter 4
Examples
An external file has data in this form:
John J. Doe,Male,25,Weight Lifter
Pat O’Neal,Female,22,Gymnast
Note that each field is separated by a comma.
This example reads the file that is identified by the fileref MYFILE, using the comma
as a separator, and writes the values for NAME, GENDER, AGE, and WORK to the
SAS log. Note that in a macro statement you do not enclose character strings in
quotation marks.
%let fid=%sysfunc(fopen(myfile));
%let rc=%sysfunc(fsep(&fid,%str(,)));
%do %while(%sysfunc(fread(&fid)) = 0);
%let rc=%sysfunc(fget(&fid,name));
%let rc=%sysfunc(fget(&fid,gender));
%let rc=%sysfunc(fget(&fid,age));
%let rc=%sysfunc(fget(&fid,work));
%put name=%bquote(&name) gender=&gender
age=&age work=&work;
%end;
%let rc=%sysfunc(fclose(&fid));
See Also
Functions:
“FCLOSE Function” on page 544
“FGET Function” on page 552
“FOPEN Function” on page 578
“FREAD Function” on page 587
“MOPEN Function” on page 696
FUZZ Function
Returns the nearest integer if the argument is within 1E−12
Category:
Truncation
Syntax
FUZZ(argument)
Functions and CALL Routines
4
FWRITE Function
593
Arguments
argument
is numeric.
Details
The FUZZ function returns the nearest integer value if the argument is within 1E−12 of
the integer (that is, if the absolute difference between the integer and argument is less
than 1E−12). Otherwise, the argument is returned.
Examples
SAS Statements
Results
var1=5.9999999999999;
x=fuzz(var1);
put x 16.14
6.000000000000000
x=fuzz(5.99999999);
put x 16.14;
5.999999990000000
FWRITE Function
Writes a record to an external file
Category: External Files
Syntax
FWRITE(file-id< ,cc>)
Arguments
file-id
specifies the identifier that was assigned when the file was opened, generally by the
FOPEN function.
594
FWRITE Function
4
Chapter 4
cc
specifies a carriage-control character:
blank
starts the record on a new line.
0
skips one blank line before a new line.
-
skips two blank lines before a new line.
1
starts the line on a new page.
+
overstrikes the line on a previous line.
P
interprets the line as a terminal prompt.
=
interprets the line as carriage control information.
all else
starts the line record on a new line.
Details
FWRITE returns 0 if the operation was successful, ≠0 if it was not successful. FWRITE
moves text from the File Data Buffer (FDB) to the external file. In order to use the
carriage control characters, you must open the file with a record format of P (print
format) in FOPEN.
Examples
This example assigns the fileref MYFILE to an external file and attempts to open the
file. If the file is opened successfully, it writes the numbers 1 to 50 to the external file,
skipping two blank lines. 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,o,0,P));
%do i=1 %to 50;
%let rc=%sysfunc(fput(&fid,
%sysfunc(putn(&i,2.))));
%if (%sysfunc(fwrite(&fid,-)) ne 0) %then
%put %sysfunc(sysmsg());
%end;
%let rc=%sysfunc(fclose(&fid));
Functions and CALL Routines
4
GAMINV Function
595
See Also
Functions:
“FAPPEND Function” on page 542
“FCLOSE Function” on page 544
“FGET Function” on page 552
“FILENAME Function” on page 555
“FOPEN Function” on page 578
“FPUT Function” on page 586
“SYSMSG Function” on page 914
GAMINV Function
Returns a quantile from the gamma distribution
Category: Quantile
Syntax
GAMINV(p,a)
Arguments
p
is a numeric probability.
Range: 0 ≤ p < 1
a
is a numeric shape parameter.
Range: a > 0
Details
th
The GAMINV function returns the p quantile from the gamma distribution, with
shape parameter a. The probability that an observation from a gamma distribution is
less than or equal to the returned quantile is p.
Note:
GAMINV is the inverse of the PROBGAM function.
4
596
GAMMA Function
4
Chapter 4
Examples
SAS Statements
Results
q1=gaminv(0.5,9);
8.6689511844
q2=gaminv(0.1,2.1);
0.5841932369
GAMMA Function
Returns the value of the Gamma function
Category:
Mathematical
Syntax
GAMMA(argument)
Arguments
argument
is numeric.
Restriction: Nonpositive integers are invalid.
Details
The GAMMA function returns the integral, which is given by
GAMMA(x) =
Z1
x01 e01 dt:
t
0
For positive integers, GAMMA(x) is (x − 1)!. This function is commonly denoted by
0 (x).
Example
SAS Statements
Results
x=gamma(6);
120
Functions and CALL Routines
4
GEOMEAN Function
597
GEOMEAN Function
Returns the geometric mean
Category: Descriptive Statistics
Syntax
GEOMEAN(argument<,argument,…>)
Arguments
argument
is a non-negative numeric constant, variable, or expression.
Tip:
The argument list can consist of a variable list, which is preceded by OF.
Comparisons
The MEAN function returns the arithmetic mean (average), and the HARMEAN
function returns the harmonic mean, whereas the GEOMEAN function returns the
geometric mean of the non-missing values. Unlike GEOMEANZ, GEOMEAN fuzzes the
values of the arguments that are approximately zero.
Details
If any argument is negative, then the result is a missing value. A message appears in
the log that the negative argument is invalid, and _ERROR_ is set to 1. If any
argument is zero, then the geometric mean is zero. If all the arguments are missing
values, then the result is a missing value. Otherwise, the result is the geometric mean
of the non-missing values.
Let n be the number of arguments with non-missing values, and let x1 ; x2 ; . . . ; xn
be the values of those arguments. The geometric mean is the nth root of the product of
the values:
px
n
(
1
3 x2 3 . . . 3 xn )
Equivalently, the geometric mean is
exp
(log (
x1 ) + log (x2 ) + . . . + log (xn ))
n
598
GEOMEANZ Function
4
Chapter 4
Floating-point arithmetic often produces tiny numerical errors. Some computations
that result in zero when exact arithmetic is used might result in a tiny non-zero value
when floating-point arithmetic is used. Therefore, GEOMEAN fuzzes the values of
arguments that are approximately zero. When the value of one argument is extremely
small relative to the largest argument, then the former argument is treated as zero. If
you do not want SAS to fuzz the extremely small values, then use the GEOMEANZ
function.
Examples
SAS Statements
Results
x1=geomean(1,2,2,4);
2
x2=geomean(.,2,4,8);
4
x3=geomean(of x1-x2);
2.8284271247
See Also
Function:
“GEOMEANZ Function” on page 598
“HARMEAN Function” on page 605
“HARMEANZ Function” on page 606
“MEAN Function” on page 681
GEOMEANZ Function
Returns the geometric mean, using zero fuzzing
Category:
Descriptive Statistics
Syntax
GEOMEANZ(argument< ,argument,…>)
Functions and CALL Routines
4
GEOMEANZ Function
599
Arguments
argument
is a non-negative numeric constant, variable, or expression.
Tip: The argument list can consist of a variable list, which is preceded by OF.
Comparisons
The MEAN function returns the arithmetic mean (average), and the HARMEAN
function returns the harmonic mean, whereas the GEOMEANZ function returns the
geometric mean of the non-missing values. Unlike GEOMEAN, GEOMEANZ does not
fuzz the values of the arguments that are approximately zero.
Details
If any argument is negative, then the result is a missing value. A message appears in
the log that the negative argument is invalid, and _ERROR_ is set to 1. If any
argument is zero, then the geometric mean is zero. If all the arguments are missing
values, then the result is a missing value. Otherwise, the result is the geometric mean
of the non-missing values.
Let n be the number of arguments with non-missing values, and let x1 ; x2 ; . . . ; xn
be the values of those arguments. The geometric mean is the nth root of the product of
the values:
px
n
(
1
3 x2 3 . . . 3 xn )
Equivalently, the geometric mean is
exp
(log (
x1 ) + log (x2 ) + . . . + log (xn ))
n
Examples
SAS Statements
Results
x1=geomeanz(1,2,2,4);
2
x2=geomeanz(.,2,4,8);
4
x3=geomeanz(of x1-x2);
2.8284271247
600
GETOPTION Function
4
Chapter 4
See Also
Function:
“GEOMEAN Function” on page 597
“HARMEAN Function” on page 605
“HARMEANZ Function” on page 606
“MEAN Function” on page 681
GETOPTION Function
Returns the value of a SAS system or graphics option
Category:
Special
Syntax
GETOPTION(option-name<,reporting-options< ,…>>)
Arguments
option-name
is the name of the system option.
Tip: Do not put an equals sign after the name. For example, write PAGESIZE= as
PAGESIZE.
Note: SAS options that are passwords, such as EMAILPW and METAPASS,
return the value xxxxxxxx, and not the actual password. 4
reporting-options
specifies the reporting options. You can separate the options with blanks, or you can
specify each reporting option as a separate argument to the GETOPTION function.
The reporting options are
IN
reports graphic units of measure in inches.
CM
reports graphic units of measure in centimeters.
KEYWORD
returns option values in a KEYWORD= format that would be
suitable for direct use in the SAS OPTIONS or GOPTIONS global
statements.
Functions and CALL Routines
4
GETOPTION Function
601
Examples
Example 1: Using GETOPTION to Change the YEARCUTOFF Option
This example saves
the initial value of the YEARCUTOFF option and then resets the value to 1920. The
DATA step that follows verifies the option setting and performs date processing. When
the DATA step ends, the YEARCUTOFF option is set to its original value.
%let cutoff=%sysfunc(getoption
(yearcutoff,keyword));
options yearcutoff=1920;
data ages;
if getoption(’yearcutoff’) = ’1920’ then
do;
...more statements...
end;
else put ’Set Option YEARCUTOFF to 1920’;
run;
options &cutoff;
Example 2: Using GETOPTION to Obtain Different Reporting Options
This example
defines a macro to illustrate the use of the GETOPTION function to obtain the value of
system and graphics options by using different reporting options.
%macro showopts;
%put PAGESIZE= %sysfunc(
getoption(PAGESIZE));
%put PS= %sysfunc(
getoption(PS));
%put LS= %sysfunc(
getoption(LS));
%put PS(keyword form)= %sysfunc(
getoption(PS,keyword));
%put LS(keyword form)= %sysfunc(
getoption(LS,keyword));
%put FORMCHAR= %sysfunc(
getoption(FORMCHAR));
%put HSIZE= %sysfunc(
getoption(HSIZE));
%put VSIZE= %sysfunc(
getoption(VSIZE));
%put HSIZE(in/keyword form)= %sysfunc(
getoption(HSIZE,in,keyword));
%put HSIZE(cm/keyword form)= %sysfunc(
getoption(HSIZE,cm,keyword));
%put VSIZE(in/keyword form)= %sysfunc(
getoption(VSIZE,in,keyword));
%put HSIZE(cm/keyword form)= %sysfunc(
getoption(VSIZE,cm,keyword));
%mend;
goptions VSIZE=8.5 in HSIZE=11 in;
%showopts;
602
GETVARC Function
4
Chapter 4
The following is SAS output from the example.
PAGESIZE= 23
PS= 23
LS= 76
PS(keyword form)= PS=23
LS(keyword form)= LS=76
FORMCHAR= |----|+|---+=|-/\<>*
HSIZE= 11.0000 in.
VSIZE= 8.5000 in.
HSIZE(in/keyword form)= HSIZE=11.0000 in.
HSIZE(cm/keyword form)= HSIZE=27.9400 cm.
VSIZE(in/keyword form)= VSIZE=8.5000 in.
HSIZE(cm/keyword form)= VSIZE=21.5900 cm.
Note: The default settings for pagesize and linesize depend on the mode you use to
run SAS. 4
GETVARC Function
Returns the value of a SAS data set character variable
SAS File I/O
Category:
Syntax
GETVARC(data-set-id,var-num)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
var-num
is the number of the variable in the Data Set Data Vector (DDV).
Tip:
You can obtain this value by using the VARNUM function.
This value is listed next to the variable when you use the CONTENTS
procedure.
Tip:
Details
Use VARNUM to obtain the number of a variable in a SAS data set. VARNUM can be
nested or it can be assigned to a variable that can then be passed as the second
argument, as shown in the following examples. GETVARC reads the value of a
character variable from the current observation in the Data Set Data Vector (DDV) into
a macro or DATA step variable.
Functions and CALL Routines
4
GETVARN Function
603
Examples
3 This example opens the SASUSER.HOUSES data set and gets the entire tenth
observation. The data set identifier value for the open data set is stored in the
macro variable MYDATAID. This example nests VARNUM to return the position of
the variable in the DDV, and reads in the value of the character variable STYLE.
%let mydataid=%sysfunc(open
(sasuser.houses,i));
%let rc=%sysfunc(fetchobs(&mydataid,10));
%let style=%sysfunc(getvarc(&mydataid,
%sysfunc(varnum
(&mydataid,STYLE))));
%let rc=%sysfunc(close(&mydataid));
3 This example assigns VARNUM to a variable that can then be passed as the
second argument. This example fetches data from observation 10.
%let namenum=%sysfunc(varnum(&mydataid,NAME));
%let rc=%sysfunc(fetchobs(&mydataid,10));
%let user=%sysfunc(getvarc
(&mydataid,&namenum));
See Also
Functions:
“FETCH Function” on page 548
“FETCHOBS Function” on page 549
“GETVARN Function” on page 603
“VARNUM Function” on page 949
GETVARN Function
Returns the value of a SAS data set numeric variable
Category: SAS File I/O
Syntax
GETVARN(data-set-id,var-num)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
604
GETVARN Function
4
Chapter 4
var-num
is the number of the variable in the Data Set Data Vector (DDV).
You can obtain this value by using the VARNUM function.
Tip:
This value is listed next to the variable when you use the CONTENTS
procedure.
Tip:
Details
Use VARNUM to obtain the number of a variable in a SAS data set. You can nest
VARNUM or you can assign it to a variable that can then be passed as the second
argument, as shown in the "Examples" section. GETVARN reads the value of a numeric
variable from the current observation in the Data Set Data Vector (DDV) into a macro
variable or DATA step variable.
Examples
3 This example obtains the entire tenth observation from a SAS data set. The data
set must have been previously opened using OPEN. The data set identifier value
for the open data set is stored in the variable MYDATAID. This example nests
VARNUM, and reads in the value of the numeric variable PRICE from the tenth
observation of an open SAS data set.
%let rc=%sysfunc(fetchobs(&mydataid,10));
%let price=%sysfunc(getvarn(&mydataid,
%sysfunc(varnum
(&mydataid,price))));
3 This example assigns VARNUM to a variable that can then be passed as the
second argument. This example fetches data from observation 10.
%let pricenum=%sysfunc(varnum
(&mydataid,price));
%let rc=%sysfunc(fetchobs(&mydataid,10));
%let price=%sysfunc(getvarn
(&mydataid,&pricenum));
See Also
Functions:
“FETCH Function” on page 548
“FETCHOBS Function” on page 549
“GETVARC Function” on page 602
“VARNUM Function” on page 949
Functions and CALL Routines
4
HARMEAN Function
605
HARMEAN Function
Returns the harmonic mean
Category: Descriptive Statistics
Syntax
HARMEAN(argument< ,argument,…>)
Arguments
argument
is a non-negative numeric constant, variable, or expression.
Tip:
The argument list can consist of a variable list, which is preceded by OF.
Comparisons
The MEAN function returns the arithmetic mean (average), and the GEOMEAN
function returns the geometric mean, whereas the HARMEAN function returns the
harmonic mean of the non-missing values. Unlike HARMEANZ, HARMEAN fuzzes the
values of the arguments that are approximately zero.
Details
If any argument is negative, then the result is a missing value. A message appears in
the log that the negative argument is invalid, and _ERROR_ is set to 1. If all the
arguments are missing values, then the result is a missing value. Otherwise, the result
is the harmonic mean of the non-missing values.
If any argument is zero, then the harmonic mean is zero. Otherwise, the harmonic
mean is the reciprocal of the arithmetic mean of the reciprocals of the values.
Let n be the number of arguments with non-missing values, and let x1 ; x2 ; . . . ; xn be
the values of those arguments. The harmonic mean is
1
x1
+
1
x2
n
+ ... +
1
xn
Floating-point arithmetic often produces tiny numerical errors. Some computations
that result in zero when exact arithmetic is used might result in a tiny non-zero value
when floating-point arithmetic is used. Therefore, HARMEAN fuzzes the values of
arguments that are approximately zero. When the value of one argument is extremely
small relative to the largest argument, then the former argument is treated as zero. If
you do not want SAS to fuzz the extremely small values, then use the HARMEANZ
function.
606
HARMEANZ Function
4
Chapter 4
Examples
SAS Statements
Results
x1=harmean(1,2,4,4);
2
x2=harmean(.,4,12,24);
8
x3=harmean(of x1-x2);
3.2
See Also
Function:
“GEOMEAN Function” on page 597
“GEOMEANZ Function” on page 598
“HARMEANZ Function” on page 606
“MEAN Function” on page 681
HARMEANZ Function
Returns the harmonic mean, using zero fuzzing
Category:
Descriptive Statistics
Syntax
HARMEANZ(argument<,argument,…)>
Arguments
argument
is a non-negative numeric constant, variable, or expression.
Tip:
The argument list can consist of a variable list, which is preceded by OF.
Functions and CALL Routines
4
HARMEANZ Function
607
Comparisons
The MEAN function returns the arithmetic mean (average), and the GEOMEAN
function returns the geometric mean, whereas the HARMEANZ function returns the
harmonic mean of the non-missing values. Unlike HARMEAN, HARMEANZ does not
fuzz the values of the arguments that are approximately zero.
Details
If any argument is negative, then the result is a missing value. A message appears in
the log that the negative argument is invalid, and _ERROR_ is set to 1. If all the
arguments are missing values, then the result is a missing value. Otherwise, the result
is the harmonic mean of the non-missing values.
If any argument is zero, then the harmonic mean is zero. Otherwise, the harmonic
mean is the reciprocal of the arithmetic mean of the reciprocals of the values.
Let n be the number of arguments with non-missing values, and let x1 ; x2 ; . . . ; xn be
the values of those arguments. The harmonic mean is
1
x1
+
1
x2
n
+ ... +
1
xn
Examples
SAS Statements
Results
x1=harmeanz(1,2,4,4);
2
x2=harmeanz(.,4,12,24);
8
x3=harmeanz(of x1-x2);
3.2
See Also
Function:
“GEOMEAN Function” on page 597
“GEOMEANZ Function” on page 598
“HARMEAN Function” on page 605
“MEAN Function” on page 681
608
HBOUND Function
4
Chapter 4
HBOUND Function
Returns the upper bound of an array
Category:
Array
Syntax
HBOUND<n>(array-name)
HBOUND(array-name,bound-n)
Arguments
n
specifies the dimension for which you want to know the upper bound. If no n value is
specified, the HBOUND function returns the upper bound of the first dimension of
the array.
array-name
specifies the name of an array defined previously in the same DATA step.
bound-n
specifies the dimension for which you want to know the upper bound. Use bound-n
only if n is not specified.
Details
The HBOUND function returns the upper bound of a one-dimensional array or the
upper bound of a specified dimension of a multidimensional array. Use HBOUND in
array processing to avoid changing the upper bound of an iterative DO group each time
you change the bounds of the array. HBOUND and LBOUND can be used together to
return the values of the upper and lower bounds of an array dimension.
Comparisons
3 HBOUND returns the literal value of the upper bound of an array dimension.
3 DIM always returns a total count of the number of elements in 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
Functions and CALL Routines
4
HBOUND Function
609
Examples
Example 1: One-dimensional Array
In this example, HBOUND returns the upper
bound of the dimension, 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 hbound(big5);
more SAS statements;
end;
Example 2: Multidimensional Array
This example shows two ways of specifying the
HBOUND function for multidimensional arrays. Both methods return the same value
for HBOUND, as shown in the table that follows the SAS code example.
array mult{2:6,4:13,2} mult1-mult100;
Syntax
Alternative Syntax
Value
HBOUND(MULT)
HBOUND(MULT,1)
6
HBOUND2(MULT)
HBOUND(MULT,2)
13
HBOUND3(MULT)
HBOUND(MULT,3)
2
See Also
Functions:
“DIM Function” on page 523
“LBOUND Function” on page 659
Statements:
“ARRAY Statement” on page 1187
“Array Reference Statement” on page 1191
“Array Processing” in SAS Language Reference: Concepts
610
HMS Function
4
Chapter 4
HMS Function
Returns a SAS time value from hour, minute, and second values
Date and Time
Category:
Syntax
HMS(hour,minute,second)
Arguments
hour
is numeric.
minute
is numeric.
second
is numeric.
Details
The HMS function returns a positive numeric value that represents a SAS time value.
Examples
The following SAS statements produce these results:
SAS Statements
Results
hrid=hms(12,45,10);
put hrid
/ hrid time.;
45910
2:45:10
See Also
Functions:
“DHMS Function” on page 519
“HOUR Function” on page 611
“MINUTE Function” on page 684
“SECOND Function” on page 880
Functions and CALL Routines
4
HOUR Function
611
HOUR Function
Returns the hour from a SAS time or datetime value
Category: Date and Time
Syntax
HOUR(<time | datetime>)
Arguments
time
specifies a SAS expression that represents a SAS time value.
datetime
specifies a SAS expression that represents a SAS datetime value.
Details
The HOUR function returns a numeric value that represents the hour from a SAS time
or datetime value. Numeric values can range from 0 through 23. HOUR always returns
a positive number.
Examples
The following SAS statements produce these results:
SAS Statements
Results
now=’1:30’t;
h=hour(now);
put h;
1
See Also
Functions:
“MINUTE Function” on page 684
“SECOND Function” on page 880
612
HTMLDECODE Function
4
Chapter 4
HTMLDECODE Function
Decodes a string containing HTML numeric character references or HTML character entity
references and returns the decoded string
Category:
Web Tools
Syntax
HTMLDECODE(expression)
Arguments
expression
specifies any character expression.
Details
The HTMLDECODE function recognizes the following character entity references:
Character entity reference
decoded character
&amp;
&
&lt;
<
&gt;
>
&quot;
"
&apos;*
’
* (SAS 9 only)
Unrecognized entities (&<name>;) are left unmodified in the output string.
The HTMLDECODE function recognizes numeric entity references that are of the
form
&#nnn;
where nnn specifies a decimal number that contains one or more
digits.
&#Xnnn;
where nnn specifies a hexadecimal number that contains one or
more digits.
Operating Environment Information: Numeric character references that cannot be
represented in the current SAS session encoding will not be decoded. The reference will
be copied unchanged to the output string. 4
Functions and CALL Routines
4
HTMLENCODE Function
613
Examples
SAS Statements
Results
x1=htmldecode(’not a &lt;tag&gt;’);
not a <tag>
x2=htmldecode(’&amp;);
’&’
x3=htmldecode (’&#65;&#66;&#67;’);
’ABC’
See Also
Function:
“HTMLENCODE Function” on page 613
HTMLENCODE Function
Encodes characters using HTML character entity references and returns the encoded string
Category: Web Tools
Syntax
HTMLENCODE(expression, <options>)
Arguments
expression
specifies any character expression. By default, any greater-than (>), less-than (<),
and ampersand (&) characters are encoded as &gt;, &lt;, and &amp;, respectively.
In SAS 9 only, this behavior can be modified with the options argument.
Note: The encoded string can be longer than the original string. You should take
the additional length into consideration when you define your output variable. If the
encoded string exceeds the maximum length that is defined, the output string might
be truncated. 4
614
HTMLENCODE Function
4
Chapter 4
options
specifies the type of characters to encode. The value can be any string expression. If
you use more than one option, separate the options by spaces. See “Details” on page
614 for a list of valid options.
Note:
This argument is available in SAS 9 only.
4
Details
Option
Character
Character
Entity
Reference
Description
amp
&
&amp;
gt
>
&gt;
lt
<
&lt;
The HTMLENCODE function encodes these
characters by default. If you need to encode
these characters only, then you do not need to
specify the options argument. However, if you
specify any value for the options argument,
then the defaults are overridden, and you
must explicitly specify the options for all of
the characters you want to encode.
apos
’
&apos;
Use this option to encode the apostrophe ( ’)
character in text that is used in an HTML or
XML tag attribute.
quot
"
&quot;
Use this option to encode the double
quotation mark (") character in text that is
used in an HTML or XML tag attribute.
7bit
any character that
is not represented
in 7-bit ASCII
encoding
&#xnnn;
(Unicode)
nnn is a one or more digit hexadecimal
number. Encode these characters to create
HTML or XML that is easily transferred
through communication paths that might only
support 7-bit ASCII encodings (for example,
ftp or e-mail).
Examples
SAS Statements
Results
htmlencode("John’s test <tag>")
John’s test &lt;tag&gt;
htmlencode("John’s test <tag>",’apos’)
John&apos;s test <tag>
htmlencode(’John "Jon" Smith <tag>’,’quot’)
John &quot;Jon&quot; Smith <tag>
htmlencode("’A&B&C’",’amp lt gt apos’)
&apos;A&amp;B&amp;C&apos;
htmlencode(’80’x, ’7bit’)
(’80’x is the euro symbol in Western European locales.)
&#x20AC;
(20AC is the Unicode code point for
the euro symbol.)
Functions and CALL Routines
4
IBESSEL Function
615
See Also
Function:
“HTMLDECODE Function” on page 612
IBESSEL Function
Returns the value of the modified bessel function
Category: Mathematical
Syntax
IBESSEL(nu,x,kode)
Arguments
nu
is numeric.
Range: nu ≥ 0
x
is numeric.
Range: x ≥ 0
kode
is a nonnegative integer.
Details
The IBESSEL function returns the value of the modified bessel function of order nu
evaluated at x (Abramowitz, Stegun 1964; Amos, Daniel, Weston 1977). When kode
equals 0, the bessel function is returned. Otherwise, the value of the following function
is returned:
e0x Inm (x)
Examples
SAS Statements
Results
x=ibessel(2,2,0);
0.6889484477
x=ibessel(2,2,1);
0.0932390333
616
IFC Function
4
Chapter 4
IFC Function
Returns a character value of an expression based on whether the expression is true, false, or
missing
Category:
Character
Syntax
IFC(logical-expression, value-returned-when-true, value-returned-when-false
<,value-returned-when-missing>)
Arguments
logical-expression
specifies a numeric expression.
value-returned-when-true
specifies a character expression that is returned when the value of logical-expression
is true.
value-returned-when-false
specifies a character expression that is returned when the value of logical-expression
is false.
value-returned-when-missing
specifies a character expression that is returned when the value of logical-expression
is missing.
Details
The IFC function uses conditional logic that enables you to select among several
different values based on the value of a logical expression.
IFC evaluates the first argument, logical-expression. If logical-expression is true (that
is, not zero and not missing), then IFC returns the value in the second argument. If
logical-expression is a missing value, and you have a fourth argument, then IFC returns
the value in the fourth argument. If logical-expression is false, IFC returns the value in
the third argument.
The IFC function is useful in DATA step expressions, and even more useful in
WHERE clauses and other expressions where it is not convenient or possible to use an
IF/THEN/ELSE construct.
Comparisons
The IFC function is similar to the IFN function except that IFC returns a character
value while IFN returns a numeric value.
Examples
In the following example, IFC evaluates the expression grade>80 to implement the
logic that determines the performance of several members on a team. The results are
written to the SAS log.
Functions and CALL Routines
data _null_;
input name $ grade;
performance = ifc(grade>80, ’Pass
put name= performance=;
datalines;
John 74
Kareem 89
Kati 100
Maria 92
;
4
IFC Function
617
’, ’Needs Improvement’);
run;
Output 4.25
Partial SAS Log: IFC Function
name=John performance=Needs Improvement
name=Kareem performance=Pass
name=Kati performance=Pass
name=Maria performance=Pass
This example uses an IF/THEN/ELSE construct to generate the same output that is
generated by the IFC function. The results are written to the SAS log.
data _null_;
input name $ grade;
if grade>80 then performance=’Pass
else performance = ’Needs Improvement’;
put name= performance=;
datalines;
John 74
Sam 89
Kati 100
Maria 92
;
run;
Output 4.26
Partial SAS Log: IF/THEN/ELSE Construct
name=John performance=Needs Improvement
name=Sam performance=Pass
name=Kati performance=Pass
name=Maria performance=Pass
See Also
Functions:
“IFN Function” on page 618
’;
618
IFN Function
4
Chapter 4
IFN Function
Returns a numeric value of an expression based on whether the expression is true, false, or
missing
Category:
Character
Syntax
IFN(logical-expression, value-returned-when-true, value-returned-when-false
<,value-returned-when-missing>)
Arguments
logical-expression
specifies a numeric expression.
value-returned-when-true
specifies a numeric expression that is returned when the value of logical-expression is
true.
value-returned-when-false
specifies a numeric expression that is returned when the value of logical-expression is
false.
value-returned-when-missing
specifies a numeric expression that is returned when the value of logical-expression is
missing.
Details
The IFN function uses conditional logic that enables you to select among several
different values based on the value of a logical expression.
IFN evaluates the first argument, then logical-expression. If logical-expression is true
(that is, not zero and not missing), then IFN returns the value in the second argument.
If logical-expression is a missing value, and you have a fourth argument, then IFN
returns the value in the fourth argument. If logical-expression is false, IFN returns the
value in the third argument.
The IFN function, an IF/THEN/ELSE construct, or a WHERE statement can produce
the same results (see “Examples” on page 618). However, the IFN function is useful in
DATA step expressions when it is not convenient or possible to use an IF/THEN/ELSE
construct or a WHERE statement.
Comparisons
The IFN function is similar to the IFC function, except that IFN returns a numeric
value whereas IFC returns a character value.
Examples
Example 1: Calculating Sales Commission
The following examples show how to
calculate sales commission using the IFN function, an IF/THEN/ELSE construct, and a
Functions and CALL Routines
4
IFN Function
619
WHERE statement. In each of the examples, the commission that is calculated is the
same.
Calculating Commission Using the IFN Function
In the following example, IFN
evaluates the expression TotalSales > 10000. If total sales exceeds $10,000, then the
sales commission is 5% of the total sales. If total sales is less than $10,000, then the
sales commission is 2% of the total sales.
data _null_;
input TotalSales;
commission=ifn(TotalSales > 10000, TotalSales*.05, TotalSales*.02);
put commission=;
datalines;
25000
10000
500
10300
;
run;
SAS writes the following output to the log:
commission=1250
commission=200
commission=10
commission=515
Calculating Commission Using an IF/THEN/ELSE Construct
In the following example,
an IF/THEN/ELSE construct evaluates the expression TotalSales > 10000. If total
sales exceeds $10,000, then the sales commission is 5% of the total sales. If total sales
is less than $10,000, then the sales commission is 2% of the total sales.
data _null_;
input TotalSales;
if TotalSales > 10000 then commission = .05 * TotalSales;
else commission = .02 * TotalSales;
put commission=;
datalines;
25000
10000
500
10300
;
run;
SAS writes the following output to the log:
commission=1250
commission=200
commission=10
commission=515
620
INDEX Function
4
Chapter 4
Calculating Commission Using a WHERE Statement
In the following example, a
WHERE statement evaluates the expression TotalSales > 10000. If total sales
exceeds $10,000, then the sales commission is 5% of the total sales. If total sales is less
than $10,000, then the sales commission is 2% of the total sales. The output shows only
those salespeople whose total sales exceed $10,000.
options pageno=1 nodate ls=80 ps=64;
data sales;
input SalesPerson $ TotalSales;
datalines;
Michaels 25000
Janowski 10000
Chen 500
Gupta 10300
;
data commission;
set sales;
where TotalSales > 10000;
commission = TotalSales * .05;
run;
proc print data=commission;
title ’Commission for Total Sales > 1000’;
run;
Output 4.27
Output from a WHERE Statement
Commission for Total Sales > 1000
Obs
1
2
Sales
Person
Total
Sales
commission
Michaels
Gupta
25000
10300
1250
515
See Also
Functions:
“IFC Function” on page 616
INDEX Function
Searches a character expression for a string of characters
Category:
Character
1
Functions and CALL Routines
4
INDEXC Function
621
Syntax
INDEX(source,excerpt)
Arguments
source
specifies the character expression to search.
excerpt
specifies the string of characters to search for in the character expression.
Tip: Enclose a literal string of characters in quotation marks.
Details
The INDEX function searches source, from left to right, for the first occurrence of the
string specified in excerpt, and returns the position in source of the string’s first
character. If the string is not found in source, INDEX returns a value of 0. If there are
multiple occurrences of the string, INDEX returns only the position of the first
occurrence.
Examples
SAS Statements
Results
a=’ABC.DEF (X=Y)’;
b=’X=Y’;
x=index(a,b);
put x;
10
See Also
Functions:
“INDEXC Function” on page 621
“INDEXW Function” on page 622
INDEXC Function
Searches a character expression for specific characters
Category: Character
Syntax
INDEXC(source,excerpt-1< ,… excerpt-n>)
622
INDEXW Function
4
Chapter 4
Arguments
source
specifies the character expression to search.
excerpt
specifies the characters to search for in the character expression.
If you specify more than one excerpt, separate them with a comma.
Tip:
Details
The INDEXC function searches source, from left to right, for the first occurrence of any
character present in the excerpts and returns the position in source of that character. If
none of the characters in excerpt-1 through excerpt-n in source are found, INDEXC
returns a value of 0.
Comparisons
The INDEXC function searches for the first occurrence of any individual character that
is present within the character string, whereas the INDEX function searches for the
first occurrence of the character string as a pattern.
Examples
SAS Statements
Results
a=’ABC.DEP (X2=Y1)’;
x=indexc(a,’0123’,’;()=.’);
put x;
4
b=’have a good day’;
x=indexc(b,’pleasant’,’very’);
put x;
2
See Also
Functions:
“INDEX Function” on page 620
“INDEXW Function” on page 622
INDEXW Function
Searches a character expression for a specified string as a word
Category:
Character
Functions and CALL Routines
4
INDEXW Function
623
Syntax
INDEXW(source, excerpt<,delimiter>)
Arguments
source
specifies the character expression to search.
excerpt
specifies the string of characters to search for in the character expression. SAS
removes the leading and trailing delimiters from excerpt.
delimiter
specifies a character expression that you want INDEXW to use as a word separator
in the character string. The default delimiter is the blank character.
Details
The INDEXW function searches source, from left to right, for the first occurrence of
excerpt and returns the position in source of the substring’s first character. If the
substring is not found in source, then INDEXW returns a value of 0. If there are
multiple occurrences of the string, then INDEXW returns only the position of the first
occurrence.
The substring pattern must begin and end on a word boundary. For INDEXW, word
boundaries are delimiters, the beginning of source, and the end of source.
INDEXW has the following behavior when the second argument contains blank
spaces or has a length of 0:
3 If both source and excerpt contain only blank spaces or have a length of 0, then
INDEXW returns a value of 1.
3 If excerpt contains only blank spaces or has a length of 0, and source contains
character or numeric data, then INDEXW returns a value of 0.
Comparisons
The INDEXW function searches for strings that are words, whereas the INDEX
function searches for patterns as separate words or as parts of other words. INDEXC
searches for any characters that are present in the excerpts.
Examples
The following SAS statements give these results.
SAS Statements
Results
s=’asdf adog dog’;
p=’dog ’;
x=indexw(s,p);
put x;
11
s=’abcdef x=y’;
p=’def’;
x=indexw(s,p);
put x;
0
624
INPUT Function
4
Chapter 4
SAS Statements
Results
x="abc,[email protected] xyz";
abc=indexw(x, " abc ", "@");
put abc;
0
x="abc,[email protected] xyz";
comma=indexw(x, ",", "@");
put comma;
0
x="abc,def% xyz";
def=indexw(x, "def", "%");
put def;
5
x="abc,[email protected] xyz";
at=indexw(x, "@", "@");
put at;
0
x="abc,[email protected] xyz";
xyz=indexw(x, " xyz", "@");
put xyz;
9
c=indexw(trimn(’ ’), ’
g=indexw(’
x
y
’);
1
’, trimn(’ ’));
0
See Also
Functions:
“INDEX Function” on page 620
“INDEXC Function” on page 621
INPUT Function
Returns the value produced when a SAS expression that uses a specified informat expression is
read
Category:
Special
Syntax
INPUT(source, <? | ??>informat.)
Arguments
source
contains the SAS character expression to which you want to apply a specific informat.
? or ??
The optional question mark (?) and double question mark (??) format modifiers
suppress the printing of both the error messages and the input lines when invalid
Functions and CALL Routines
4
INPUT Function
625
data values are read. The ? modifier suppresses the invalid data message. The ??
modifier also suppresses the invalid data message and, in addition, prevents the
automatic variable _ERROR_ from being set to 1 when invalid data are read.
informat.
is the SAS informat that you want to apply to the source.
Details
If the INPUT function returns a value to a variable that has not yet been assigned a
length, by default the variable length is determined by the width of the informat.
The INPUT function enables you to read the value of source by using a specified
informat. The informat determines whether the result is numeric or character. Use
INPUT to convert character values to numeric values.
Comparisons
The INPUT function returns the value produced when a SAS expression is read using a
specified informat. You must use an assignment statement to store that value in a
variable. The INPUT statement uses an informat to read a data value and then
optionally stores that value in a variable.
Examples
Example 1: Converting Character Values to Numeric Values
This example uses the
INPUT function to convert a character value to a numeric value and store it in another
variable. The COMMA9. informat reads the value of the SALE variable, stripping the
commas. The resulting value, 2115353, is stored in FMTSALE.
data testin;
input sale $9.;
fmtsale=input(sale,comma9.);
datalines;
2,115,353
;
Example 2: Using PUT and INPUT Functions
In this example, PUT returns a numeric
value as a character string. The value 122591 is assigned to the CHARDATE variable.
INPUT returns the value of the character string as a SAS date value using a SAS date
informat. The value 11681 is stored in the SASDATE variable.
numdate=122591;
chardate=put(numdate,z6.);
sasdate=input(chardate,mmddyy6.);
Example 3: Suppressing Error Messages
In this example, the question mark (?) format
modifier tells SAS not to print the invalid data error message if it finds data errors. The
automatic variable _ERROR_ is set to 1 and input data lines are written to the SAS log.
y=input(x,? 3.1);
Because the double question mark (??) format modifier suppresses printing of error
messages and input lines and prevents the automatic variable _ERROR_ from being set
to 1 when invalid data are read, the following two examples produce the same result:
3 y=input(x,?? 2.);
3 y=input(x,? 2.); _error_=0;
626
INPUTC Function
4
Chapter 4
See Also
Functions:
“INPUTC Function” on page 626
“INPUTN Function” on page 628
“PUT Function” on page 803
“PUTC Function” on page 805
“PUTN Function” on page 807
Statements:
“INPUT Statement” on page 1342
INPUTC Function
Enables you to specify a character informat at run time
Category:
Special
Syntax
INPUTC(source, informat.< ,w>)
Arguments
source
is the SAS expression to which you want to apply the informat.
informat.
is an expression that contains the character informat you want to apply to source.
w
specifies a width to apply to the informat.
Interaction: If you specify a width here, it overrides any width specification in the
informat.
Details
If the INPUTC function returns a value to a variable that has not yet been assigned a
length, by default the variable length is determined by the length of the first argument.
Comparisons
The INPUTN function enables you to specify a numeric informat at run time.
Examples
Example 1: Specifying Character Informats
The PROC FORMAT step in this example
creates a format, TYPEFMT., that formats the variable values 1, 2, and 3 with the
Functions and CALL Routines
4
INPUTC Function
627
name of one of the three informats that this step also creates. The informats store
responses of "positive," "negative," and "neutral" as different words, depending on the
type of question. After PROC FORMAT creates the format and informats, the DATA
step creates a SAS data set from raw data consisting of a number identifying the type
of question and a response. After reading a record, the DATA step uses the value of
TYPE to create a variable, RESPINF, that contains the value of the appropriate
informat for the current type of question. The DATA step also creates another variable,
WORD, whose value is the appropriate word for a response. The INPUTC function
assigns the value of WORD based on the type of question and the appropriate informat.
proc format;
value typefmt 1=’$groupx’
2=’$groupy’
3=’$groupz’;
invalue $groupx ’positive’=’agree’
’negative’=’disagree’
’neutral’=’notsure’;
invalue $groupy ’positive’=’accept’
’negative’=’reject’
’neutral’=’possible’;
invalue $groupz ’positive’=’pass’
’negative’=’fail’
’neutral’=’retest’;
run;
data answers;
input type response $;
respinformat = put(type, typefmt.);
word = inputc(response, respinformat);
datalines;
1 positive
1 negative
1 neutral
2 positive
2 negative
2 neutral
3 positive
3 negative
3 neutral
;
The value of WORD for the first observation is agree. The value of WORD for the last
observation is retest.
See Also
Functions:
“INPUT Function” on page 624
“INPUTN Function” on page 628
“PUT Function” on page 803
“PUTC Function” on page 805
“PUTN Function” on page 807
628
INPUTN Function
4
Chapter 4
INPUTN Function
Enables you to specify a numeric informat at run time
Category:
Special
Syntax
INPUTN(source, informat.< ,w< ,d>>)
Arguments
source
is the SAS expression to which you want to apply the informat.
informat.
is an expression that contains the numeric informat you want to apply to source.
w
specifies a width to apply to the informat.
Interaction: If you specify a width here, it overrides any width specification in the
informat.
d
specifies the number of decimal places to use.
Interaction: If you specify a number here, it overrides any decimal-place
specification in the informat.
Comparisons
The INPUTC function enables you to specify a character informat at run time.
Examples
Example 1: Specifying Numeric Informats
The PROC FORMAT step in this example
creates a format, READDATE., that formats the variable values 1 and 2 with the name
of a SAS date informat. The DATA step creates a SAS data set from raw data originally
from two different sources (indicated by the value of the variable SOURCE). Each
source specified dates differently. After reading a record, the DATA step uses the value
of SOURCE to create a variable, DATEINF, that contains the value of the appropriate
informat for reading the date. The DATA step also creates a new variable, NEWDATE,
whose value is a SAS date. The INPUTN function assigns the value of NEWDATE
based on the source of the observation and the appropriate informat.
proc format;
value readdate 1=’date7.’
2=’mmddyy8.’;
run;
options yearcutoff=1920;
data fixdates (drop=start dateinformat);
Functions and CALL Routines
1
1
2
2
;
4
INT Function
629
length jobdesc $12;
input source id lname $ jobdesc $ start $;
dateinformat=put(source, readdate.);
newdate = inputn(start, dateinformat);
datalines;
1604 Ziminski writer 09aug90
2010 Clavell editor 26jan95
1833 Rivera writer 10/25/92
2222 Barnes proofreader 3/26/98
See Also
Functions:
“INPUT Function” on page 624
“INPUTC Function” on page 626
“PUT Function” on page 803
“PUTC Function” on page 805
“PUTN Function” on page 807
INT Function
Returns the integer value, fuzzed to avoid unexpected floating-point results
Category: Truncation
Syntax
INT(argument)
Arguments
argument
is numeric.
Details
The INT function returns the integer portion of the argument (truncates the decimal
portion). If the argument’s value is within 1E-12 of an integer, the function results in
that integer. If the value of argument is positive, the INT function has the same result
as the FLOOR function. If the value of argument is negative, the INT function has the
same result as the CEIL function.
Comparisons
Unlike the INTZ function, the INT function fuzzes the result. If the argument is within
1E-12 of an integer, the INT function fuzzes the result to be equal to that integer. The
630
INTCK Function
4
Chapter 4
INTZ function does not fuzz the result. Therefore, with the INTZ function you might
get unexpected results.
Examples
The following SAS statements produce these results.
SAS Statements
Results
var1=2.1;
x=int(var1);
put x;
2
var2=-2.4;
y=int(var2);
put y;
-2
a=int(1+1.e-11);
put a;
1
b=int(-1.6);
put b;
-1
See Also
Functions:
“CEIL Function” on page 448
“FLOOR Function” on page 571
“INTZ Function” on page 640
INTCK Function
Returns the integer count of the number of interval boundaries between two dates, two times, or
two datetime values
Category:
Date and Time
Syntax
INTCK(interval, from, to)
Arguments
interval
specifies a character constant, a variable, or an expression that contains an interval
name. Interval can appear in uppercase or lowercase. The possible values of interval
are listed in the “Intervals Used with Date and Time Functions” table in SAS
Language Reference: Concepts.
Functions and CALL Routines
4
INTCK Function
631
The type of interval (date, datetime, or time) must match the type of
value in from.
Requirement:
Multipliers and shift indexes can be used with the basic interval names to
construct more complex interval specifications. The general form of an interval name
is as follows:
interval<n.s>
The three parts of the interval name are
interval
specifies the name of the basic interval type. For example, YEAR specifies
yearly intervals.
n
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.
See: “Details” on page 631 for more information.
s
specifies an optional shift index that shifts the interval to start at a specified
subperiod starting point. For example, YEAR.3 specifies yearly periods shifted
to start on the first of March of each calendar year and to end in February of
the following year.
Restriction: The shift index cannot be greater than the number of subperiods
in the whole interval. For example, you could use YEAR2.24, but YEAR2.25
would be an error because there is no twenty-fifth month in a two-year
interval.
Restriction: If the default shift period is the same as the interval type, then
only multiperiod intervals can be shifted with the optional shift index. For
example, MONTH type intervals shift by MONTH subperiods by default;
thus, monthly intervals cannot be shifted with the shift index. However,
bimonthly intervals can be shifted with the shift index, because there are two
MONTH intervals in each MONTH2 interval. The interval name MONTH2.2,
for example, specifies bimonthly periods starting on the first day of
even-numbered months.
See: “Details” on page 631 for more information.
from
specifies a SAS expression that represents the starting SAS date, time, or datetime
value.
to
specifies a SAS expression that represents the ending SAS date, time, or datetime
value.
Details
The INTCK function counts the number of times the beginning of an interval is reached
in moving from the from argument to the to argument. It does not count the number of
complete intervals between those two values. For example, WEEK intervals are
determined by the number of Sundays that occur between the from argument and the
to argument, not by how many seven-day periods fall in between the from argument
and the to argument.
632
INTCK Function
4
Chapter 4
Both the multiplier n and the shift index s are optional and default to 1. For
example, YEAR, YEAR1, YEAR.1, and YEAR1.1 are all equivalent ways of specifying
ordinary calendar years.
Intervals that do not nest within years or days are aligned relative to the SAS date
or datetime value 0. The arbitrary reference time of midnight on January 1, 1960, is
used as the origin for non-shifted intervals, and shifted intervals are defined relative to
that reference point.
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, and the convention of alignment relative to the period
containing January 1, 1960, tells where to start counting to find out what dates
correspond to the second Fridays of six-week intervals.
Table 4.3 Commonly Used Intervals with Optional Multiplier and Shift Indexes
Interval
Description
DAY3
Three-day intervals starting on Sunday
WEEK.7
Weekly with Saturday as the first day of the week
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
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 (with the cycle three-weekday intervals aligned
to Monday 4 Jan 1960)
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
Three-month intervals starting on April 1, July 1, October 1,
and January 1
SEMIYEAR.3
Six-month intervals, March-August and September-February
Functions and CALL Routines
4
INTCK Function
Interval
Description
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 AM, 2 PM, and 10 PM
(might be used for work shifts)
Examples
SAS Statements
Results
qtr=intck(’qtr’,’10jan95’d,’01jul95’d);
put qtr;
2
year=intck(’year’,’31dec94’d,
’01jan95’d);
put year;
1
year=intck(’year’,’01jan94’d,
’31dec94’d);
put year;
0
semi=intck(’semiyear’,’01jan95’d,
’01jan98’d);
put semi;
6
weekvar=intck(’week2.2’,’01jan97’d,
’31mar97’d);
put weekvar;
6
wdvar=intck(’weekday7w’,’01jan97’d,
’01feb97’d);
put wdvar;
26
y=’year’;
date1=’1sep1991’d;
date2=’1sep2001’d;
newyears=intck(y,date1,date2);
put newyears;
10
y=trim(’year
’);
date1=’1sep1991’d + 300;
date2=’1sep2001’d - 300;
newyears=intck(y,date1,date2);
put newyears;
8
In the second example, INTCK returns a value of 1 even though only one day has
elapsed. This is because the interval from December 31, 1994 to January 1, 1995
633
634
INTNX Function
4
Chapter 4
contains the starting point for the YEAR interval. In the third example, however, a
value of 0 is returned even though 364 days have elapsed. This is because the period
between January 1, 1994 and December 31, 1994 does not contain the starting point for
the interval.
In the fourth example, SAS returns a value of 6 because January 1, 1995 through
January 1, 1998 contains six semiyearly intervals. (Note that if the ending date were
December 31, 1997, SAS would count five intervals.) In the fifth example, SAS returns
a value of 6 because there are six two-week intervals beginning on a first Monday
during the period of January 1, 1997 through March 31, 1997. In the sixth example,
SAS returns the value 26. That indicates that beginning with January 1, 1997, and
counting only Saturdays as weekend days through February 1, 1997, the period
contains 26 weekdays.
In the seventh example, the use of variables for the arguments is illustrated. The
use of expressions for the arguments is illustrated in the last example.
See Also
Function:
“INTNX Function” on page 634
INTNX Function
Increments a date, time, or datetime value by a given interval or intervals, and returns a date,
time, or datetime value
Category:
Date and Time
Syntax
INTNX(interval<multiple>< .shift-index>, start-from, increment<,alignment>)
Arguments
interval
specifies a character constant, a variable, or an expression that contains a time
interval such as WEEK, SEMIYEAR, QTR, or HOUR.
Requirement: The type of interval (date, datetime, or time) must match the type of
value in start-from and increment.
See: Table 4.4 on page 636 for a list of commonly used time intervals.
multiple
specifies a multiple of the interval. It sets the interval equal to a multiple of the
interval type. For example, YEAR2 consists of two-year, or biennial, periods.
See: “Incrementing Dates and Times by Using Multipliers and by Shifting
Intervals” on page 636 for more information.
Functions and CALL Routines
4
INTNX Function
635
shift-index
specifies the starting point of the interval. By default, the starting point is 1. A value
that is greater than 1 shifts the start to a later point within the interval. The unit
for shifting depends on the interval. For example, YEAR.3 specifies yearly periods
that are shifted to start on the first of March of each calendar year and to end in
February of the following year.
Restriction: The shift index cannot be greater than the number of periods in the
entire interval. For example, YEAR2.24 has a valid shift index, but YEAR2.25 is
invalid because there is no twenty-fifth month in a two-year interval.
Restriction: If the default shift period is the same as the interval type, then you
can shift only multiperiod intervals with the shift index. For example, because
MONTH type intervals shift by MONTH subperiods by default, you cannot shift
monthly intervals with the shift index. However, you can shift bimonthly intervals
with the shift index, because two MONTH intervals exist in each MONTH2
interval. The interval name MONTH2.2, for example, specifies bimonthly periods
starting on the first day of even-numbered months.
See: “Incrementing Dates and Times by Using Multipliers and by Shifting
Intervals” on page 636 for more information.
start-from
specifies a SAS expression that represents a SAS date, time, or datetime value that
identifies a starting point.
increment
specifies a negative, positive, or zero integer that represents the number of date,
time, or datetime intervals. Increment is the number of intervals to shift the value of
start-from.
alignment
controls the position of SAS dates within the interval. Alignment can be one of these
values:
BEGINNING
specifies that the returned date is aligned to the beginning of the interval.
Alias: B
MIDDLE
specifies that the returned date is aligned to the midpoint of the interval.
Alias: M
END
specifies that the returned date is aligned to the end of the interval.
Alias: E
SAMEDAY
specifies that the date that is returned is aligned to the same calendar date with
the corresponding interval increment.
Alias: S
Alias: SAME
Default: BEGINNING
See: “Aligning SAS Date Output within Its Intervals” on page 637 for more
information.
Details
The Basics
The INTNX function increments a date, time, or datetime value by
intervals such as DAY, WEEK, QTR, and MINUTE. The increment is based on a
636
INTNX Function
4
Chapter 4
starting date, time, or datetime value, and on the number of time intervals that you
specify. The INTNX function returns the beginning date, time, or datetime value of the
interval that you specify in the start–from argument. For example, to determine the
date of the start of the week that is six weeks from the week of October 17, 2003, use
the following example:
intnx(’week’, ’17oct03’d, 6);
INTNX returns the value 23NOV2003.
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.
Understanding 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. The intervals December 1, 1958, November 1, 1957, October
1, 1956, and so on are dates that occurred before the base date of 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.4 Commonly Used Intervals with Optional Multiplier and Shift Indexes
Interval
Description
DAY3
Three-day intervals starting on Sundays
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
Functions and CALL Routines
4
INTNX Function
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 (with the cycle three-weekday intervals aligned
to Monday 4 Jan 1960)
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
Three-month intervals starting on April 1, July 1, October 1,
and January 1
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
637
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.
Aligning SAS Date Output within Its Intervals
SAS date values are normally aligned with the beginning of the time intervals that
correspond to the interval type in interval.
You can use the optional alignment argument to specify the alignment of the date
that is returned. The values BEGINNING, MIDDLE, or END align the date to the
beginning, middle, or end of the interval, respectively.
638
INTNX Function
4
Chapter 4
If you use the SAMEDAY value, then INTNX returns the same calendar date after
computing the interval increment that you specified. The function automatically adjusts
for the date if the date in the interval that is incremented does not exist. Here is an
example:
intnx(’month’, ’15mar2000’d, 5, ’sameday’);
intnx(’year’, ’29feb2000’d, 2, ’sameday’);
intnx(’month’, ’31aug2001’d, 1, ’sameday’);
returns 15AUG2000
returns 28FEB2002
returns 30SEP2001
BEGINNING is the default value for alignment.
Examples
The following examples show how to use the INTNX function.
SAS Statements
Results
yr=intnx(’year’,’05feb94’d,3);
put yr / yr date7.;
13515
01JAN97
x=intnx(’month’,’05jan95’d,0);
put x / x date7.;
12784
01JAN95
next=intnx(’semiyear’,’01jan97’d,1);
put next / next date7.;
13696
01JUL97
past=intnx(’month2’,’01aug96’d,-1);
put past / past date7.;
13270
01MAY96
sm=intnx(’semimonth2.2’,’01apr97’d,4);
put sm / sm date7.;
13711
16JUL97
x=’month’;
date=’1jun1990’d;
nextmon=intnx(x,date,1);
put nextmon / nextmon date7.;
11139
01JUL90
x1=’month
’;
x2=trim(x1);
date=’1jun1990’d - 100;
nextmonth=intnx(x2,date,1);
put nextmonth / nextmonth date7.;
11017
01MAR90
The following examples show the results of advancing a date by using the optional
alignment argument.
SAS Statements
Results
date1=intnx(’month’,’01jan95’d,5,’beginning’);
put date1 / date1 date7.;
12935
01JUN95
date2=intnx(’month’,’01jan95’d,5,’middle’);
put date2 / date2 date7.;
12949
15JUN95
date3=intnx(’month’,’01jan95’d,5,’end’);
put date3 / date3 date7.;
12964
30JUN95
date4=intnx(’month’,’01jan95’d,5,’sameday’);
put date4 / date4 date7.;
12935
01JUN95
Functions and CALL Routines
4
INTRR Function
SAS Statements
Results
date5=intnx(’month’,’15mar2000’d,5,’same’);
put date5 / date5 date9.;
14837
15AUG2000
interval=’month’;
date=’1sep2001’d;
align=’m’;
date4=intnx(interval,date,2,align);
put date4 / date4 date7.;
15294
15NOV01
x1=’month
’;
x2=trim(x1);
date=’1sep2001’d + 90;
date5=intnx(x2,date,2,’m’);
put date5 / date5 date7.;
15356
16JAN02
639
See Also
Function:
“INTCK Function” on page 630
INTRR Function
Returns the internal rate of return as a fraction
Category: Financial
Syntax
INTRR(freq,c0, c1, ..., cn)
Arguments
freq
is numeric, the number of payments over a specified base period of time that is
associated with the desired internal rate of return.
Range: freq > 0
Exception:
The case freq = 0 is a flag to allow continuous compounding.
c0,c1, ... ,cn
are numeric, the optional cash payments.
Details
The INTRR function returns the internal rate of return over a specified base period of
time for the set of cash payments c0, c1, ..., cn. The time intervals between any two
640
INTZ Function
4
Chapter 4
consecutive payments are assumed to be equal. The argument freq>0 describes the
number of payments that occur over the specified base period of time.
The internal rate of return is the interest rate such that the sequence of payments
has a 0 net present value (see the NETPV function). It is given by
r
1
= 0x log (x)
e
f req
f req > 0
f req = 0
where x is the real root, nearest to 1, of the polynomial
n
X
=0
ci x i = 0
i
The routine uses Newton’s method to look for the internal rate of return nearest to 0.
Depending on the value of payments, a root for the equation does not always exist; in
that case, a missing value is returned.
Missing values in the payments are treated as 0 values. When freq>0, the computed
rate of return is the effective rate over the specified base period. To compute a quarterly
internal rate of return (the base period is three months) with monthly payments, set
freq to 3.
If freq is 0, continuous compounding is assumed and the base period is the time
interval between two consecutive payments. The computed internal rate of return is the
nominal rate of return over the base period. To compute with continuous compounding
and monthly payments, set freq to 0. The computed internal rate of return will be a
monthly rate.
Examples
For an initial outlay of $400 and expected payments of $100, $200, and $300 over the
following three years, the annual internal rate of return can be expressed as
rate=intrr(1,-400,100,200,300);
The value returned is 0.19438.
INTZ Function
Returns the integer portion of the argument, using zero fuzzing
Category:
Truncation
Syntax
INTZ (argument)
Functions and CALL Routines
4
INTZ Function
641
Arguments
argument
is a numeric constant, variable, or expression.
Details
The following rules apply:
3 If the value of the argument is an exact integer, INTZ returns that integer.
3 If the argument is positive and not an integer, INTZ returns the largest integer
that is less than the argument.
3 If the argument is negative and not an integer, INTZ returns the smallest integer
that is greater than the argument.
Comparisons
Unlike the INT function, the INTZ function uses zero fuzzing. If the argument is within
1E-12 of an integer, the INT function fuzzes the result to be equal to that integer. The
INTZ function does not fuzz the result. Therefore, with the INTZ function you might
get unexpected results.
Examples
The following SAS statements produce these results.
SAS Statements
Results
var1=2.1;
a=intz(var1);
put a;
2
var2=-2.4;
b=intz(var2);
put b;
-2
var3=1+1.e-11;
c=intz(var3);
put c;
1
f=intz(-1.6);
put f;
-1
642
IORCMSG Function
4
Chapter 4
See Also
Functions:
“CEIL Function” on page 448
“CEILZ Function” on page 449
“FLOOR Function” on page 571
“FLOORZ Function” on page 572
“INT Function” on page 629
“ROUND Function” on page 845
“ROUNDZ Function” on page 855
IORCMSG Function
Returns a formatted error message for _IORC_
Category:
SAS File I/O
Syntax
character-variable=IORCMSG()
Arguments
character-variable
specifies a character variable.
If the length has been previously defined, then the result will be truncated or
padded as needed.
Tip:
Default: The default length is 200 characters.
Details
If the IORCMSG function returns a value to a variable that has not yet been assigned a
length, then by default the variable is assigned a length of 200.
The IORCMSG function returns the formatted error message that is associated with
the current value of the automatic variable _IORC_. The _IORC_ variable is created
when you use the MODIFY statement, or when you use the SET statement with the
KEY= option. The value of the _IORC_ variable is internal and is meant to be read in
conjunction with the SYSRC autocall macro. If you try to set _IORC_ to a specific value,
you might get unexpected results.
Functions and CALL Routines
4
IORCMSG Function
643
Examples
In the following program, observations are either rewritten or added to the updated
master file that contains bank accounts and current bank balance. The program queries
the _IORC_ variable and returns a formatted error message if the _IORC_ value is
unexpected.
libname bank ’SAS-data-library’;
data bank.master(index=(AccountNum));
infile ’external-file-1’;
format balance dollar8.;
input @ 1 AccountNum $ 1--3 @ 5 balance 5--9;
run;
data bank.trans(index=(AccountNum));
infile ’external-file-2’;
format deposit dollar8.;
input @ 1 AccountNum $ 1--3 @ 5 deposit 5--9;
run;
data bank.master;
set bank.trans;
modify bank.master key=AccountNum;
if (_IORC_ EQ %sysrc(_SOK)) then
do;
balance=balance+deposit;
replace;
end;
else
if (_IORC_ = %sysrc(_DSENOM)) then
do;
balance=deposit;
output;
_error_=0;
end;
else
do;
errmsg=IORCMSG();
put ’Unknown error condition:’
errmsg;
end;
run;
644
IQR Function
4
Chapter 4
IQR Function
Returns the interquartile range
Descriptive Statistics
Category:
Syntax
IQR(value-1 <, value-2...>)
Arguments
value
specifies a numeric constant, variable, or expression of which the interquartile range
is to be computed.
Details
If all arguments have missing values, the result is a missing value. Otherwise, the
result is the interquartile range of the non-missing values. The formula for the
interquartile range is the same as the one that is used in the UNIVARIATE procedure.
For more information, see Base SAS Procedures Guide.
Examples
SAS Statements
iqr=iqr(2,4,1,3,999999);
put iqr;
See Also
Functions:
“MAD Function” on page 678
“PCTL Function” on page 736
Results
2
Functions and CALL Routines
4
JBESSEL Function
645
IRR Function
Returns the internal rate of return as a percentage
Category: Financial
Syntax
IRR(freq,c0,cl,...,cn)
Arguments
freq
is numeric, the number of payments over a specified base period of time that is
associated with the desired internal rate of return.
Range: freq > 0.
Exception:
The case freq = 0 is a flag to allow continuous compounding.
c0,c1,...,cn
are numeric, the optional cash payments.
Comparisons
The IRR function is identical to INTRR, except that the rate returned is a percentage.
JBESSEL Function
Returns the value of the bessel function
Category: Mathematical
Syntax
JBESSEL(nu,x)
Arguments
nu
is numeric.
Range: nu ≥ 0
646
JULDATE Function
4
Chapter 4
x
is numeric.
Range:
x≥0
Details
The JBESSEL function returns the value of the bessel function of order nu evaluated at
x (For more information, see Abramowitz and Stegun 1964; Amos, Daniel, and Weston
1977).
Examples
SAS Statements
Results
x=jbessel(2,2);
0.3528340286
JULDATE Function
Returns the Julian date from a SAS date value
Category:
Date and Time
Syntax
JULDATE(date)
Arguments
date
specifies a SAS date value.
Functions and CALL Routines
4
JULDATE7 Function
647
Details
The JULDATE function converts a SAS date value to a five- or seven-digit Julian date.
If date falls within the 100-year span defined by the system option YEARCUTOFF=,
the result has five digits: the first two digits represent the year, and the next three
digits represent the day of the year (1 to 365, or 1 to 366 for leap years). Otherwise, the
result has seven digits: the first four digits represent the year, and the next three digits
represent the day of the year. For example, if YEARCUTOFF=1920, JULDATE would
return 97001 for January 1, 1997, and return 1878365 for December 31, 1878.
Comparisons
The function JULDATE7 is similar to JULDATE except that JULDATE7 always
returns a four digit year. Thus JULDATE7 is year 2000 compliant because it eliminates
the need to consider the implications of a two digit year.
Examples
The following SAS statements produce these results:
SAS Statements
Results
julian=juldate(’31dec99’d);
99365
julian=juldate(’01jan2099’d);
2099001
See Also
Function:
“DATEJUL Function” on page 501
“JULDATE7 Function” on page 647
System Option:
“YEARCUTOFF= System Option” on page 1760
JULDATE7 Function
Returns a seven-digit Julian date from a SAS date value
Category: Date and Time
Syntax
JULDATE7(date)
648
KCOMPARE Function
4
Chapter 4
Arguments
date
specifies a SAS date value.
Details
The JULDATE7 function returns a seven digit Julian date from a SAS date value. The
first four digits represent the year, and the next three digits represent the day of the
year.
Comparisons
The function JULDATE7 is similar to JULDATE except that JULDATE7 always
returns a four digit year. Thus JULDATE7 is year 2000 compliant because it eliminates
the need to consider the implications of a two digit year.
Examples
The following SAS statements produce these results:
SAS Statements
Results
julian=juldate7(’31dec96’d);
1996366
julian=juldate7(’01jan2099’d);
2099001
See Also
Function:
“JULDATE Function” on page 646
KCOMPARE Function
Returns the result of a comparison of character strings
DBCS
See: The KCOMPARE function in SAS National Language Support (NLS): User’s Guide
Category:
Functions and CALL Routines
4
KINDEX Function
KCOMPRESS Function
Removes specific characters from a character string
Category: DBCS
The KCOMPRESS function in SAS National Language Support (NLS): User’s
Guide
See:
KCOUNT Function
Returns the number of double-byte characters in a string
Category: DBCS
See:
The KCOUNT function in SAS National Language Support (NLS): User’s Guide
KCVT Function
Converts data from an encoding code to another encoding code
Category: DBCS
See:
The KCVT function in SAS National Language Support (NLS): User’s Guide
KINDEX Function
Searches a character expression for a string of characters
Category: DBCS
See:
The KINDEX function in SAS National Language Support (NLS): User’s Guide
649
650
KINDEXC Function
4
Chapter 4
KINDEXC Function
Searches a character expression for specific characters
DBCS
See: The KINDEXC function in SAS National Language Support (NLS): User’s Guide
Category:
KLEFT Function
Left aligns a character expression by removing unnecessary leading DBCS blanks and SO/SI
Category:
See:
DBCS
The KLEFT function in SAS National Language Support (NLS): User’s Guide
KLENGTH Function
Returns the length of an argument
DBCS
The KLENGTH function in SAS National Language Support (NLS): User’s Guide
Category:
See:
KLOWCASE Function
Converts all letters in an argument to lowercase
DBCS
See: The KLOWCASE in SAS National Language Support (NLS): User’s Guide
Category:
Functions and CALL Routines
4
KSTRCAT Function
651
KREVERSE Function
Reverses a character expression
Category: DBCS
See:
The KREVERSE in SAS National Language Support (NLS): User’s Guide
KRIGHT Function
Right aligns a character expression by trimming trailing DBCS blanks and SO/SI
Category: DBCS
See:
The KRIGHT function in SAS National Language Support (NLS): User’s Guide
KSCAN Function
Selects a specific word from a character expression
Category: DBCS
See:
The KSCAN function in SAS National Language Support (NLS): User’s Guide
KSTRCAT Function
Concatenates two or more character strings
Category: DBCS
See:
The KSTRCAT function in SAS National Language Support (NLS): User’s Guide
652
KSUBSTR Function
4
Chapter 4
KSUBSTR Function
Extracts a substring from an argument
DBCS
See: The KSUBSTR function in SAS National Language Support (NLS): User’s Guide
Category:
KSUBSTRB Function
Extracts a substring from an argument according to the byte position of the substring in the
argument
Category:
See:
DBCS
The KSUBSTRB function in SAS National Language Support (NLS): User’s Guide
KTRANSLATE Function
Replaces specific characters in a character expression
DBCS
The KTRANSLATE function in SAS National Language Support (NLS): User’s
Guide
Category:
See:
KTRIM Function
Removes trailing DBCS blanks and SO/SI from character expressions
Category:
See:
DBCS
The KTRIM function in SAS National Language Support (NLS): User’s Guide
Functions and CALL Routines
4
KUPDATEB Function
653
KTRUNCATE Function
Truncates a numeric value to a specified length
Category: DBCS
See: The KTRUNCATE function in SAS National Language Support (NLS): User’s
Guide
KUPCASE Function
Converts all single-byte letters in an argument to uppercase
Category: DBCS
See:
The KUPCASE function in SAS National Language Support (NLS): User’s Guide
KUPDATE Function
Inserts, deletes, and replaces character value contents
Category: DBCS
See:
The KUPDATE function in SAS National Language Support (NLS): User’s Guide
KUPDATEB Function
Inserts, deletes, and replaces the contents of the character value according to the byte position of
the character value in the argument
Category: DBCS
See:
The KUPDATEB function in SAS National Language Support (NLS): User’s Guide
654
KURTOSIS Function
4
Chapter 4
KURTOSIS Function
Returns the kurtosis
Category:
Descriptive Statistics
Syntax
KURTOSIS(argument,argument, ...)
Arguments
argument
is numeric. At least four nonmissing arguments are required. Otherwise, the
function returns a missing value. The argument list can consist of a variable list,
which is preceded by OF.
Examples
SAS Statements
Results
x1=kurtosis(5,9,3,6);
0.928
x2=kurtosis(5,8,9,6,.);
-3.3
x3=kurtosis(8,9,6,1);
1.5
x4=kurtosis(8,1,6,1);
-4.483379501
x5=kurtosis(of x1-x4);
-5.065692754
KVERIFY Function
Returns the position of the first character that is unique to an expression
DBCS
The KVERIFY function in SAS National Language Support (NLS): User’s Guide
Category:
See:
Functions and CALL Routines
4
LAG Function
655
LAG Function
Returns values from a queue
Category: Special
Syntax
LAG< n>(argument)
Arguments
n
specifies the number of lagged values.
argument
is numeric or character.
Details
If the LAG function returns a value to a variable that has not yet been assigned a
length, by default the variable is assigned a length of 200.
The LAG functions, LAG1, LAG2, ..., LAG100 return values from a queue. LAG1 can
also be written as LAG. A LAGn function stores a value in a queue and returns a value
stored previously in that queue. Each occurrence of a LAGn function in a program
generates its own queue of values.
The queue for LAGn is initialized with n missing values, where n is the length of the
queue (for example, a LAG2 queue is initialized with two missing values). When LAGn
is executed, the value at the top of the queue is removed and returned, the remaining
values are shifted upwards, and the new value of the argument is placed at the bottom
of the queue. Hence, missing values are returned for the first n executions of LAGn,
after which the lagged values of the argument begin to appear.
Note: Storing values at the bottom of the queue and returning values from the top
of the queue occurs only when the function is executed. A LAGn function that is
executed conditionally will store and return values only from the observations for which
the condition is satisfied. See Example 2 on page 657. 4
If the argument of LAGn is an array name, a separate queue is maintained for each
variable in the array.
656
LAG Function
4
Chapter 4
Examples
Example 1: Creating a Data Set
The following program creates a data set that
contains the values for X, Y, and Z.
options pagesize=25 linesize=64 nodate pageno=1;
data one;
input X @@;
Y=lag1(x);
Z=lag2(x);
datalines;
1 2 3 4 5 6
;
proc print;
title ’Lag Output’;
run;
Lag Output
1
Obs
X
Y
Z
1
2
3
4
5
6
1
2
3
4
5
6
.
1
2
3
4
5
.
.
1
2
3
4
LAG1 returns one missing value and the values of X (lagged once). LAG2 returns
two missing values and the values of X (lagged twice).
Functions and CALL Routines
Example 2: Storing Every Other Lagged Value
4
LAG Function
657
This example shows the difference in
output when you use conditional and unconditional logic in your program. Because the
LAG function stores values on the queue only when it is called, you must call LAG
unconditionally to get the correct answers.
options pagesize=25 linesize=64 nodate pageno=1;
title ’Store Every Other Lagged Value’;
data test;
input x @@;
if mod(x,2)=0 then a=lag(x);
b=lag(x);
if mod(x,2)=0 then c=b;
label a=’(WRONG) a’ c=’(RIGHT) c’;
datalines;
1 2 3 4 5 6 7 8
;
proc print label data=test;
run;
Store Every Other Lagged Value
Obs
x
(WRONG)
a
b
(RIGHT)
c
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
.
.
.
2
.
4
.
6
.
1
2
3
4
5
6
7
.
1
.
3
.
5
.
7
See Also
Function:
“DIF Function” on page 520
1
658
LARGEST Function
4
Chapter 4
LARGEST Function
Returns the kth largest non-missing value
Category:
Descriptive Statistics
Syntax
LARGEST (k, value-1<, value-2 ...>)
Arguments
k
is a numeric constant, variable, or expression that specifies which value to return.
value
specifies the value of a numeric constant, variable, or expression to be processed.
Details
If k is missing, less than zero, or greater than the number of values, the result is a
missing value and _ERROR_ is set to 1. Otherwise, if k is greater than the number of
non-missing values, the result is a missing value but _ERROR_ is not set to 1.
Examples
The following SAS statements produce these results.
SAS Statements
Results
k=1;
largest1=largest(k, 456, 789, .Q, 123);
put largest1;
789
k=2;
largest2=largest(k, 456, 789, .Q, 123);
put largest2;
456
k=3;
largest3=largest(k, 456, 789, .Q, 123);
put largest3;
123
k=4;
largest4=largest(k, 456, 789, .Q, 123);
put largest4;
.
Functions and CALL Routines
4
LBOUND Function
659
See Also
Functions:
“ORDINAL Function” on page 734
“PCTL Function” on page 736
“SMALLEST Function” on page 886
LBOUND Function
Returns the lower bound of an array
Category: Array
Syntax
LBOUND< n>(array-name)
LBOUND(array-name,bound-n)
Arguments
n
specifies the dimension for which you want to know the lower bound. If no n value is
specified, the LBOUND function returns the lower bound of the first dimension of the
array.
array-name
specifies the name of an array defined previously in the same DATA step.
bound-n
specifies the dimension for which you want to know the lower bound. Use bound-n
only if n is not specified.
Details
The LBOUND function returns the lower bound of a one-dimensional array or the lower
bound of a specified dimension of a multidimensional array. Use LBOUND in array
processing to avoid changing the lower bound of an iterative DO group each time you
change the bounds of the array. LBOUND and HBOUND can be used together to
return the values of the lower and upper bounds of an array dimension.
660
LBOUND Function
4
Chapter 4
Examples
Example 1: One-dimensional Array
In this example, LBOUND returns the lower
bound of the dimension, a value of 2. SAS repeats the statements in the DO loop five
times.
array big{2:6} weight sex height state city;
do i=lbound(big) to hbound(big);
...more SAS statements...;
end;
Example 2: Multidimensional Array
This example shows two ways of specifying the
LBOUND function for multidimensional arrays. Both methods return the same value
for LBOUND, as shown in the table that follows the SAS code example.
array mult{2:6,4:13,2} mult1-mult100;
Syntax
Alternative Syntax
Value
LBOUND(MULT)
LBOUND(MULT,1)
2
LBOUND2(MULT)
LBOUND(MULT,2)
4
LBOUND3(MULT)
LBOUND(MULT,3)
1
See Also
Functions:
“DIM Function” on page 523
“HBOUND Function” on page 608
Functions and CALL Routines
4
LEFT Function
661
Statements:
“ARRAY Statement” on page 1187
“Array Reference Statement” on page 1191
“Array Processing” in SAS Language Reference: Concepts
LEFT Function
Left aligns a SAS character expression
Category: Character
Syntax
LEFT(argument)
Arguments
argument
specifies any SAS character expression.
Details
If the LEFT function returns a value to a variable that has not yet been assigned a
length, by default the variable length is determined by the length of the first argument.
LEFT returns an argument with leading blanks moved to the end of the value. The
argument’s length does not change.
662
LENGTH Function
4
Chapter 4
Examples
SAS Statements
Results
----+----1----+
a=’ DUE DATE’;
b=left(a);
put b;
DUE DATE
See Also
Functions:
“COMPRESS Function” on page 476
“RIGHT Function” on page 843
“TRIM Function” on page 931
LENGTH Function
Returns the length of a non-blank character string, excluding trailing blanks, and returns 1 for a
blank character string
Category:
Character
Syntax
LENGTH(string)
Arguments
string
specifies a character constant, variable, or expression.
Details
The LENGTH function returns an integer that represents the position of the rightmost
non-blank character in string. If the value of string is blank or missing, LENGTH
returns a value of 1. If string is a numeric variable (either initialized or uninitialized),
LENGTH returns a value of 12 and prints a note in the SAS log that the numeric
values have been converted to character values.
Comparisons
3 The LENGTH and LENGTHN functions return the same value for non-blank
character strings. LENGTH returns a value of 1 for blank character strings,
whereas LENGTHN returns a value of 0.
Functions and CALL Routines
4
LENGTHC Function
663
3 The LENGTH function returns the length of a character string, excluding trailing
blanks, whereas the LENGTHC function returns the length of a character string,
including trailing blanks. LENGTH always returns a value that is less than or
equal to the value returned by LENGTHC.
3 The LENGTH function returns the length of a character string, excluding trailing
blanks, whereas the LENGTHM function returns the amount of memory in bytes
that is allocated for a character string. LENGTH always returns a value that is
less than or equal to the value returned by LENGTHM.
Examples
SAS Statements
Results
len=length(’ABCDEF’);
put len;
6
len2=length(’ ’);
put len2;
1
See Also
Functions:
“LENGTHC Function” on page 663
“LENGTHM Function” on page 664
“LENGTHN Function” on page 666
LENGTHC Function
Returns the length of a character string, including trailing blanks
Category: Character
Syntax
LENGTHC(string)
Arguments
string
specifies a character constant, variable, or expression.
Details
The LENGTHC function returns an integer that represents the position of the rightmost
blank or non-blank character in string. If the value of string is missing and contains
664
LENGTHM Function
4
Chapter 4
blanks, LENGTHC returns the number of blanks in string. If the value of string is
missing and contains no blanks, LENGTHC returns a value of 0. If string is a numeric
variable (either initialized or uninitialized), LENGTHC returns a value of 12 and prints
a note in the SAS log that the numeric values have been converted to character values.
Comparisons
3 The LENGTHC function returns the length of a character string, including
trailing blanks, whereas the LENGTH and LENGTHN functions return the length
of a character string, excluding trailing blanks. LENGTHC always returns a value
that is greater than or equal to the values returned by LENGTH and LENGTHN.
3 The LENGTHC function returns the length of a character string, including
trailing blanks, whereas the LENGTHM function returns the amount of memory
in bytes that is allocated for a character string. For fixed-length character strings,
LENGTHC and LENGTHM always return the same value. For varying-length
character strings, LENGTHC always returns a value that is less than or equal to
the value returned by LENGTHM.
Examples
The following SAS statements produce these results:
SAS Statements
Results
x=lengthc(’variable with trailing blanks
put x;
length fixed $35;
fixed=’variable with trailing blanks
x=lengthc(fixed);
put x;
’);
32
’;
35
See Also
Functions:
“LENGTH Function” on page 662
“LENGTHM Function” on page 664
“LENGTHN Function” on page 666
LENGTHM Function
Returns the amount of memory (in bytes) that is allocated for a character string
Category:
Character
Syntax
LENGTHM(string)
Functions and CALL Routines
4
LENGTHM Function
665
Arguments
string
specifies a character constant, variable, or expression.
Details
The LENGTHM function returns an integer that represents the amount of memory in
bytes that is allocated for string. If string is a numeric variable (either initialized or
uninitialized), LENGTHM returns a value of 12 and prints a note in the SAS log that
the numeric values have been converted to character values.
Comparisons
The LENGTHM function returns the amount of memory in bytes that is allocated for a
character string, whereas the LENGTH, LENGTHC, and LENGTHN functions return
the length of a character string. LENGTHM always returns a value that is greater
than or equal to the values returned by LENGTH, LENGTHC, and LENGTHN.
Examples
Example 1: Determining the Amount of Allocated Memory for a Variable with Trailing
Blanks This example determines the amount of memory (in bytes) that is allocated to
a variable with trailing blanks.
data _null_;
x=lengthm(’variable with trailing blanks
put x;
run;
’);
The following line is written to the SAS log:
32
Example 2: Determining the Amount of Allocated Memory for a Variable from an External
File
This example determines the amount of memory (in bytes) that is allocated to a
variable that is input into a SAS file from an external file.
data _null_;
file ’test.txt’;
put ’trailing blanks
run;
’;
data test;
infile ’test.txt’;
input;
x=lengthm(_infile_);
put x;
run;
The following line is written to the SAS log:
256
666
4
LENGTHN Function
Chapter 4
See Also
Functions:
“LENGTH Function” on page 662
“LENGTHC Function” on page 663
“LENGTHN Function” on page 666
LENGTHN Function
Returns the length of a non-blank character string, excluding trailing blanks, and returns 0 for a
blank character string
Category:
Character
Syntax
LENGTHN(string)
Arguments
string
specifies a character constant, variable, or expression.
Details
The LENGTHN function returns an integer that represents the position of the
rightmost non-blank character in string. If the value of string is blank or missing,
LENGTHN returns a value of 0. If string is a numeric variable (either initialized or
uninitialized), LENGTHN returns a value of 12 and prints a note in the SAS log that
the numeric values have been converted to character values.
Comparisons
3 The LENGTHN and LENGTH functions return the same value for non-blank
character strings. LENGTHN returns a value of 0 for blank character strings,
whereas LENGTH returns a value of 1.
3 The LENGTHN function returns the length of a character string, excluding
trailing blanks, whereas the LENGTHC function returns the length of a character
string, including trailing blanks. LENGTHN always returns a value that is less
than or equal to the value returned by LENGTHC.
3 The LENGTHN function returns the length of a character string, excluding
trailing blanks, whereas the LENGTHM function returns the amount of memory
in bytes that is allocated for a character string. LENGTHN always returns a value
that is less than or equal to the value returned by LENGTHM.
Functions and CALL Routines
Examples
SAS Statements
Results
len=lengthn(’ABCDEF’);
put len;
6
len2=lengthn(’ ’);
put len2;
0
See Also
Functions:
“LENGTH Function” on page 662
“LENGTHC Function” on page 663
“LENGTHM Function” on page 664
LGAMMA Function
Returns the natural logarithm of the Gamma function
Category: Mathematical
Syntax
LGAMMA(argument)
Arguments
argument
is numeric.
Range: must be positive.
Examples
SAS Statements
Results
x=lgamma(2);
0
x=lgamma(1.5);
-0.120782238
4
LGAMMA Function
667
668
4
LIBNAME Function
Chapter 4
LIBNAME Function
Assigns or deassigns a libref for a SAS data library
Category:
See:
SAS File I/O
LIBNAME Function in the documentation for your operating environment.
Syntax
LIBNAME(libref< ,SAS-data-library< ,engine<,options>>>)
Arguments
libref
specifies the libref that is assigned to a SAS data library.
SAS-data-library
specifies the physical name of the SAS data library that is associated with the libref.
Specify this name as required by the host operating environment.
engine
specifies the engine that is used to access SAS files opened in the data library. If you
are specifying a SAS/SHARE server, then the engine should be REMOTE.
options
names one or more options honored by the specified engine, delimited with blanks.
Details
If the LIBNAME function returns 0, then the function was successful. However, you
could receive a non-zero value, even if the function was successful. A non-zero value is
returned if an error, warning, or note is produced. To determine if the function was
successful, look through the SAS log and use the following guidelines:
3 If a warning or note was generated, then the function was successful.
3 If an error was generated, then the function was not successful.
Operating Environment Information:
Some systems allow a SAS-data-library value of
’’(with a space) to assign a libref to the current directory. The behavior of LIBNAME
when a single space is specified for SAS-data-library is host dependent.
If no value is provided for SAS-data-library or if SAS-data-library has a value of
"(with no space), LIBNAME disassociates the libref from the data library.
Under some operating environments, the user can assign librefs using system
commands outside the SAS session. 4
Functions and CALL Routines
4
LIBREF Function
669
Examples
Example 1: Assigning a Libref
This example attempts to assign the libref NEW to the SAS data library MYLIB. If
an error or warning occurs, the message is written to the SAS log. Note that in a macro
statement you do not enclose character strings in quotation marks.
%if (%sysfunc(libname(new,MYLIB))) %then
%put %sysfunc(sysmsg());
Example 2: Deassigning a Libref
This example deassigns the libref NEW that has been previously associated with the
data library MYLIB in the preceding example. If an error or warning occurs, the
message is written to the SAS log. Note that in a macro statement you do not enclose
character strings in quotation marks.
%if (libname(new)) %then
%put %sysfunc(sysmsg());
See Also
Function:
“LIBREF Function” on page 669
LIBREF Function
Verifies that a libref has been assigned
Category: SAS File I/O
See:
LIBREF Function in the documentation for your operating environment.
Syntax
LIBREF(libref)
670
LOG Function
4
Chapter 4
Arguments
libref
specifies the libref to be verified.
Details
LIBREF returns 0 if the operation was successful, ≠0 if it was not successful.
Examples
This example verifies a libref. If an error or warning occurs, the message is written
to the log. Under some operating environments, the user can assign librefs by using
system commands outside the SAS session.
%if (%sysfunc(libref(sashelp))) %then
%put %sysfunc(sysmsg());
See Also
Function:
“LIBNAME Function” on page 668
LOG Function
Returns the natural (base e) logarithm
Category:
Mathematical
Syntax
LOG(argument)
Functions and CALL Routines
Arguments
argument
is numeric.
Range: must be positive.
Examples
SAS Statements
Results
x=log(1.0);
0
x=log(10.0);
2.302585093
LOG10 Function
Returns the logarithm to the base 10
Category: Mathematical
Syntax
LOG10(argument)
Arguments
argument
is numeric.
Range: must be positive.
Examples
SAS Statements
Results
x=log10(1.0);
0
x=log10(10.0);
1
x=log10(100.0);
2
4
LOG10 Function
671
672
LOG2 Function
4
Chapter 4
LOG2 Function
Returns the logarithm to the base 2
Category:
Mathematical
Syntax
LOG2(argument)
Arguments
argument
is numeric.
Range:
must be positive.
Examples
SAS Statements
Results
x=log2(2.0);
1
x=log2(0.5);
-1
LOGBETA Function
Returns the logarithm of the beta function
Category:
Mathematical
Syntax
LOGBETA(a,b)
Arguments
a
is the first shape parameter, where a>0.
b
is the second shape parameter, where b>0.
Functions and CALL Routines
4
LOGCDF Function
673
Details
The LOGBETA function is mathematically given by the equation
log
( (a; b)) =
log
(0 (a)) + log (0 (b))
0
log
(0 (a + b))
where 0 (:) is the gamma function.
If the expression cannot be computed, LOGBETA returns a missing value.
Examples
SAS Statements
Results
LOGBETA(5,3);
-4.653960350
See Also
Function:
“BETA Function” on page 345
LOGCDF Function
Computes the logarithm of a left cumulative distribution function
Category: Probability
See:
“CDF Function” on page 434
Syntax
LOGCDF(’dist’,quantile< ,parm-1,...,parm-k>)
Arguments
’dist’
is a character string that identifies the distribution. Valid distributions are as follows:
Distribution
Argument
Bernoulli
’BERNOULLI’
Beta
’BETA’
Binomial
’BINOMIAL’
674
LOGCDF Function
4
Chapter 4
Distribution
Argument
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’
Wald (inverse Gaussian)
’WALD’|’IGAUSS’
Weibull
’WEIBULL’
Note: Except for T, F, and NORMALMIX, you can minimally identify any
distribution by its first four characters. 4
quantile
is a numeric random variable.
parm-1,...,parm-k
are optional shape, location, or scale parameters appropriate for the specific
distribution.
The LOGCDF function computes the logarithm of a left cumulative distribution
function (logarithm of the left side) from various continuous and discrete distributions.
For more information, see the “CDF Function” on page 434.
Functions and CALL Routines
4
LOGPDF Function
675
LOGPDF Function
Computes the logarithm of a probability density (mass) function
Category: Probability
Alias:
See:
LOGPMF
“PDF Function” on page 737
Syntax
LOGPDF(’dist’,quantile,parm-1,...,parm-k)
Arguments
’dist’
is a character string 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’
676
LOGSDF Function
4
Chapter 4
Distribution
Argument
Wald (inverse Gaussian)
’WALD’|’IGAUSS’
Weibull
’WEIBULL’
Note: Except for T, F, and NORMALMIX, you can minimally identify any
distribution by its first four characters. 4
quantile
is a numeric random variable.
parm-1,...,parm-k
are optional shape, location, or scale parameters appropriate for the specific
distribution.
The LOGPDF function computes the logarithm of the probability density (mass)
function from various continuous and discrete distributions. For more information, see
the “PDF Function” on page 737.
LOGSDF Function
Computes the logarithm of a survival function
Probability
“SDF Function” on page 878
Category:
See:
Syntax
LOGSDF(’dist’,quantile,parm-1,...,parm-k)
Arguments
’dist’
is a character string 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’
Functions and CALL Routines
Distribution
Argument
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’
Wald (inverse Gaussian)
’WALD’|’IGAUSS’
Weibull
’WEIBULL’
4
LOWCASE Function
677
Note: Except for T, F, and NORMALMIX, you can minimally identify any
distribution by its first four characters. 4
quantile
is a numeric random variable.
parm-1,...,parm-k
are optional shape, location, or scale parameters appropriate for the specific
distribution.
The LOGSDF function computes the logarithm of the survival function from various
continuous and discrete distributions. For more information, see the “SDF Function” on
page 878.
LOWCASE Function
Converts all letters in an argument to lowercase
Category: Character
Syntax
LOWCASE(argument)
678
MAD Function
4
Chapter 4
Arguments
argument
specifies any SAS character expression.
Details
If the LOWCASE function returns a value to a variable that has not yet been assigned a
length, by default the variable length is determined by the length of the first argument.
The LOWCASE function copies a character argument, converts all uppercase letters
to lowercase letters, and returns the altered value as a result.
Examples
SAS Statements
Results
x=’INTRODUCTION’;
y=lowcase(x);
put y;
introduction
See Also
Functions:
“UPCASE Function” on page 936
“PROPCASE Function” on page 784
MAD Function
Returns the median absolute deviation from the median
Category:
Descriptive Statistics
Syntax
MAD(value-1 <, value-2...>)
Arguments
value
specifies a numeric constant, variable, or expression of which the median absolute
deviation from the median is to be computed.
Functions and CALL Routines
4
MAX Function
679
Details
If all arguments have missing values, the result is a missing value. Otherwise, the
result is the median absolute deviation from the median of the non-missing values. The
formula for the median is the same as the one that is used in the UNIVARIATE
procedure. For more information, see Base SAS Procedures Guide.
Examples
SAS Statements
mad=mad(2,4,1,3,5,999999);
put mad;
Results
1.5
See Also
Functions:
“IQR Function” on page 644
“MEDIAN Function” on page 682
“PCTL Function” on page 736
MAX Function
Returns the largest value
Category: Descriptive Statistics
Syntax
MAX(argument,argument,...)
Arguments
argument
is numeric. At least two arguments are required. The argument list may consist of a
variable list, which is preceded by OF.
Comparisons
The MAX function returns a missing value (.) only if all arguments are missing.
The MAX operator (<>) returns a missing value only if both operands are missing. In
this case, it returns the value of the operand that is higher in the sort order for missing
values.
680
MDY Function
4
Chapter 4
Examples
SAS Statements
Results
x=max(8,3);
8
x1=max(2,6,.);
6
x2=max(2.-3,1,-1);
2
x3=max(3,.,-3);
3
x4=max(of x1-x3);
6
MDY Function
Returns a SAS date value from month, day, and year values
Category:
Date and Time
Syntax
MDY(month,day,year)
Arguments
month
specifies a numeric expression that represents an integer from 1 through 12.
day
specifies a numeric expression that represents an integer from 1 through 31.
year
specifies a two-digit or four-digit integer that represents the year. The
YEARCUTOFF= system option defines the year value for two-digit dates.
Functions and CALL Routines
4
MEAN Function
Examples
SAS Statements
Results
birthday=mdy(8,27,90);
put birthday;
put birthday= worddate.;
11196
birthday=August 27, 1990
anniversary=mdy(7,11,2001);
put anniversary;
put anniversary=date9.;
15167
anniversary=11JUL2001
See Also
Functions:
“DAY Function” on page 503
“MONTH Function” on page 695
“YEAR Function” on page 991
MEAN Function
Returns the arithmetic mean (average)
Category: Descriptive Statistics
Syntax
MEAN(argument< ,argument,…>)
681
682
MEDIAN Function
4
Chapter 4
Arguments
argument
is numeric. At least one non-missing argument is required. Otherwise, the function
returns a missing value.
The argument list can consist of a variable list, which is preceded by OF.
Tip:
Comparisons
The GEOMEAN function returns the geometric mean, the HARMEAN function returns
the harmonic mean, and the MEDIAN function returns the median of the non-missing
values, whereas the MEAN function returns the arithmetic mean (average).
Examples
SAS Statements
Results
x1=mean(2,.,.,6);
4
x2=mean(1,2,3,2);
2
x3=mean(of x1-x2);
3
See Also
Function:
“GEOMEAN Function” on page 597
“GEOMEANZ Function” on page 598
“HARMEAN Function” on page 605
“HARMEANZ Function” on page 606
“MEDIAN Function” on page 682
MEDIAN Function
Computes median values
Category:
Descriptive Statistics
Syntax
MEDIAN(value1< , value2, ...>)
Functions and CALL Routines
4
MIN Function
683
Arguments
value
is numeric.
Details
The MEDIAN function returns the median of the nonmissing values. If all arguments
have missing values, the result is a missing value.
Note: The formula that is used in the MEDIAN function is the same as the formula
that is used in PROC UNIVARIATE. For more information, see “SAS Elementary
Statistics Procedures” in Base SAS Procedures Guide. 4
Comparisons
The MEDIAN function returns the median of nonmissing values, whereas the MEAN
function returns the arithmetic mean (average).
Examples
SAS Statements
Results
x=median(2,4,1,3);
2.5
y=median(5,8,0,3,4);
4
See Also
Function:
“MEAN Function” on page 681
MIN Function
Returns the smallest value
Category: Descriptive Statistics
Syntax
MIN(argument,argument,...)
684
MINUTE Function
4
Chapter 4
Arguments
argument
is numeric. At least two arguments are required. The argument list may consist of a
variable list, which is preceded by OF.
Comparisons
The MIN function returns a missing value (.) only if all arguments are missing.
The MIN operator (><) returns a missing value only if either operand is missing. In
this case, it returns the value of the operand that is lower in the sort order for missing
values.
Examples
SAS Statements
Results
x=min(7,4);
4
x1=min(2,.,6);
2
x2=min(2,-3,1,-1);
-3
x3=min(0,4);
0
x4=min(of x1-x3);
-3
MINUTE Function
Returns the minute from a SAS time or datetime value
Category:
Date and Time
Syntax
MINUTE(time | datetime)
Functions and CALL Routines
4
MINUTE Function
685
Arguments
time
specifies a SAS expression that represents a SAS time value.
datetime
specifies a SAS expression that represents a SAS datetime value.
Details
The MINUTE function returns an integer that represents a specific minute of the hour.
MINUTE always returns a positive number in the range of 0 through 59. Missing
values are ignored.
Examples
SAS Statements
Results
time=’3:19:24’t;
m=minute(time);
put m;
19
See Also
Functions:
“HOUR Function” on page 611
“SECOND Function” on page 880
686
MISSING Function
4
Chapter 4
MISSING Function
Returns a numeric result that indicates whether the argument contains a missing value
Category:
Descriptive Statistics
Category:
Character
Syntax
MISSING(numeric-expression | character-expression)
Arguments
numeric-expression
specifies numeric data.
character-expression
is the name of a character variable or an expression that evaluates to a character
value.
Details
3 The MISSING function checks a numeric or character expression for a missing
value, and returns a numeric result. If the argument does not contain a missing
value, SAS returns a value of 0. If the argument contains a missing value, SAS
returns a value of 1.
3 A character-expression is defined as having a missing value if the result of the
expression contains all blank spaces.
3 A numeric-expression is defined as having a missing value if the result of the
expression is missing (.), or if the expression contains special characters you used
to differentiate among missing values. The special characters are the letters A
through Z and the underscore, preceded by a period.
Comparisons
The NMISS function requires a numeric argument and returns the number of missing
values in the list of arguments.
Functions and CALL Routines
4
MOD Function
Examples
This example uses the MISSING function to check whether the input variables
contain missing values.
data values;
input @1 var1 3. @5 var2 3.;
if missing(var1) then
do;
put ’Variable 1 is Missing.’;
end;
else if missing(var2) then
do;
put ’Variable 2 is Missing.’;
end;
datalines;
127
988 195
;
In this example, the following message appears in the SAS log.
Variable 2 is Missing.
See Also
Functions and CALL Routines:
“NMISS Function” on page 705
“CALL MISSING Routine” on page 364
MOD Function
Returns the remainder from the division of the first argument by the second argument, fuzzed to
avoid most unexpected floating-point results
Category: Mathematical
Syntax
MOD (argument-1, argument-2)
687
688
MOD Function
4
Chapter 4
Arguments
argument-1
is a numeric constant, variable, or expression that specifies the dividend.
argument-2
is a numeric constant, variable, or expression that specifies the divisor.
Restriction: cannot be 0
Details
The MOD function returns the remainder from the division of argument-1 by
argument-2. When the result is non-zero, the result has the same sign as the first
argument. The sign of the second argument is ignored.
The computation that is performed by the MOD function is exact if both of the
following conditions are true:
3 Both arguments are exact integers.
3 All integers that are less than either argument have exact 8-byte floating-point
representations.
To determine the largest integer for which the computation is exact, execute the
following DATA step:
data _null_;
exactint = constant(’exactint’);
put exactint=;
run;
Operating Environment Information: You can also refer to the SAS documentation
for your operating environment for information about the largest integer. 4
If either of the above conditions is not true, a small amount of numerical error can
occur in the floating-point computation. In this case
3 MOD returns zero if the remainder is very close to zero or very close to the value
of the second argument.
3 MOD returns a missing value if the remainder cannot be computed to a precision
of approximately three digits or more. In this case, SAS also writes an error
message to the log.
Note: Prior to SAS 9, the MOD function did not perform the adjustments to the
remainder that were described in the previous paragraph. For this reason, the results
of the MOD function in SAS 9 might differ from previous versions. 4
Functions and CALL Routines
4
MOD Function
689
Comparisons
Here are some comparisons between the MOD and MODZ functions:
3 The MOD function performs extra computations, called fuzzing, to return an exact
zero when the result would otherwise differ from zero because of numerical error.
3 The MODZ function performs no fuzzing.
3 Both the MOD and MODZ functions return a missing value if the remainder
cannot be computed to a precision of approximately three digits or more.
Examples
The following SAS statements produce results for MOD and MODZ.
SAS Statements
Results
x1=mod(10,3);
put x1 9.4;
1.0000
xa=modz(10,3);
put xa 9.4;
1.0000
x2=mod(.3,-.1);
put x2 9.4;
0.0000
xb=modz(.3,-.1);
put xb 9.4;
0.1000
x3=mod(1.7,.1);
put x3 9.4;
0.0000
xc=modz(1.7,.1);
put xc 9.4;
0.0000
x4=mod(.9,.3);
put x4 24.20;
0.00000000000000000000
xd=modz(.9,.3);
put xd 24.20;
0.00000000000000005551
See Also
Functions:
“INT Function” on page 629
“INTZ Function” on page 640
“MODZ Function” on page 694
690
MODULEC Function
4
Chapter 4
MODULEC Function
Calls an external routine and returns a character value
External Routines
Category:
See:
“CALL MODULE Routine” on page 365
Syntax
MODULEC(< cntl-string,>module-name< ,argument-1, ..., argument-n>)
Details
For details on the MODULEC function, see “CALL MODULE Routine” on page 365.
See Also
CALL Routines:
“CALL MODULE Routine” on page 365
“CALL MODULEI Routine” on page 368
Functions:
“MODULEIC Function” on page 691
“MODULEIN Function” on page 692
“MODULEN Function” on page 693
Functions and CALL Routines
4
MODULEIC Function
MODULEIC Function
Calls an external routine and returns a character value (in IML environment only)
Category: External Routines
Restriction:
See:
MODULEIC can only be invoked from within the IML procedure
“CALL MODULE Routine” on page 365
Syntax
MODULEIC(< cntl-string,>module-name< ,argument-1, ..., argument-n>)
Details
For details on the MODULEIC function, see “CALL MODULE Routine” on page 365.
See Also
CALL Routines:
“CALL MODULE Routine” on page 365
“CALL MODULEI Routine” on page 368
Functions:
“MODULEC Function” on page 690
“MODULEIN Function” on page 692
“MODULEN Function” on page 693
691
692
MODULEIN Function
4
Chapter 4
MODULEIN Function
Calls an external routine and returns a numeric value (in IML environment only)
External Routines
Restriction: MODULEIN can only be invoked from within the IML procedure
Category:
See:
“CALL MODULE Routine” on page 365
Syntax
MODULEIN(<cntl-string,>module-name< ,argument-1, ..., argument-n>)
Details
For details on the MODULEIN function, see “CALL MODULE Routine” on page 365.
See Also
CALL Routines:
“CALL MODULE Routine” on page 365
“CALL MODULEI Routine” on page 368
Functions:
“MODULEC Function” on page 690
“MODULEIC Function” on page 691
“MODULEN Function” on page 693
Functions and CALL Routines
4
MODULEN Function
MODULEN Function
Calls an external routine and returns a numeric value
Category: External Routines
See:
“CALL MODULE Routine” on page 365
Syntax
MODULEN(< cntl-string,>module-name< ,argument-1, ..., argument-n>)
Details
For details on the MODULEN function, see “CALL MODULE Routine” on page 365.
See Also
CALL Routines:
“CALL MODULE Routine” on page 365
“CALL MODULEI Routine” on page 368
Functions:
“MODULEC Function” on page 690
“MODULEIC Function” on page 691
“MODULEIN Function” on page 692
693
694
MODZ Function
4
Chapter 4
MODZ Function
Returns the remainder from the division of the first argument by the second argument, using zero
fuzzing
Mathematical
Category:
Syntax
MODZ (argument-1, argument-2)
Arguments
argument-1
is a numeric constant, variable, or expression that specifies the dividend.
argument-2
is a non-zero numeric constant, variable, or expression that specifies the divisor.
Details
The MODZ function returns the remainder from the division of argument-1 by
argument-2. When the result is non-zero, the result has the same sign as the first
argument. The sign of the second argument is ignored.
The computation that is performed by the MODZ function is exact if both of the
following conditions are true:
3 Both arguments are exact integers.
3 All integers that are less than either argument have exact 8-byte floating-point
representation.
To determine the largest integer for which the computation is exact, execute the
following DATA step:
data _null_;
exactint = constant(’exactint’);
put exactint=;
run;
Operating Environment Information: You can also refer to the SAS documentation
for your operating environment for information about the largest integer. 4
If either of the above conditions is not true, a small amount of numerical error can
occur in the floating-point computation. For example, when you use exact arithmetic
and the result is zero, MODZ might return a very small positive value or a value
slightly less than the second argument.
Functions and CALL Routines
4
MONTH Function
695
Comparisons
Here are some comparisons between the MODZ and MOD functions:
3 The MODZ function performs no fuzzing.
3 The MOD function performs extra computations, called fuzzing, to return an exact
zero when the result would otherwise differ from zero because of numerical error.
3 Both the MODZ and MOD functions return a missing value if the remainder
cannot be computed to a precision of approximately three digits or more.
Examples
The following SAS statements produce results for MOD and MODZ.
SAS Statements
Results
x1=mod(10,3);
put x1 9.4;
1.0000
xa=modz(10,3);
put xa 9.4;
1.0000
x2=mod(.3,-.1);
put x2 9.4;
0.0000
xb=modz(.3,-.1);
put xb 9.4;
0.1000
x3=mod(1.7,.1);
put x3 9.4;
0.0000
xc=modz(1.7,.1);
put xc 9.4;
0.0000
x4=mod(.9,.3);
put x4 24.20;
0.00000000000000000000
xd=modz(.9,.3);
put xd 24.20;
0.00000000000000005551
See Also
Functions:
“INT Function” on page 629
“INTZ Function” on page 640
“MOD Function” on page 687
MONTH Function
Returns the month from a SAS date value
Category: Date and Time
696
MOPEN Function
4
Chapter 4
Syntax
MONTH(date)
Arguments
date
specifies a SAS expression that represents a SAS date value.
Details
The MONTH function returns a numeric value that represents the month from a SAS
date value. Numeric values can range from 1 through 12.
Examples
SAS Statements
Results
date=’25jan94’d;
m=month(date);
put m;
1
See Also
Functions:
“DAY Function” on page 503
“YEAR Function” on page 991
MOPEN Function
Opens a file by directory id and member name, and returns the file identifier or a 0
Category:
See:
External Files
MOPEN Function in the documentation for your operating environment.
Syntax
MOPEN(directory-id,member-name<open-mode< ,record-length<,record-format>>>)
Functions and CALL Routines
4
MOPEN Function
697
Arguments
directory-id
specifies the identifier that was assigned when the directory was opened, generally
by the DOPEN function.
member-name
specifies the member name in the directory.
open-mode
specifies the type of access to the file:
A
APPEND mode allows writing new records after the current end
of the file.
I
INPUT mode allows reading only (default).
O
OUTPUT mode defaults to the OPEN mode specified in the
operating environment option in the FILENAME statement or
function. If no operating environment option is specified, it allows
writing new records at the beginning of the file.
S
Sequential input mode is used for pipes and other sequential
devices such as hardware ports.
U
UPDATE mode allows both reading and writing.
W
Sequential update mode is used for pipes and other sequential
devices such as ports.
Default: I
record-length
specifies a new logical record length for the file. To use the existing record length for
the file, specify a length of 0, or do not provide a value here.
record-format
specifies a new record format for the file. To use the existing record format, do not
specify a value here. Valid values are:
B
specifies that data is to be interpreted as binary data.
D
specifies the default record format.
E
specifies the record format that you can edit.
F
specifies that the file contains fixed-length records.
P
specifies that the file contains printer carriage control in
operating environment-dependent record format.
V
specifies that the file contains variable-length records.
698
MOPEN Function
4
Chapter 4
Details
MOPEN returns the identifier for the file, or 0 if the file could not be opened. You can
use a file-id that is returned by the MOPEN function as you would use a file-id
returned by the FOPEN function.
CAUTION:
Use OUTPUT mode with care. Opening an existing file for output may overwrite the
current contents of the file without warning. 4
The member is identified by directory-id and member-name instead of by a fileref.
You can also open a directory member by using FILENAME to assign a fileref to the
member, followed by a call to FOPEN. However, when you use MOPEN, you do not
have to use a separate fileref for each member.
If the file already exists, the output and update modes default to the operating
environment option (append or replace) specified with the FILENAME statement or
function. For example,
%let
%let
%let
%let
%let
%let
rc=%sysfunc(filename(file,physical-name,,mod));
did=%sysfunc(dopen(&file));
fid=%sysfunc(mopen(&did,member-name,o,0,d));
rc=%sysfunc(fput(&fid,This is a test.));
rc=%sysfunc(fwrite(&fid));
rc=%sysfunc(fclose(&fid));
If ’file’ already exists, FWRITE appends the new record instead of writing it at
the beginning of the file. However, if no operating environment option is specified with
the FILENAME function, the output mode implies that the record be replaced.
If the open fails, use SYSMSG to retrieve the message text.
Operating Environment Information: The term directory in this description refers to
an aggregate grouping of files that are managed by the operating environment.
Different host operating environments identify such groupings with different names,
such as directory, subdirectory, MACLIB, or partitioned data set. For details, see the
SAS documentation for your operating environment.
Opening a directory member for output or append is not possible in some operating
environments. 4
Examples
This example assigns the fileref MYDIR to a directory. Then it opens the directory,
determines the number of members, retrieves the name of the first member, and opens
that member. The last three arguments to MOPEN are the defaults. Note that in a
macro statement you do not enclose character strings in quotation marks.
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf,physical-name));
%let did=%sysfunc(dopen(&filrf));
%let frstname=’ ’;
%let memcount=%sysfunc(dnum(&did));
%if (&memcount > 0) %then
%do;
%let frstname =
%sysfunc(dread(&did,1));
%let fid =
%sysfunc(mopen(&did,&frstname,i,0,d));
macro statements to process the member
Functions and CALL Routines
4
%let rc=%sysfunc(fclose(&fid));
%end;
%else
%put %sysfunc(sysmsg());
%let rc=%sysfunc(dclose(&did));
See Also
Functions:
“DCLOSE Function” on page 504
“DNUM Function” on page 526
“DOPEN Function” on page 527
“DREAD Function” on page 531
“FCLOSE Function” on page 544
“FILENAME Function” on page 555
“FOPEN Function” on page 578
“FPUT Function” on page 586
“FWRITE Function” on page 593
“SYSMSG Function” on page 914
MORT Function
Returns amortization parameters
Category: Financial
Syntax
MORT(a,p,r,n)
Arguments
a
is numeric, the initial amount.
p
is numeric, the periodic payment.
r
is numeric, the periodic interest rate that is expressed as a fraction.
n
is an integer, the number of compounding periods.
Range: n ≥ 0
MORT Function
699
700
N Function
4
Chapter 4
Details
The MORT function returns the missing argument in the list of four arguments from an
amortization calculation with a fixed interest rate that is compounded each period. The
arguments are related by
p=
ar (1 + r)n
n
(1 + r) 0 1
One missing argument must be provided. It is then calculated from the remaining
three. No adjustment is made to convert the results to round numbers.
Examples
An amount of $50,000 is borrowed for 30 years at an annual interest rate of 10
percent compounded monthly. The monthly payment can be expressed as
payment=mort(50000, . , .10/12,30*12);
The value returned is 438.79. The second argument has been set to missing, which
indicates that the periodic payment is to be calculated. The 10 percent nominal annual
rate has been converted to a monthly rate of 0.10/12. The rate is the fractional (not the
percentage) interest rate per compounding period. The 30 years are converted into 360
months.
N Function
Returns the number of nonmissing values
Category:
Descriptive Statistics
Syntax
N(argument,argument, ...)
Arguments
argument
is numeric. At least one argument is required. The argument list may consist of a
variable list, which is preceded by OF.
Functions and CALL Routines
4
NETPV Function
701
Examples
SAS Statements
Results
x1=n(1,0,.,2,5,.);
4
x2=n(1,2);
2
x3=n(of x1-x2);
2
NETPV Function
Returns the net present value as a fraction
Category: Financial
Syntax
NETPV(r,freq,c0,c1,...,cn)
r
is numeric, the interest rate over a specified base period of time expressed as a
fraction.
freq
is numeric, the number of payments during the base period of time that is specified
with the rate r.
Range: freq > 0
Exception:
The case freq = 0 is a flag to allow continuous discounting.
c0,c1,...,cn
are numeric cash flows that represent cash outlays (payments) or cash inflows
(income) occurring at times 0, 1, ...n. These cash flows are assumed to be equally
spaced, beginning-of-period values. Negative values represent payments, positive
values represent income, and values of 0 represent no cash flow at a given time. The
c0 argument and the c1 argument are required.
Details
The NETPV function returns the net present value at time 0 for the set of cash
payments c0,c1, ...,cn, with a rate r over a specified base period of time. The argument
freq>0 describes the number of payments that occur over the specified base period of
time.
The net present value is given by
NETPV (r; f req; c0; c1; :::; cn) =
X
n
=0
i
ci x
i
702
NLDATE Function
4
Chapter 4
where
x=
1
(1=freq)
(1+r )
e0r
f req > 0
f req = 0
Missing values in the payments are treated as 0 values. When freq>0, the rate r is
the effective rate over the specified base period. To compute with a quarterly rate (the
base period is three months) of 4 percent with monthly cash payments, set freq to 3 and
set r to .04.
If freq is 0, continuous discounting is assumed. The base period is the time interval
between two consecutive payments, and the rate r is a nominal rate.
To compute with a nominal annual interest rate of 11 percent discounted
continuously with monthly payments, set freq to 0 and set r to .11/12.
Examples
For an initial investment of $500 that returns biannual payments of $200, $300, and
$400 over the succeeding 6 years and an annual discount rate of 10 percent, the net
present value of the investment can be expressed as
value=netpv(.10,.5,-500,200,300,400);
The value returned is 95.98.
NLDATE Function
Converts the SAS date value to the date value of the specified locale using the date-format
modifiers
Date and Time
See: The NLDATE function in SAS National Language Support (NLS): User’s Guide
Category:
NLDATM Function
Converts the SAS datetime values to the time value of the specified locale using the datetime
format modifiers
Category:
See:
Date and Time
The NLDATM function in SAS National Language Support (NLS): User’s Guide
Functions and CALL Routines
4
NLITERAL Function
703
NLTIME Function
Converts the SAS time or datetime value to the time value of the specified locale using the
time-format modifiers
Category: Date and Time
See:
The NLTIME function in SAS National Language Support (NLS): User’s Guide
NLITERAL Function
Converts a character string that you specify to a SAS name literal (n-literal)
Category: Character
Syntax
NLITERAL(string)
Arguments
string
specifies a character constant, variable, or expression that is to be converted to a SAS
name literal (n-literal).
Tip: Enclose a literal string of characters in quotation marks.
Restriction: If the string is a valid SAS variable name, by default, it is not
converted to an n–literal.
Details
If the NLITERAL function returns a value to a variable that has not yet been assigned
a length, by default the variable is assigned a length of 200.
The NLITERAL function converts string to a SAS name literal (n-literal). String will
be converted to an n-literal, unless it qualifies under the default rules for a SAS
variable name. These default rules are in effect when the SAS system option
VALIDVARNAME=V7:
3 It begins with an English letter or an underscore.
3 All subsequent characters are English letters, underscores, or digits.
3 The length is 32 or fewer alphanumeric characters.
String, therefore, qualifies as a SAS variable name, when all of these are true.
CAUTION:
If insufficient space is available for the resulting n-literal, NLITERAL returns a blank string,
prints an error message, and sets _ERROR_ to 1. 4
The NLITERAL function encloses the value of string in single or double quotation
marks, based on the contents of string.
704
NLITERAL Function
4
Chapter 4
If string contains …
NLITERAL encloses the result in …
an ampersand (&)
single quotation marks
a percent sign (%)
single quotation marks
more double quotation marks than single quotation
marks
single quotation marks
none of the above
double quotation marks
Examples
This example demonstrates multiple uses of NLITERAL.
data test;
input string $32.;
length result $ 67;
result = nliteral(string);
datalines;
abc_123
This and That
cats & dogs
Company’s profits (%)
"Double Quotes"
’Single Quotes’
;
proc print;
title ’Strings Converted to N-Literals or Returned Unchanged’;
run;
Output 4.28
Converting Strings to Name Literals with NLITERAL
Strings Converted to N-Literals or Returned Unchanged
Obs
1
2
3
4
5
6
string
result
abc_123
This and That
cats & dogs
Company’s profits (%)
"Double Quotes"
’Single Quotes’
abc_123
"This and That"N
’cats & dogs’N
’Company’’s profits (%)’N
’"Double Quotes"’N
"’Single Quotes’"N
See Also
Functions:
“COMPARE Function” on page 463
“DEQUOTE Function” on page 512
“NVALID Function” on page 730
1
Functions and CALL Routines
4
NORMAL Function
System Option:
“VALIDVARNAME= System Option” on page 1754
“Rules for Words and Names in the SAS Language” in SAS Language Reference:
Concepts
NMISS Function
Returns the number of missing values
Category: Descriptive Statistics
Syntax
NMISS(argument<,...argument-n>)
Arguments
argument
is numeric. At least one argument is required. The argument list may consist of a
variable list, which is preceded by OF.
Examples
SAS Statements
Results
x1=nmiss(1,0,.,2,5,.);
2
x2=nmiss(1,0);
0
x3=nmiss(of x1-x2);
0
NORMAL Function
Returns a random variate from a normal distribution
Category:
See:
Random Number
“RANNOR Function” on page 834
Syntax
NORMAL(seed)
705
706
NOTALNUM Function
4
Chapter 4
Arguments
seed
is an integer.
31
Range: seed < 2 − 1
Note: If seed ≤ 0, the time of day is used to initialize the seed stream.
NOTALNUM Function
Searches a character string for a non-alphanumeric character and returns the first position at
which it is found
Category:
Character
Syntax
NOTALNUM(string <,start>)
Arguments
string
specifies the character 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 NOTALNUM function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTALNUM function searches a string for the first occurrence of any character
that is not a digit or an uppercase or lowercase letter. If such a character is found,
NOTALNUM returns the position in the string of that character. If no such character is
found, NOTALNUM returns a value of 0.
If you use only one argument, NOTALNUM 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.
NOTALNUM returns a value of zero when
Functions and CALL Routines
4
NOTALPHA Function
707
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 NOTALNUM function searches a character string for a non-alphanumeric character.
The ANYALNUM function searches a character string for an alphanumeric character.
Examples
The following example uses the NOTALNUM function to search a string from left to
right for non-alphanumeric characters.
data _null_;
string=’Next = Last + 1;’;
j=0;
do until(j=0);
j=notalnum(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=6 c==
j=7 c=
j=12 c=
j=13 c=+
j=14 c=
j=16 c=;
That’s all
See Also
Function:
“ANYALNUM Function” on page 314
NOTALPHA Function
Searches a character string for a non-alphabetic character and returns the first position at which it
is found
Category: Character
708
NOTALPHA Function
4
Chapter 4
Syntax
NOTALPHA(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 NOTALPHA function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTALPHA function searches a string for the first occurrence of any character
that is not an uppercase or lowercase letter. If such a character is found, NOTALPHA
returns the position in the string of that character. If no such character is found,
NOTALPHA returns a value of 0.
If you use only one argument, NOTALPHA 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.
NOTALPHA returns a value of zero when
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 NOTALPHA function searches a character string for a non-alphabetic character.
The ANYALPHA function searches a character string for an alphabetic character.
Examples
The following example uses the NOTALPHA function to search a string from left to
right for non-alphabetic characters.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notalpha(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
Functions and CALL Routines
4
NOTCNTRL Function
709
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=5 c=
j=6 c==
j=7 c=
j=8 c=_
j=10 c=_
j=11 c=
j=12 c=+
j=13 c=
j=14 c=1
j=15 c=2
j=17 c=3
j=18 c=;
That’s all
See Also
Function:
“ANYALPHA Function” on page 316
NOTCNTRL Function
Searches a character string for a character that is not a control character and returns the first
position at which it is found
Category: Character
Syntax
NOTCNTRL(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 NOTCNTRL function searches a string for the first occurrence of a character that
is not a control character. If such a character is found, NOTCNTRL returns the position
710
4
NOTDIGIT Function
Chapter 4
in the string of that character. If no such character is found, NOTCNTRL returns a
value of 0.
If you use only one argument, NOTCNTRL 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.
NOTCNTRL returns a value of zero when
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 NOTCNTRL function searches a character string for a character that is not a
control character. The ANYCNTRL function searches a character string for a control
character.
See Also
Function:
“ANYCNTRL Function” on page 318
NOTDIGIT Function
Searches a character string for any character that is not a digit and returns the first position at
which that character is found
Category:
Character
Syntax
NOTDIGIT(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
NOTDIGIT Function
711
Details
The NOTDIGIT function searches a string for the first occurrence of any character that
is not a digit. If such a character is found, NOTDIGIT returns the position in the string
of that character. If no such character is found, NOTDIGIT returns a value of 0.
If you use only one argument, NOTDIGIT 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.
NOTDIGIT returns a value of zero when
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 NOTDIGIT function searches a character string for any character that is not a
digit. The ANYDIGIT function searches a character string for a digit.
Examples
The following example uses the NOTDIGIT function to search for a character that is
not a digit.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notdigit(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=+
712
NOTE Function
4
Chapter 4
j=13 c=
j=16 c=E
j=18 c=;
That’s all
See Also
Function:
“ANYDIGIT Function” on page 319
NOTE Function
Returns an observation ID for the current observation of a SAS data set
Category:
SAS File I/O
Syntax
NOTE(data-set-id)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
Details
You can use the observation ID value to return to the current observation by using
POINT. Observations can be marked by using NOTE and then returned to later by
using POINT. Each observation ID is a unique numeric value.
To free the memory that is associated with an observation ID, use DROPNOTE.
Examples
This example calls CUROBS to display the observation number, calls NOTE to mark
the observation, and calls POINT to point to the observation that corresponds to
NOTEID.
%let dsid=%sysfunc(open(sasuser.fitness,i));
/* Go to observation 10 in data set */
%let rc=%sysfunc(fetchobs(&dsid,10));
%if %sysfunc(abs(&rc)) %then
%put FETCHOBS FAILED;
%else
%do;
/* Display observation number
*/
/* in the Log
*/
%let cur=%sysfunc(curobs(&dsid));
Functions and CALL Routines
4
NOTFIRST Function
%put CUROBS=&cur;
/* Mark observation 10 using NOTE */
%let noteid=%sysfunc(note(&dsid));
/* Rewind pointer to beginning
*/
/* of data
*/
/* set using REWIND
*/
%let rc=%sysfunc(rewind(&dsid));
/* FETCH first observation into DDV */
%let rc=%sysfunc(fetch(&dsid));
/* Display first observation number */
%let cur=%sysfunc(curobs(&dsid));
%put CUROBS=&cur;
/* POINT to observation 10 marked */
/* earlier by NOTE
*/
%let rc=%sysfunc(point(&dsid,&noteid));
/* FETCH observation into DDV */
%let rc=%sysfunc(fetch(&dsid));
/* Display observation number 10
*/
/* marked by NOTE
*/
%let cur=%sysfunc(curobs(&dsid));
%put CUROBS=&cur;
%end;
%if (&dsid > 0) %then
%let rc=%sysfunc(close(&dsid));
The output produced by this program is:
CUROBS=10
CUROBS=1
CUROBS=10
See Also
Functions:
“DROPNOTE Function” on page 532
“OPEN Function” on page 732
“POINT Function” on page 761
“REWIND Function” on page 842
NOTFIRST Function
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
Category: Character
Syntax
NOTFIRST(string <,start>)
713
714
NOTFIRST Function
4
Chapter 4
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 NOTFIRST function does not depend on the TRANTAB, ENCODING, or LOCALE
options.
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. These characters are any except the underscore (_) and
uppercase or lowercase English letters. If such a character is found, NOTFIRST returns
the position in the string of that character. If no such character is found, NOTFIRST
returns a value of 0.
If you use only one argument, NOTFIRST 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.
NOTFIRST returns a value of zero when
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 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.
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.
Examples
The following example uses the NOTFIRST function to search a string for any
character that is not 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=notfirst(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
Functions and CALL Routines
4
NOTGRAPH Function
715
put +3 j= c=;
end;
end;
run;
The following lines are written to the SAS log:
j=5 c=
j=6 c==
j=7 c=
j=11 c=
j=12 c=+
j=13 c=
j=14 c=1
j=15 c=2
j=17 c=3
j=18 c=;
That’s all
See Also
Function:
“ANYFIRST Function” on page 320
NOTGRAPH Function
Searches a character string for a non-graphical character and returns the first position at which it
is found
Category: Character
Syntax
NOTGRAPH(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 NOTGRAPH function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
716
NOTGRAPH Function
4
Chapter 4
The NOTGRAPH function searches a string for the first occurrence of a non-graphical
character. A graphical character is defined as any printable character other than white
space. If such a character is found, NOTGRAPH returns the position in the string of
that character. If no such character is found, NOTGRAPH returns a value of 0.
If you use only one argument, NOTGRAPH 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.
NOTGRAPH returns a value of zero when
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 NOTGRAPH function searches a character string for a non-graphical character.
The ANYGRAPH function searches a character string for a graphical character.
Examples
The following example uses the NOTGRAPH function to search a string for a
non-graphical character.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notgraph(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
See Also
Function:
“ANYGRAPH Function” on page 322
Functions and CALL Routines
4
NOTLOWER Function
717
NOTLOWER Function
Searches a character string for a character that is not a lowercase letter and returns the first
position at which that character is found
Category: Character
Syntax
NOTLOWER(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 NOTLOWER function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTLOWER function searches a string for the first occurrence of any character
that is not a lowercase letter. If such a character is found, NOTLOWER returns the
position in the string of that character. If no such character is found, NOTLOWER
returns a value of 0.
If you use only one argument, NOTLOWER 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.
NOTLOWER returns a value of zero when
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 NOTLOWER function searches a character string for a character that is not a
lowercase letter. The ANYLOWER function searches a character string for a lowercase
letter.
Examples
The following example uses the NOTLOWER function to search a string for any
character that is not a lowercase letter.
718
NOTNAME Function
4
Chapter 4
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notlower(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=5 c=
j=6 c==
j=7 c=
j=8 c=_
j=10 c=_
j=11 c=
j=12 c=+
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
See Also
Function:
“ANYLOWER Function” on page 324
NOTNAME Function
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
Category:
Character
Syntax
NOTNAME(string <,start>)
Functions and CALL Routines
4
NOTNAME Function
719
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 NOTNAME function does not depend on the TRANTAB, ENCODING, or LOCALE
options.
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. These characters
are any except underscore (_), digits, and uppercase or lowercase English letters. If
such a character is found, NOTNAME returns the position in the string of that
character. If no such character is found, NOTNAME returns a value of 0.
If you use only one argument, NOTNAME 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.
NOTNAME returns a value of zero when
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 NOTNAME function searches a string for the first occurrence of any character that
is not valid in a SAS variable name under VALIDVARNAME=V7. The ANYNAME
function searches a string for the first occurrence of any character that is valid in a SAS
variable name under VALIDVARNAME=V7.
Examples
The following example uses the NOTNAME function to search a string for any
character that is not valid in a SAS variable name under VALIDVARNAME=V7.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notname(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
720
4
NOTPRINT Function
Chapter 4
end;
run;
The following lines are written to the SAS log:
j=5 c=
j=6 c==
j=7 c=
j=11 c=
j=12 c=+
j=13 c=
j=18 c=;
That’s all
See Also
Function:
“ANYNAME Function” on page 325
NOTPRINT Function
Searches a character string for a non-printable character and returns the first position at which it
is found
Category:
Character
Syntax
NOTPRINT(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 NOTPRINT function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTPRINT function searches a string for the first occurrence of a non-printable
character. If such a character is found, NOTPRINT returns the position in the string of
that character. If no such character is found, NOTPRINT returns a value of 0.
If you use only one argument, NOTPRINT begins the search at the beginning of the
string. If you use two arguments, the absolute value of the second argument, start,
Functions and CALL Routines
4
NOTPUNCT Function
721
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.
NOTPRINT returns a value of zero when
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 NOTPRINT function searches a character string for a non-printable character. The
ANYPRINT function searches a character string for a printable character.
See Also
Function:
“ANYPRINT Function” on page 327
NOTPUNCT Function
Searches a character string for a character that is not a punctuation character and returns the first
position at which it is found
Category: Character
Syntax
NOTPUNCT(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.
722
NOTPUNCT Function
4
Chapter 4
Details
The results of the NOTPUNCT function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTPUNCT function searches a string for the first occurrence of a character
that is not a punctuation character. If such a character is found, NOTPUNCT returns
the position in the string of that character. If no such character is found, NOTPUNCT
returns a value of 0.
If you use only one argument, NOTPUNCT 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.
NOTPUNCT returns a value of zero when
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 NOTPUNCT function searches a character string for a character that is not a
punctuation character. The ANYPUNCT function searches a character string for a
punctuation character.
Functions and CALL Routines
4
NOTPUNCT Function
Examples
The following example uses the NOTPUNCT function to search a string for
characters that are not punctuation characters.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notpunct(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=7 c=
j=9 c=n
j=11 c=
j=13 c=
j=14 c=1
j=15 c=2
j=16 c=E
j=17 c=3
That’s all
See Also
Function:
“ANYPUNCT Function” on page 329
723
724
NOTSPACE Function
4
Chapter 4
NOTSPACE Function
Searches a character string for a character that is not a white-space character (blank, horizontal
and vertical tab, carriage return, line feed, form feed) and returns the first position at which it is
found
Category:
Character
Syntax
NOTSPACE(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 NOTSPACE function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTSPACE function searches a string for the first occurrence of a character that
is not a blank, horizontal tab, vertical tab, carriage return, line feed, or form feed. If
such a character is found, NOTSPACE returns the position in the string of that
character. If no such character is found, NOTSPACE returns a value of 0.
If you use only one argument, NOTSPACE 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.
NOTSPACE returns a value of zero when
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 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. 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.
Functions and CALL Routines
4
NOTSPACE Function
Examples
The following example uses the NOTSPACE function to search a string for a
character that is not a white-space character.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notspace(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
See Also
Function:
“ANYSPACE Function” on page 330
725
726
NOTUPPER Function
4
Chapter 4
NOTUPPER Function
Searches a character string for a character that is not an uppercase letter and returns the first
position at which that character is found
Category:
Character
Syntax
NOTUPPER(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 NOTUPPER function depend directly on the translation table that is
in effect (see “TRANTAB= System Option” on page 1747) and indirectly on the
ENCODING and LOCALE system options.
The NOTUPPER function searches a string for the first occurrence of a character
that is not an uppercase letter. If such a character is found, NOTUPPER returns the
position in the string of that character. If no such character is found, NOTUPPER
returns a value of 0.
If you use only one argument, NOTUPPER 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.
NOTUPPER returns a value of zero when
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 NOTUPPER function searches a character string for a character that is not an
uppercase letter. The ANYUPPER function searches a character string for an
uppercase letter.
Functions and CALL Routines
4
NOTXDIGIT Function
Examples
The following example uses the NOTUPPER function to search a string for any
character that is not an uppercase letter.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notupper(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=5 c=
j=6 c==
j=7 c=
j=8 c=_
j=9 c=n
j=10 c=_
j=11 c=
j=12 c=+
j=13 c=
j=14 c=1
j=15 c=2
j=17 c=3
j=18 c=;
That’s all
See Also
Function:
“ANYUPPER Function” on page 332
NOTXDIGIT Function
Searches a character string for a character that is not a hexadecimal digit and returns the first
position at which that character is found
Category: Character
727
728
NOTXDIGIT Function
4
Chapter 4
Syntax
NOTXDIGIT(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 NOTXDIGIT function searches a string for the first occurrence of any character
that is not a digit or an uppercase or lowercase A, B, C, D, E, or F. If such a character is
found, NOTXDIGIT returns the position in the string of that character. If no such
character is found, NOTXDIGIT returns a value of 0.
If you use only one argument, NOTXDIGIT 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.
NOTXDIGIT returns a value of zero when
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 NOTXDIGIT function searches a character string for a character that is not a
hexadecimal digit. The ANYXDIGIT function searches a character string for a
character that is a hexadecimal digit.
Examples
The following example uses the NOTXDIGIT function to search a string for a
character that is not a hexadecimal digit.
data _null_;
string=’Next = _n_ + 12E3;’;
j=0;
do until(j=0);
j=notxdigit(string,j+1);
if j=0 then put +3 "That’s all";
else do;
c=substr(string,j,1);
put +3 j= c=;
end;
Functions and CALL Routines
4
NPV Function
729
end;
run;
The following lines are written to the SAS log:
j=1 c=N
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=+
j=13 c=
j=18 c=;
That’s all
See Also
Function:
“ANYXDIGIT Function” on page 333
NPV Function
Returns the net present value with the rate expressed as a percentage
Category: Financial
Syntax
NPV(r,freq,c0,c1,...,cn)
Arguments
r
is numeric, the interest rate over a specifed base period of time expressed as a
percentage.
freq
is numeric, the number of payments during the base period of time specified with the
rate r.
Range: freq > 0
Exception:
The case freq = 0 is a flag to allow continuous discounting.
730
NVALID Function
4
Chapter 4
c0,c1,...,cn
are numeric cash flows that represent cash outlays (payments) or cash inflows
(income) occurring at times 0, 1, ...n. These cash flows are assumed to be equally
spaced, beginning-of-period values. Negative values represent payments, positive
values represent income, and values of 0 represent no cash flow at a given time. The
c0 argument and the c1 argument are required.
Comparisons
The NPV function is identical to NETPV, except that the r argument is provided as a
percentage.
NVALID Function
Checks a character string for validity for use as a SAS variable name in a SAS statement
Category:
Character
Syntax
NVALID(string<,validvarname>)
Arguments
string
specifies a character constant, variable, or expression which will be checked to
determine if it can be used as a SAS variable name in a SAS statement.
Note:
Tip:
Trailing blanks are ignored.
4
Enclose a literal string of characters in quotation marks.
validvarname
is a character constant, variable, or expression that specifies one of the following
values:
V7
determines that string is a valid SAS variable name when all
three of the following are true:
3 It begins with an English letter or an underscore.
3 All subsequent characters are English letters, underscores,
or digits.
3 The length is 32 or fewer alphanumeric characters.
ANY
determines that string is a valid SAS variable name if it contains
32 or fewer characters of any type, including blanks.
NLITERAL
determines that string is a valid SAS variable name if it is in the
form of a SAS name literal (’name’N) or if it is a valid SAS
variable name when VALIDVARNAME=V7.
See: V7 above in this same list.
Functions and CALL Routines
4
NVALID Function
731
Default: If no value is specified, the NVALID function determines that string is a
valid SAS variable name based on the value of the SAS system option
VALIDVARNAME=.
Details
The NVALID function checks string to determine if it can be used as a SAS variable
name in a SAS statement.
The NVALID function returns a value or 1 or 0.
If this condition exists …
NVALID returns a value of …
string can be used as a SAS variable name in a SAS
statement
1
string cannot be used as a SAS variable name in a
SAS statement
0
Examples
This example determines the validity of specified strings as SAS variable names. The
value that is returned by the NVALID function varies with the validvarname argument.
The value of 1 is returned when the string is determined to be a valid SAS variable
name under the rules for the specified validvarname argument. Otherwise, the value of
0 is returned.
options validvarname=v7 ls=64;
data string;
input string $char40.;
v7=nvalid(string,’v7’);
any=nvalid(string,’any’);
nliteral=nvalid(string,’nliteral’);
default=nvalid(string);
datalines;
Tooooooooooooooooooooooooooo Long
OK
Very_Long_But_Still_OK_for_V7
1st_char_is_a_digit
Embedded blank
[email protected]#$%^&*
"Very Loooong N-Literal with """N
’No closing quotation mark
;
proc print noobs;
title1 ’NLITERAL and Validvarname Arguments Determine’;
title2 ’Invalid (0) and Valid (1) SAS Variable Names’;
run;
732
OPEN Function
4
Chapter 4
Output 4.29
Determining the Validity of SAS Variable Names with NLITERAL
NLITERAL and Validvarname Arguments Determine
Invalid (0) and Valid (1) SAS Variable Names
string
v7
Tooooooooooooooooooooooooooo Long
OK
Very_Long_But_Still_OK_for_V7
1st_char_is_a_digit
Embedded blank
[email protected]#$%^&*
"Very Loooong N-Literal with """N
’No closing quotation mark
any
0
0
1
1
0
0
0
0
0
nliteral
0
0
1
1
1
1
1
0
1
1
default
0
0
1
1
1
1
1
1
0
0
0
1
1
0
0
0
0
0
See Also
Functions:
“COMPARE Function” on page 463
“NLITERAL Function” on page 703
System Option:
“VALIDVARNAME= System Option” on page 1754
“Rules for Words and Names in the SAS Language” in SAS Language Reference:
Concepts
OPEN Function
Opens a SAS data set
Category:
SAS File I/O
Syntax
OPEN(<data-set-name<,mode>>)
Arguments
data-set-name
specifies the SAS data set to be opened. The name should be of the form
<libref.>member-name< (data-set-options)>
Default: The default value for data-set-name is _LAST_.
Restriction: If you specify the FIRSTOBS= and OBS= data set, they are ignored.
All other data set options are valid.
Functions and CALL Routines
4
OPEN Function
733
mode
specifies the type of access to the data set:
I
opens the data set in INPUT mode (default). Values can be read
but not modified. ’I’ uses the strongest access mode available in
the engine. That is, if the engine supports random access, OPEN
defaults to random access. Otherwise, the file is opened in ’IN’
mode automatically. Files are opened with sequential access and
a system level warning is set.
IN
opens the data set in INPUT mode. Observations are read
sequentially, and you are allowed to revisit an observation.
IS
opens the data set in INPUT mode. Observations are read
sequentially, but you are not allowed to revisit an observation.
Default: I
Details
OPEN opens a SAS data set (a SAS data set or a SAS SQL view) and returns a unique
numeric data set identifier, which is used in most other data set access functions.
OPEN returns 0 if the data set could not be opened.
By default, a SAS data set is opened with a control level of RECORD. For details, see
the “CNTLLEV= Data Set Option” on page 13 . An open SAS data set should be closed
when it is no longer needed. If you open a data set within a DATA step, it will be closed
automatically when the DATA step ends.
OPEN defaults to the strongest access mode available in the engine. That is, if the
engine supports random access, OPEN defaults to random access when data sets are
opened in INPUT or UPDATE mode. Otherwise, data sets are opened with sequential
access, and a system-level warning is set.
Examples
3 This example opens the data set PRICES in the library MASTER using INPUT
mode. Note that in a macro statement you do not enclose character strings in
quotation marks.
%let dsid=%sysfunc(open(master.prices,i));
%if (&dsid = 0) %then
%put %sysfunc(sysmsg());
%else
%put PRICES data set has been opened;
3 This example passes values from macro or DATA step variables to be used on data
set options. It opens the data set SASUSER.HOUSES, and uses the WHERE=
data set option to apply a permanent WHERE clause. Note that in a macro
statement you do not enclose character strings in quotation marks.
%let choice = style="RANCH";
%let dsid=%sysfunc(open(sasuser.houses
(where=(&choice)),i));
734
ORDINAL Function
4
Chapter 4
See Also
Function:
“CLOSE Function” on page 455
ORDINAL Function
Returns any specified order statistic
Category:
Descriptive Statistics
Syntax
ORDINAL(count,argument,argument,…)
Arguments
count
is an integer that is less than or equal to the number of elements in the list of
arguments.
argument
is numeric. At least two arguments are required. An argument can consist of a
variable list, preceded by OF.
Details
th
The ORDINAL function sorts the list and returns the count argument in the list.
Examples
SAS Statements
Results
x1=ordinal(4,1,2,3,-4,5,6,7);
3
PATHNAME Function
Returns the physical name of a SAS data library or of an external file, or returns a blank
SAS File I/O
External Files
See: PATHNAME Function in the documentation for your operating environment.
Category:
Category:
Functions and CALL Routines
4
PATHNAME Function
735
Syntax
PATHNAME((fileref | libref) < ,search-ref>)
Arguments
fileref
specifies the fileref assigned to an external file.
libref
specifies the libref assigned to a SAS library.
search-ref
specifies whether to search for a fileref or a libref.
F
specifies a search for a fileref.
L
specifies a search for a libref.
Details
PATHNAME returns the physical name of an external file or SAS library, or blank if
fileref or libref is invalid.
If the name of a fileref is identical to the name of a libref, you can use the search-ref
argument to choose which reference you want to search. If you specify a value of F, SAS
searches for a fileref. If you specify a value of L, SAS searches for a libref.
If you do not specify a search-ref argument, and the name of a fileref is identical to
the name of a libref, PATHNAME searches first for a fileref. If a fileref does not exist,
PATHNAME then searches for a libref.
The default length of the target variable in the DATA step is 200 characters.
You can assign a fileref to an external file by using the FILENAME statement or the
FILENAME function.
You can assign a libref to a SAS library using the LIBNAME statement or the
LIBNAME function. Some operating environments allow you to assign a libref using
system commands.
Operating Environment Information: Under some operating environments, filerefs can
also be assigned by using system commands. For details, see the SAS documentation
for your operating environment. 4
736
PCTL Function
4
Chapter 4
Examples
This example uses the FILEREF function to verify that the fileref MYFILE is
associated with an external file. Then it uses PATHNAME to retrieve the actual name
of the external file:
data _null_;
length fname $ 100;
rc=fileref("myfile");
if (rc=0) then
do;
fname=pathname("myfile");
put fname=;
end;
run;
See Also
Functions:
“FEXIST Function” on page 551
“FILEEXIST Function” on page 554
“FILENAME Function” on page 555
“FILEREF Function” on page 557
Statements:
“LIBNAME Statement” on page 1381
“FILENAME Statement” on page 1257
PCTL Function
Computes percentiles
Category:
Descriptive Statistics
Syntax
PCTL<n>(percentage, value1<, value2, ...>)
Arguments
n
is a digit from 1 to 5 which specifies the definition of the percentile to be computed.
Default: definition 5
percentage
specifies the percentile to be computed.
Requirement:
is numeric where, 0
percentage 100.
Functions and CALL Routines
4
PDF Function
737
value
is numeric.
Details
The PCTL function returns the percentile of the nonmissing values corresponding to the
percentage. If percentage is missing, less than zero, or greater than 100, the PCTL
function generates an error message.
Note: The formula that is used in the PCTL function is the same as the function
that is used in PROC UNIVARIATE. For more information, see “SAS Elementary
Statistics Procedures” in Base SAS Procedures Guide. 4
Examples
SAS Statements
Results
lower_quartile=PCTL(25,2,4,1,3);
put lower_quartile;
1.5
percentile_def2=PCTL2(25,2,4,1,3);
put percentile_def2;
1
lower_tertile=PCTL(100/3,2,4,1,3);
put lower_tertile;
2
percentile_def3=PCTL3(100/3,2,4,1,3);
put percentile_def3;
2
median=PCTL(50,2,4,1,3);
put median;
2.5
upper_tertile=PCTL(200/3,2,4,1,3);
put upper_tertile;
3
upper_quartile=PCTL(75,2,4,1,3);
put upper_quartile;
3.5
PDF Function
Computes probability density (mass) functions
Category: Probability
Alias:
PMF
Syntax
PDF (’dist’,quantile,parm-1, ...,parm-k)
738
PDF Function
4
Chapter 4
Arguments
’dist’
is a character string 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’
Wald (inverse Gaussian)
’WALD’|’IGAUSS’
Weibull
’WEIBULL’
Note: Except for T, F, and NORMALMIX, you can minimally identify any
distribution by its first four characters. 4
quantile
is a numeric random variable.
parm-1,...,parm-k
are optional shape, location, or scale parameters that are appropriate for the specific
distribution.
See:
“Details” on page 739 for complete information about these parameters
Functions and CALL Routines
4
PDF Function
Details
Bernoulli Distribution
PDF(’BERNOULLI’,x,p)
where
x
is a numeric random variable.
p
is a numeric probability of success.
Range: 0 ≤ p ≤ 1
The PDF function for the Bernoulli distribution returns the probability density
function of a Bernoulli distribution, with probability of success equal to p. The PDF
function is evaluated at the value x. The equation follows:
00
P DF BERN ; x; p
Note:
0
1
=
8
0
>
>
<1
0
>
>
:p
0
0p
x<0
x=0
0<x<1
x=1
x>1
There are no location or scale parameters for this distribution.
Beta Distribution
PDF(’BETA’,x,a,b<,l,r>)
where
x
is a numeric random variable.
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: 0
Range: r > l
4
739
740
PDF Function
4
Chapter 4
The PDF function for the beta distribution returns the probability density function of
a beta distribution, with shape parameters a and b. The PDF function is evaluated at
the value x. The equation follows:
00
P DF BET A ; x; a; b; l; r
Note:
0
1
=
(0
1
(a;b)
0
0l is forced to be
The quantity xr0
l
x<1
0l)a01 (ax+0b0r1)b01 l x r
(r 0l )
x>r
(x
xr00ll
1 0 2.
4
Binomial Distribution
PDF(’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.
Range: n = 0, 1, ...
The PDF function for the binomial distribution returns the probability density
function of a binomial distribution, with parameters p and n, which is evaluated at the
value m. The equation follows:
00
P DF BINOM ; m; p; n
Note:
0
1
8
<0
=:
0
n m
n0m
m p (1 0 p)
m<0
0mn
m>n
There are no location or scale parameters for the binomial distribution.
4
Functions and CALL Routines
4
PDF Function
Cauchy Distribution
PDF(’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 PDF function for the Cauchy distribution returns the probability density
function of a Cauchy distribution, with the location parameter and the scale
parameter . The PDF function is evaluated at the value x. The equation follows:
P DF
00
CAU CHY ; x; ; 0
1
=
1
2 + ( x
Chi-Square Distribution
PDF(’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
!
0 )2
741
742
PDF Function
4
Chapter 4
The PDF function for the chi-square distribution returns the probability density
function of a chi-square distribution, with df degrees of freedom and non-centrality
parameter nc. The PDF function is evaluated at the value x. This function accepts
non-integer degrees of freedom. If nc is omitted or equal to zero, the value returned is
from the central chi-square distribution. The following equation describes the PDF
function of the chi–square distribution,
(0
P
x<0
1
()
0
P DF CHISQ ; x; v; =
e j ! pc (x; v + 2j ) x 0
00
1
0
j
2
=
2
j 0
where pc(.,.) denotes the density from the central chi-square distribution:
pc (x; a) = pg
x
2
;
a
2 2
and where pg(y,b) is the density from the gamma distribution, which is given by
pg (y; b) =
0 ( b)
e0y y b01
Exponential Distribution
PDF(’EXPONENTIAL’,x <, >)
where
x
is a numeric random variable.
is a scale parameter.
Default: 1
Range: > 0
The PDF function for the exponential distribution returns the probability density
function of an exponential distribution, with the scale parameter . The PDF function
is evaluated at the value x. The equation follows:
00
1
P DF EXP O ; x; 0
=
n
0
exp
1
0 x1
0
x<0
x0
Functions and CALL Routines
4
PDF Function
743
F Distribution
PDF(’F’,x,ndf,ddf<,nc>)
where
x
is a numeric random variable.
ndf
is a numeric numerator degrees of freedom parameter.
Range: ndf > 0
ddf
is a numeric denominator degrees of freedom parameter.
Range: ddf > 0
nc
is a numeric non-centrality parameter.
Range: nc ≥ 0
The PDF function for the F distribution returns the probability density function of an
F distribution, with ndf numerator degrees of freedom, ddf denominator degrees of
freedom, and non-centrality parameter nc. The PDF function is evaluated at the value
x. This PDF 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. The
following equation describes the PDF function of the F distribution,
(0
P
1 0 ()
P DF F ; x; v1 ; v2 ; =
e j pf (f; v
00
0
1
j =0
x<0
j
2
2
1
!
+ 2j; v2 )
x
0
where pf(f,u1,u2) is the density from the central F distribution with
pf (f; u1 ; u2 ) = pB
u1 f
u1 u2
; ;
uf + u2 2 2
u 1 u2
(u2 + u1 f )
2
and where pB(x,a,b) is the density from the standard beta distribution.
Note:
There are no location or scale parameters for the F distribution.
4
744
PDF Function
4
Chapter 4
Gamma Distribution
PDF(’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 PDF function for the gamma distribution returns the probability density
function of a gamma distribution, with the shape parameter a and the scale parameter
. The PDF function is evaluated at the value x. The equation follows:
00
1
P DF GAMMA ; x; a; 0
=
0
1
a 0(a)
xa01 exp
0 x1
0
x<0
x0
Geometric Distribution
PDF(’GEOMETRIC’,m,p)
where
m
is a numeric random variable that denotes the number of failures.
Range: m ≥ 0
p
is a numeric probability of success.
Range: 0 ≤ p ≤ 1
The PDF function for the geometric distribution returns the probability density
function of a geometric distribution, with parameter p. The PDF function is evaluated
at the value m. The equation follows:
00
P DF GEOM ; m; p
Note:
0
1
n
m<0
= 0p (1 0 p)m m
0
There are no location or scale parameters for this distribution.
4
Functions and CALL Routines
4
PDF Function
745
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 PDF function for the hypergeometric distribution returns the probability density
function of an extended hypergeometric distribution, with population size N, number of
items R, sample size n, and odds ratio o. The PDF function is evaluated at the value x.
If o is omitted or equal to 1, the value returned is from the usual hypergeometric
distribution. The equation follows:
00
P DF 8HY P ER ; x; N; R; n; o
0
0
>
>
>
>
>
>
<
R
x
minP
(R;n)
>
>
>
>
>
>
: j=max(0;R+n0N )
0
N 0R
n0x
1
=
ox
x < max (0; R + n 0 N )
max (0; R + n 0 N ) x min (R; n)
R N 0 R oj
j
n0j
x > min (R; n)
746
PDF Function
4
Chapter 4
Laplace Distribution
PDF(’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 PDF function for the Laplace distribution returns the probability density
function of the Laplace distribution, with the location parameter and the scale
parameter . The PDF function is evaluated at the value x. The equation follows:
P DF
00
1
LAP LACE ; x; ; 0
=
1
exp
2
x
j
0 j Logistic Distribution
PDF(’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 PDF function for the logistic distribution returns the probability density function
of a logistic distribution, with the location parameter and the scale parameter . The
PDF function is evaluated at the value x. The equation follows:
P DF
00
1
LOGIST IC 0; x; ; =
1
0
0 112
1 + exp x0
Functions and CALL Routines
4
PDF Function
Lognormal Distribution
PDF(’LOGNORMAL’,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 PDF function for the lognormal distribution returns the probability density
function of a lognormal distribution, with the location parameter and the scale
parameter . The PDF function is evaluated at the value x. The equation follows:
P DF
00
1
LOGN ; x; ; 0
=
0
p
1
x 2
exp
0
x0
0 x>0
(log(x) )2
22
Negative Binomial Distribution
PDF(’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 PDF function for the negative binomial distribution returns the probability
density function of a negative binomial distribution, with probability of success p and
number of successes n. The PDF function is evaluated at the value m. The equation
follows:
0
1
(0
PDF NEGB ; m;p; n = pn
0
0
m<0
n + m 0 1 (1 0 p)m m 0
m
Note: There are no location or scale parameters for the negative binomial
distribution. 4
747
748
PDF Function
4
Chapter 4
Normal Distribution
PDF(’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 PDF function for the normal distribution returns the probability density function
of a normal distribution, with the location parameter and the scale parameter . The
PDF function is evaluated at the value x. The equation follows:
P DF
00
1
N ORM AL ; x; ; 0
= p
1
2
exp
2
0
)
0 22
(x
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
i=n
P
i=1
Range: p = 0, 1, ...
m
s
is the n means m1; m2 ; . . . ; mn.
is the n standard deviations s1 ; s2 ; . . . ; sn .
Range: s > 0
pi = 1 .
!
Functions and CALL Routines
4
PDF Function
749
The PDF 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:
00
P DF NORMALMIX ; x; n; p; m; s
0
1
=
i=n
X
=1
00
pi P DF NORMAL ; x; mi; si
0
1
i
Note: There are no location or scale parameters for the normal mixture
distribution. 4
Pareto Distribution
PDF(’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 PDF function for the Pareto distribution returns the probability density function
of a Pareto distribution, with the shape parameter a and the scale parameter k. The
PDF function is evaluated at the value x. The equation follows:
00
P DF P ARET O ; x; a; k
0
1
=
00 1
a
k a+1
k
x
x<k
xk
Poisson Distribution
PDF(’POISSON’,n,m)
where
n
is an integer random variable.
Range: n= 0, 1, ...
m
is a numeric mean parameter.
Range: m > 0
The PDF function for the Poisson distribution returns the probability density
function of a Poisson distribution, with mean m. The PDF function is evaluated at the
value n. The equation follows:
00
1
P DF P OISSON ; n; m
0
=
n
0
e0m mn
n
!
n<0
n0
750
PDF Function
4
Chapter 4
Note:
There are no location or scale parameters for the Poisson distribution.
4
T Distribution
PDF(’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 PDF function for the T distribution returns the probability density function of a
T distribution, with degrees of freedom df and non-centrality parameter nc. The PDF
function is evaluated at the value x. This PDF function accepts non-integer degrees of
freedom. If nc is omitted or equal to zero, the value returned is from the central T
distribution. The equation follows:
00
P DF T ; t; v; 0
1
=
1
0 1
1
2( 2 v01) 0 1 v
2
Note:
Z1
xv01 e0 2 x
1 2
0
p1
e0 2 ( pv 0 )
1
2
tx
2
pxv dx
There are no location or scale parameters for the T distribution.
4
Uniform Distribution
PDF(’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 PDF function for the uniform distribution returns the probability density
function of a uniform distribution, with the left location parameter l and the right
location parameter r. The PDF function is evaluated at the value x. The equation
follows:
P DF
00
U N IF ORM 0 ; x; l; r
1
(
=
0
1
r0l
0
x<l
l x
x>r
r
Functions and CALL Routines
4
PDF Function
751
Wald (Inverse Gaussian) Distribution
PDF(’WALD’,x,d)
PDF(’IGAUSS’,x,d)
where
x
is a numeric random variable.
d
is a numeric shape parameter.
Range: d > 0
The PDF function for the Wald distribution returns the probability density function
of a Wald distribution, with shape parameter d, which is evaluated at the value x. The
equation follows:
00
P DF W ALD ; x; d
Note:
0
1
=
(
0q
0 d
d
2x3 exp
2x + d
0
d1
0 2x
x0
x>0
There are no location or scale parameters for the Wald distribution.
4
Weibull Distribution
PDF(’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 PDF function for the Weibull distribution returns the probability density
function of a Weibull distribution, with the shape parameter a and the scale parameter
. The PDF function is evaluated at the value x. The equation follows:
00
P DF W EIBULL ; x; a; 0
1
<0
= 0exp 00 0 x 1a1 a 0 x 1a01 xx 0
Examples
SAS Statements
Results
y=pdf(’BERN’,0,.25);
0.75
y=pdf(’BERN’,1,.25);
0.25
y=pdf(’BETA’,0.2,3,4);
1.2288
752
PEEK Function
4
Chapter 4
SAS Statements
Results
y=pdf(’BINOM’,4,.5,10);
0.20508
y=pdf(’CAUCHY’,2);
0.063662
y=pdf(’CHISQ’,11.264,11);
0.081686
y=pdf(’EXPO’,1);
0.36788
y=pdf(’F’,3.32,2,3);
0.054027
y=pdf(’GAMMA’,1,3);
0.18394
y=pdf(’HYPER’,2,200,50,10);
0.28685
y=pdf(’LAPLACE’,1);
0.18394
y=pdf(’LOGISTIC’,1);
0.19661
y=pdf(’LOGNORMAL’,1);
0.39894
y=pdf(’NEGB’,1,.5,2);
0.25
y=pdf(’NORMAL’,1.96);
0.058441
y=pdf(’NORMALMIX’,2.3,3,.33,.33,.34,
.5,1.5,2.5,.79,1.6,4.3);
0.1166
y=pdf(’PARETO’,1,1);
1
y=pdf(’POISSON’,2,1);
0.18394
y=pdf(’T’,.9,5);
0.24194
y=pdf(’UNIFORM’,0.25);
1
y=pdf(’WALD’,1,2);
0.56419
y=pdf(’WEIBULL’,1,2);
0.73576
PEEK Function
Stores the contents of a memory address into a numeric variable on a 32–bit platform
Category:
Restriction:
Special
Use on 32–bit platforms only.
Syntax
PEEK(address<,length>)
Arguments
address
specifies the memory address.
Functions and CALL Routines
4
PEEK Function
753
length
specifies the data length.
Default: a 4-byte address pointer
Range: 2 to 8
Details
If you do not have access to the memory storage location that you are requesting, the
PEEK function returns an "Invalid argument" error.
You cannot use the PEEK 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 PEEK, change the applications and use PEEKLONG instead. You
can use PEEKLONG on both 32–bit and 64–bit platforms.
Comparisons
The PEEK function stores the contents of a memory address into a numeric variable.
The PEEKC function stores the contents of a memory address into a character variable.
Note: SAS recommends that you use PEEKLONG instead of PEEK because
PEEKLONG can be used on both 32–bit and 64–bit platforms. 4
Examples
The following example, specific to the z/OS operating environment, returns a numeric
value that represents the address of the Communication Vector Table (CVT).
data _null_;
/* 16 is the location of the CVT address */
y=16;
x=peek(y);
put ’x= ’ x hex8.;
run;
See Also
Functions:
“ADDR Function” on page 311
“PEEKC Function” on page 754
CALL Routine:
“CALL POKE Routine” on page 369
754
PEEKC Function
4
Chapter 4
PEEKC Function
Stores the contents of a memory address in a character variable on a 32–bit platform
Category:
Special
Restriction:
Use on 32–bit platforms only.
Syntax
PEEKC(address<,length>)
Arguments
address
specifies the memory address.
length
specifies the data length.
Default: 8, unless the variable length has already been set (by the LENGTH
statement, for example)
Range:
1 to 32,767
Details
If you do not have access to the memory storage location that you are requesting, the
PEEKC function returns an "Invalid argument" error.
You cannot use the PEEKC 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 PEEKC, change the applications and use PEEKCLONG instead.
You can use PEEKCLONG on both 32–bit and 64–bit platforms.
Comparisons
The PEEKC function stores the contents of a memory address into a character variable.
The PEEK function stores the contents of a memory address into a numeric variable.
Note: SAS recommends that you use PEEKCLONG instead of PEEKC because
PEEKCLONG can be used on both 32–bit and 64–bit platforms. 4
Functions and CALL Routines
4
PEEKC Function
755
Examples
Example 1: Listing ASCB Bytes
The following example, specific to the z/OS operating
environment, uses both PEEK and PEEKC, and prints the first four bytes of the
Address Space Control Block (ASCB).
data _null_;
length y $4;
/* 220x is the location of the ASCB pointer */
x=220x;
y=peekc(peek(x));
put ’y= ’ y;
run;
Example 2: Creating a DATA Step View
This example, specific to the z/OS operating
environment, also uses both the PEEK and PEEKC functions. It creates a DATA step
view that accesses the entries in the Task Input Output Table (TIOT). The PRINT
procedure is then used to print the entries. Entries in the TIOT include the three
components outlined in the following list. In this example, TIOT represents the starting
address of the TIOT entry.
TIOT+4
is the DDname. This component takes up 8 bytes.
TIOT+12
is a 3-byte pointer to the Job File Control Block (JFCB).
TIOT+134
is the volume serial number (volser) of the data set. This component
takes up 6 bytes.
Here is the program:
/*
/*
/*
/*
/*
/*
Create a DATA step view of the contents
of the TIOT. The code steps through each
TIOT entry to extract the DDname, JFCB,
and volser of each DDname that has been
allocated for the current task. The data
set name is also extracted from the JFCB.
data save.tiot/view=save.tiot;
length ddname $8 volser $6 dsname $44;
/* Get the TCB (Task Control Block)address
/* from the PSATOLD variable in the PSA
/* (Prefixed Save Area). The address of
/* the PSA is 21CX. Add 12 to the address
/* of the TCB to get the address of the
/* TIOT. Add 24 to bypass the 24-byte
/* header, so that TIOTVAR represents the
/* start of the TIOT entries.
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
tiotvar=peek(peek(021CX)+12)+24;
/* Loop through all TIOT entries until the */
/* TIOT entry length (indicated by the
*/
/* value of the first byte) is 0.
*/
do while(peek(tiotvar,1));
/* Check to see whether the current TIOT
/* entry is a freed TIOT entry (indicated
*/
*/
756
PEEKC Function
4
Chapter 4
/* by the high order bit of the second
/* byte of the TIOT entry). If it is not
/* freed, then proceed.
*/
*/
*/
if peek(tiotvar+1,1)NE’l.......’B then do;
ddname=peekc(tiotvar+4);
jfcb=peek(tiotvar+12,3);
volser=peekc(jfcb+134);
/* Add 16 to the JFCB value to get */
/* the data set name. The data set */
/* name is 44 bytes.
*/
dsname=peekc(jfcb+16);
output;
end;
/*
/*
/*
/*
/*
/*
Increment the TIOTVAR value to point
to the next TIOT entry. This is done
by adding the length of the current
TIOT entry (indicated by first byte
of the entry) to the current value
of TIOTVAR.
*/
*/
*/
*/
*/
*/
tiotvar+peek(tiotvar,1);
end;
/* The final DATA step view does not
*/
/* contain the TIOTVAR and JFCB variables. */
keep ddname volser dsname;
run;
/* Print the TIOT entries.
*/
proc print data=save.tiot uniform width=minimum;
run;
In the PROC PRINT statement, the UNIFORM option ensures that each page of the
output is formatted exactly the same way. WIDTH=MINIMUM causes the PRINT
procedure to use the minimum column width for each variable on the page. The column
width is defined by the longest data value in that column.
See Also
CALL Routine:
“CALL POKE Routine” on page 369
Functions:
“ADDR Function” on page 311
“PEEK Function” on page 752
Functions and CALL Routines
4
PEEKCLONG Function
757
PEEKCLONG Function
Stores the contents of a memory address in a character variable on 32-bit and 64-bit platforms
Category: Special
See:
PEEKCLONG Function in the documentation for your operating environment.
Syntax
PEEKCLONG(address< ,length>)
Arguments
address
specifies a character string that is the pointer address.
length
specifies the length of the character data.
Default: 8
Range: 1 to 32,767
Details
If you do not have access to the memory storage location that you are requesting, the
PEEKCLONG function returns an “Invalid argument” error.
Comparisons
The PEEKCLONG function stores the contents of a memory address in a character
variable.
The PEEKLONG function stores the contents of a memory address in a numeric
variable. It assumes that the input address refers to an integer in memory.
Examples
Example 1: Example for a 32-bit Platform
address for the character variable Z.
data _null_;
x=’ABCDE’;
y=addrlong(x);
z=peekclong(y,2);
put z=;
run;
The output from the SAS log is: z=AB
The following example returns the pointer
758
PEEKLONG Function
4
Chapter 4
Example 2: Example for a 64-bit Platform
The following example, specific to the z/OS
operating environment, returns the pointer address for the character variable Y.
data _null_;
length y $4;
x220addr=put(220x,pib4.);
ascb=peeklong(x220addr);
ascbaddr=put(ascb,pib4.);
y=peekclong(ascbaddr);
run;
The output from the SAS log is: y=’ASCB’
See Also
Function:
“PEEKLONG Function” on page 758
PEEKLONG Function
Stores the contents of a memory address in a numeric variable on 32-bit and 64-bit platforms
Category:
See:
Special
PEEKLONG Function in the documentation for your operating environment
Syntax
PEEKLONG(address< ,length>)
Arguments
address
specifies a character string that is the memory address.
length
specifies the length of the character data.
Default: 4 on 32-bit machines; 8 on 64-bit machines.
Range:
1-4 on 32-bit machines; 1-8 on 64-bit machines.
Functions and CALL Routines
4
PEEKLONG Function
759
Details
If you don’t have access to the memory storage location that you are requesting, the
PEEKLONG function returns an “Invalid argument” error.
Comparisons
The PEEKLONG function stores the contents of a memory address in a numeric
variable. It assumes that the input address refers to an integer in memory.
The PEEKCLONG function stores the contents of a memory address in a character
variable. It assumes that the input address refers to character data.
Examples
Example 1: Example for a 32-bit Platform
The following example returns the pointer
address for the numeric variable Z.
data _null_;
length y $4;
y=put(1,IB4.);
addry=addrlong(y);
z=peeklong(addry,4);
put z=;
run;
The output from the SAS log is: z=1
Example 2: Example for a 64-bit Platform
The following example, specific to the z/OS
operating environment, returns the pointer address for the numeric variable X.
data _null_;
x=peeklong(put(16,pib4.));
put x=hex8.;
run;
The output from the SAS log is: x=00FCFCB0
See Also
Function:
“PEEKCLONG Function” on page 757
760
PERM Function
4
Chapter 4
PERM Function
Computes the number of permutations of n items taken r at a time
Category:
Mathematical
Syntax
PERM(n<,r>)
Arguments
n
is an integer that represents the total number of elements from which the sample is
chosen.
r
is an optional integer value that represents the number of chosen elements. If r is
omitted, the function returns the factorial of n.
Restriction: r ≤ n
Details
The mathematical representation of the PERM function is given by the following
equation:
P ERM (n; r) =
(n
n!
0 r )!
with n ≥ 0, r ≥ 0, and n≥ r.
If the expression cannot be computed, a missing value is returned.
Examples
SAS Statements
Results
x=perm(5,1);
5
x=perm(5);
120
x=perm(5,2)
20
Functions and CALL Routines
4
POINT Function
761
See Also
Functions:
“COMB Function” on page 462
“FACT Function” on page 541
POINT Function
Locates an observation identified by the NOTE function
Category: SAS File I/O
Syntax
POINT(data-set-id,note-id)
Arguments
data-set-id
specifies the data set identifier that the OPEN function returns.
note-id
specifies the identifier assigned to the observation by the NOTE function.
Details
POINT returns 0 if the operation was successful, ≠0 if it was not successful. POINT
prepares the program to read from the SAS data set. The Data Set Data Vector is not
updated until a read is done using FETCH or FETCHOBS.
Examples
This example calls NOTE to obtain an observation ID for the most recently read
observation of the SAS data set MYDATA. It calls POINT to point to that observation,
and calls FETCH to return the observation marked by the pointer.
%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));
...more macro statements...
%let rc=%sysfunc(close(&dsid));
762
POISSON Function
4
Chapter 4
See Also
Functions:
“DROPNOTE Function” on page 532
“NOTE Function” on page 712
“OPEN Function” on page 732
POISSON Function
Returns the probability from a Poisson distribution
Category:
See:
Probability
“CDF Function” on page 434
Syntax
POISSON(m,n)
Arguments
m
is a numeric mean parameter.
Range:
m≥0
n
is an integer random variable.
Range:
n≥0
Details
The POISSON function returns the probability that an observation from a Poisson
distribution, with mean m, is less than or equal to n. To compute the probability that
an observation is equal to a given value, n, compute the difference of two probabilities
from the Poisson distribution for n and n− .
Examples
SAS Statements
Results
x=poisson(1,2);
0.9196986029
Functions and CALL Routines
4
PROBBETA Function
PROBBETA Function
Returns the probability from a beta distribution
Category: Probability
See:
“CDF Function” on page 434
Syntax
PROBBETA(x,a,b)
Arguments
x
is a numeric random variable.
Range: 0 ≤ x ≤ 1
a
is a numeric shape parameter.
Range: a > 0
b
is a numeric shape parameter.
Range: b > 0
Details
The PROBBETA function returns the probability that an observation from a beta
distribution, with shape parameters a and b, is less than or equal to x.
Example
SAS Statements
Results
x=probbeta(.2,3,4);
0.09888
763
764
PROBBNML Function
4
Chapter 4
PROBBNML Function
Returns the probability from a binomial distribution
Probability
See: “CDF Function” on page 434, “PDF Function” on page 737
Category:
Syntax
PROBBNML(p,n,m)
Arguments
p
is a numeric probability of success parameter.
RANGE: 0 ≤ p ≤ 1
n
is an integer number of independent Bernoulli trials parameter.
RANGE: n > 0
m
is an integer number of successes random variable.
RANGE: 0 ≤ m ≤ n
Details
The PROBBNML function returns the probability that an observation from a binomial
distribution, with probability of success p, number of trials n, and number of successes
m, is less than or equal to m. To compute the probability that an observation is equal to
a given value m, compute the difference of two probabilities from the binomial
distribution for m and m−1 successes.
Examples
SAS Statements
Results
x=probbnml(0.5,10,4);
0.376953125
Functions and CALL Routines
4
PROBBNRM Function
765
PROBBNRM Function
Computes a probability from the bivariate normal distribution
Category: Probability
Syntax
PROBBNRM(x, y, r)
Arguments
x
is a numeric variable.
y
is a numeric variable.
r
is a numeric correlation coefficient.
Range: -1 ≤ r ≤ 1
Details
The PROBBNRM function returns the probability that an observation (X, Y) from a
standardized bivariate normal distribution with mean 0, variance 1, and a correlation
coefficient r, is less than or equal to (x, y). That is, it returns the probability that X≤x
and Y≤y. The following equation describes the PROBBNRM function, where u and v
represent the random variables x and y, respectively:
Zx Zy
1
u 2 0 2ruv + v 2
PROBBNRM (x; y; r) = p
exp 0
2 (1 0 r 2 )
2 1 0 r2 0101
Examples
SAS Statements
Result
p=probbnrm(.4, -.3, .2);
put p;
0.2783183345
dv du
766
PROBCHI Function
4
Chapter 4
PROBCHI Function
Returns the probability from a chi-squared distribution
Probability
See: “CDF Function” on page 434
Category:
Syntax
PROBCHI(x,df< ,nc>)
Arguments
x
is a numeric random variable.
Range: x ≥ 0
df
is a numeric degrees of freedom parameter.
Range: df > 0
nc
is an optional numeric noncentrality parameter.
Range:
nc ≥ 0
Details
The PROBCHI function returns the probability that an observation from a chi-square
distribution, with degrees of freedom df and noncentrality parameter nc, is less than or
equal to x. This function accepts a nonintege