Date and Time Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Definition of a Date and Time Interval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Interval Names and SAS Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Incrementing Dates and Times by Using Multipliers and by Shifting Intervals . . . 31
Commonly Used Time Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Retail Calendar Intervals: ISO 8601 Compliant . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Custom Time Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Best Practices for Custom Interval Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Pattern Matching Using Perl Regular Expressions (PRX) . . . . . . . . . . . . . . . . . . . . 42
Definition of Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Definition of Perl Regular Expression (PRX) Functions and CALL Routines . . . . 43
Benefits of Using Perl Regular Expressions in the DATA Step . . . . . . . . . . . . . . . 43
Using Perl Regular Expressions in the DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Syntax of Perl Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Example 1: Validating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Example 2: Matching and Replacing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Example 3: Extracting a Substring from a String . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Example 4: Another Example of Extracting a Substring from a String . . . . . . . . . . 50
Writing Perl Debug Output to the SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Perl Artistic License Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Base SAS Functions for Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Definitions of Functions and CALL Routines
Definition of Functions
A SAS function is a component of the SAS programming language that can accept
arguments, perform a computation or other operation, and return a value. Functions can
return either numeric or character results. The value that is returned can be used in an
assignment statement or elsewhere in expressions. Many functions are included with
SAS, and you can write your own functions as well.
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. For more
information about these functions, see the documentation that pertains to the specific
SAS software product.
Definition of CALL Routines
A CALL routine alters variable values or performs other system functions. CALL
routines are similar to functions, but differ from functions in that you cannot use them in
assignment statements or expressions.
All SAS CALL routines are invoked with CALL statements. That is, the name of the
routine must appear after the keyword CALL in the CALL statement.
2 Chapter 1 • SAS Functions and CALL Routines