| www.sas.com > SAS UK > In the Know Homepage | Search | Contact Us |
|
|
|
|
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. In addition to the existing SAS regular expressions (RX), SAS 9 has introduced the ability to use Perl regular expression (PRX) functions and CALL routines to also manipulate character values. Perl is a scripting programming language that is similar to C in syntax and includes a number of popular Unix functions. It is most commonly used for developing CGI programs because of its excellent text manipulation facilities. Pattern matching enables searching and extracting multiple patterns from a character string as well as to make several substitutions in a string in one step. SAS uses a modified version of Perl as a pattern matching language to parse character strings. With the new Perl functions you can:
DATA Postcode_screening (drop=RE POSITION);
IF _N_ = 1 THEN DO ;
RE = PRXPARSE("/\RG|rg|Rg|rG(1|5|4)\ ?\w\w\w/");
IF MISSING(RE) THEN DO;
PUT "ERROR IN COMPILING REGULAR EXPRESSION";
STOP;
END;
END;
RETAIN RE;
INPUT POSTCODE $CHAR8.;
POSITION = PRXMATCH(RE,POSTCODE);
IF POSITION GT 0 THEN OUTPUT;
DATALINES;
RG30 3xy
Rg10 7uj
tg19 078
Rg15np
DG13 2wd
;
RUN;
PROC PRINT DATA=Postcode_screening NOOBS;
TITLE "List of Reading based postcodes only";
RUN;
Here is a list of the new PRX functions and Call routines:
Further documentation for SAS 9 can be found on the SAS Products and Solutions website at:
For more comprehensive examples on using Perl Regular expressions, please search the SAS OnlineDoc for: SAS 9 Language Reference: Concepts ' Pattern Matching Using SAS Regular Expressions (RX) and Perl Regular Expressions (PRX). Note: The above code has been tested using SAS 9.1.2 on the Windows operating system.
|