/*** TIP 00400 ***/
 Match String Patterns

 I have a field which mixes addresses, cities and postal code etc. Is
 there any function or method that I can use to find out the only the
 postal code(a string pattern)?

 eg.

 Apt 16
 123 any street
 3456 any Ave.
 M5E 7B7 <-----needs to be identified
 L2T 9Y1 <-----needs to be identified
 New York
 Toronto

Solution provided by David Cassell Cassell.David@epa.gov If you have SAS 9.x , I suggest you look at the PRX... functions. It looks as if you want the following form: ^ start of field \s* (maybe with whitespace at the front) [A-Z] a letter from A to Z \d a digit [A-Z] A to Z again a space \d a digit [A-Z] A to Z again \d a digit \s* possible whitespace $ end of field So try the following code: data new; set YourData; if _n_=1 then do; re = prxparse('/^\s*[A-Z]\d[A-Z] \d[A-Z]\d\s*$/'); if missing (re) then stop; end; if prxmatch(re,YourNameField); run; This ought to pull out the desired records. /*** end of tip 00400 ***/