Help using Base SAS procedures

Searching string for multiple variations of a different string.

Reply
N/A
Posts: 0

Searching string for multiple variations of a different string.

I'm trying to take this code and do it in one shot. Instead of check 3 seperate times I want to know if it's possible to do it all in one line.

data temp;
length a b c 8 ;

a= 1 ;
b= 1 ;
c= 1 ;

if ( find(upcase(addr),'PO') > 0 ) Then a = 0 ;
if ( find(upcase(addr),'P O') > 0 ) Then b= 0 ;
if ( find(upcase(addr),'P.O.') > 0 ) Then c= 0 ;

run;


Thank you for any help
Jerry
Super Contributor
Super Contributor
Posts: 3,174

Re: Searching string for multiple variations of a different string.

The COMPRESS function comes to mind (to squeeze out unwanted characters within your test), given the limited example and conditions you have shown in your post.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Searching string for multiple variations of a different string.

Thanks for the tip. It helped me clean it up.
SAS Super FREQ
Posts: 8,742

Re: Searching string for multiple variations of a different string.

Hi:
Other considerations might be whether you want to search for PO or P.O. within the first 4 or 5 characters of the address or anywhere in the address. For example:
[pre]
P.O. Box 66
PO 333
P O 222
1234 Rumpole St
4567 Popopo Blvd.
[/pre]

You would probably want the first 3, but not the last 2 (if you're looking for PO boxes). In which case, the SUBSTRING function might help limit the search to the first 4 or 5 characters of the address.

cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 105 views
  • 0 likes
  • 3 in conversation