Title: SAS v9, Enhancements
1SAS v9, Enhancements
- Prepared by Luigi Muro Consultant
- Bell Canada
2Enhancements to the FORMAT Procedure
Formats/Informats
- FORMAT and INFORMATS with longer names.
- 32 Characters for Numeric formats.
- 31 Characters for Character formats (allows for a
sign). - Note Not compatible with version 8
proc format value genderformat "1""Female"
"2""Male" NOTE Format
GENDERFORMAT has been output.
3Character Functions
New Character SAS Functions
STRIP Strips leading and trailing blanks from a
string 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
CATX Concatenates strings, removes leading and
trailing blanks, and inserts separators PROPCASE
Converts all words in an argument to proper case
CHAR Extracts a single character from a string
FIRST Extracts the first character from a string
4Concatenating Strings
Character Functions
- Have you ever used (concat), TRIM, LEFT, and
PUT functions.
Version 8 and below combine
trim(left(Char1)) left(Char2) remblank
s trim(left(put(1350.624, 8.2))) Version 9
(Reduce code complexity) combine catx( ,
Char1, Char2) remblanks strip(put(1350.624,
8.2))
5Macro Functions
CREATING MACRO VARIABLES Commonly include LEFT,
TRIM and PUT functions to make sure that the
macro variable value is constructed properly.
Version 8 and below call symput(Max,
trim(left(put(maxValue , 8.))) ) Version 9
CALL SYMPUTX handles left justification,
trimming, and character conversion. call
symputx( Max , maxValue)
6The PROPCASE Function
Character Functions
- The PROPCASE function returns a string in proper
(mixed) case.
Example line 'macro-generated line'
line1 PROPCASE(line, ' ') line2
PROPCASE(line, ' -') Result line1
Macro-generated Line line2 Macro-Generated Line
7Data step IN operator
- Integer ranges can be specified with an IN
operator - Version 8 and below
- A. if code in (3,7,8,9,10,11,15,19,20,21,22,23,24,
25) then put Found - B. if code 3 or (code gt 7 and code lt 11) or
code 15 or - (code gt 19 and code lt 25) ...
- C. if code 3 or (7 lt code lt 11) or code 15
or (19 lt code lt 25) ... - Version 9 (Reduce code complexity)
- if code in (3, 711, 15, 1925) then put Found
8Data step - Putlog
PUTLOG - Writes a message to the SAS log Data
_null_ file print put 'This goes to
OUTPUT window' putlog This message goes to
the LOG' putlog 'WARNING ...' Line
displayed as Green in log window putlog 'ERROR
... Line displayed as Red in log window
put 'This goes to OUTPUT window' run
Difference between Put and Putlog PUTLOG
explicitly writes to the SAS LOG. This means that
you can direct regular PUT statements to another
destination, and write to the log using PUTLOG
without the need to redirect output to the LOG
with a FILE LOG statement.
9Character Functions
- Extract a single character from a string using
CHAR and FIRST
- Version 8 and Below
- Data extract
- MarketingCode'FD12Q1320'
- Regionsubstr(MarketingCode, 5, 1)
- Productsubstr(MarketingCode, 1, 1)
- run
- Version 9
- Data extract
- MarketingCode'FD12Q1320'
- RegionCHAR(MarketingCode, 5)
- ProductFIRST(MarketingCode)
- Run
10PRX
- Perl regular expression (PRX) - Primary
functions
- PRXPARSE To define a Perl regular expression to
be used later by the other regular expression
functions. - Combination of alphanumeric characters, strings
and metacharacters. - PRXMATCH Locate the position in a string, where
a regular expression match is found. This
function returns the first position in a string.
If this pattern is not found, the function
returns a zero. - Other functions and call routines include
PRXSUBSTR, PRXPOSN, PRXNEXT, PRXPAREN - DATA _NULL_
- IF _N_ 1 THEN PATTERN_NUM
PRXPARSE("/cat/") - RETAIN PATTERN_NUM
- INPUT STRING 30.
- POSITION PRXMATCH(PATTERN_NUM,STRING)
- DATALINES
- ...
11PRX
- Perl regular expression (PRX) - Examples
12PRX
- Perl regular expression (PRX) - Examples
To use the PRX pattern specified with PRXPARSE
use PRXMATCH function . POSITION
PRXMATCH(PATTERN_NUM,STRING)
Interested in learning more. Excellent SUGI 29
paper _at_ http//www2.sas.com/proceedings/sugi29/265
-29.pdf Title An Introduction to Perl Regular
Expressions in SAS 9 Author Ron Cody, Robert
Wood Johnson Medical School, Piscataway, NJ