SAS® and R

Best of Both Worlds

The flexibility of PRX functions in SAS

with 3 comments

PRX here stands for Perl Regular Expression.  SAS regular expressions (the RX functions) and Perl Regular Expressions (the PRX functions) are a set of functions added to SAS since version 9.  However, many SAS users are unfamiliar with SAS/Perl Regular Expressions.  This tool is very useful and flexible because it enables you to locate patterns in text strings, and it sometimes provide a much more compact solution to a complicated string manipulation task.

Here is one example.  Function PRXCHANGE substitutes one string for another.  Say in this dataset, you want to compress the long form of VISIT variable to a short form, ridding the words ‘Observation’ and ‘Treatment’.
prxchange 

If you use PRXCHANGE function, there is only one line of code.  And you will get the desired result.

/* PRXCHANGE demo */
VIS=trim(left(prxchange('s/(observation|treatment)//io',-1,visit)))

prxchange function

I will introduce more examples in my next blog post.

Advertisements

Written by sasandr

April 25, 2012 at 1:32 pm

Posted in SAS

Tagged with ,

3 Responses

Subscribe to comments with RSS.

  1. This is pretty cool. Thanks.

    Tessie

    April 30, 2012 at 8:57 am

  2. Neat, but also confusing.

    Xiao

    May 1, 2012 at 11:40 am

  3. […] Let’s take a look at the example from post The flexibility of PRX functions in SAS: […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: