You are on page 1of 2

13/02/2022, 19:10 Practice

Print     

Challenge Practice: Using the CALL PRXSUBSTR Routine


The pg3.np_unstructured_codes table contains a single column (Column1) whose contents include
park codes and names. Extract the first occurrence of the park codes. Park codes are 3 to 10 uppercase
letters.

Reminder: If you restarted your SAS session, open and submit the libname.sas program in the course
files.

1. Open the p302p06.sas program in the practices folder. Run the program to view the Column1
values. The park codes follow a "C:" or "Code:" prefix. What are the characteristics of the codes?

The park codes consist of three or more uppercase letters enclosed in double quotation marks.

2. Modify the program.


Create a column named Expression that is equal to a Perl regular expression that includes at
least three uppercase letters followed by zero or more uppercase letters. Be sure to end the
expression with the letter o so that it is compiled only once.
Create a column named PatternID that uses the PRXPARSE function on the Expression
column to return a pattern identifier number.
Use the CALL PRXSUBSTR routine to find the expression (PatternID) in Column1 and
create a MyStart column and a MyLength column.

CALL PRXSUBSTR(pattern-identifier-number, source, position <,length>);

Note: Use the SAS documentation (SAS Functions and CALL Routines: Reference) to learn about
the CALL PRXSUBSTR routine.

data work.ParkCodes;

set pg3.np_unstructured_codes;

Expression='/[A-Z]{3}[A-Z]*/o';

PatternId=prxparse(Expression);

call prxsubstr(PatternID,Column1,MyStart,MyLength);

run;

title 'Park Codes from Unstructured Column';

proc print data=work.ParkCodes;

run;

title;

3. Run the program. What are the values of the MyStart and MyLength columns in row 1 and row 7?

In row 1, MyStart=10 and MyLength=4. In row 7, MyStart=7 and MyLength=6.

4. Use the SUBSTR function to create a column named ParkCode based on the MyStart and
MyLength columns.

/* p302p06_s.sas */

data work.ParkCodes;

set pg3.np_unstructured_codes;

Expression='/[A-Z]{3}[A-Z]*/o';

https://vle.sas.com/pluginfile.php/565533/mod_scorm/content/17/02/epg3m602_2_p_l3.htm 1/2
13/02/2022, 19:10 Practice
PatternId=prxparse(Expression);

call prxsubstr(PatternID,Column1,MyStart,MyLength);

ParkCode=substr(Column1,MyStart,MyLength);

run;

title 'Park Codes from Unstructured Column';

proc print data=work.ParkCodes;

run;

title;

5. Run the program and verify the ParkCode values. What are the values of ParkCode in rows 1 and
7?

In row 1, ParkCode=ADAM and in row7, ParkCode=AKEPMT.

Hide Solution

https://vle.sas.com/pluginfile.php/565533/mod_scorm/content/17/02/epg3m602_2_p_l3.htm 2/2

You might also like