1
PharmaSUG 2019 - Paper AP-205
Quick Tips and Tricks: Perl Regular Expressions in SAS
®
Pratap S. Kunwar, Jinson Erinjeri, Emmes Corporation
ABSTRACT
Programming with text strings or patterns in SAS® can be complicated without the knowledge of Perl
regular expressions. Just knowing the basics of regular expressions (PRX functions) will sharpen
anyone's programming skills. Having attended a few SAS conferences lately, we have noticed that there
are few presentations on this topic and many programmers tend to avoid learning and applying the
regular expressions. Also, many of them are not aware of the capabilities of these functions in SAS. In
this presentation, we present quick tips on these expressions with various applications which will enable
anyone learn this topic with ease.
INTRODUCTION
SAS has numerous character (string) functions which are very useful in manipulating character fields.
Every SAS programmer is generally familiar with basic character functions such as SUBSTR, SCAN,
STRIP, INDEX, UPCASE, LOWCASE, CAT, ANY, NOT, COMPARE, COMPBL, COMPRESS, FIND,
TRANSLATE, TRANWRD etc. Though these common functions are very handy for simple string
manipulations, they are not built for complex pattern matching and search-and-replace operations.
Regular expressions (RegEx) are both flexible and powerful and are widely used in popular programming
languages such as Perl, Python, JavaScript, PHP, .NET and many more for pattern matching and
translating character strings. Regular expressions skills can be easily ported to other languages like
SQL., However, unlike SQL, RegEx itself is not a programming language, but simply defines a search
pattern that describes text.
Learning regular expressions starts with understanding of character classes and metacharacters.
Becoming skillful on this topic is not hard but RegEx can be intimidating at first as it is based on a system
of symbols (metacharacters) to describe a text pattern to read text, and this can be an obvious reason for
anyone to put it off.