Help using Base SAS procedures

Finding String

Posts: 74

Finding String

Hello all,

I am a situation where i have dataset with two variables name and alias:

Name Alias
xxx_999_aa 999
vvv_156_bb 156

My requirement is to find the alias in the name,so as per below i need to find if 999 or 156 is present in names.I tried using the FIND function like the following;

data test;
set a;
if x > 0 then delete;
but this does not seems working as the value of the x is getting assigned as 0.

Please help
Super User
Posts: 23,683

Re: Finding String

The alias might have trailing or leading blanks, and then you're searching for
' 999' or '999 ' rather than 999.

Try using the compress function on alias:

x=find(name, compress(alias));
y=find(name, alias);
Trusted Advisor
Posts: 2,124

Re: Finding String

without your log and contents it is hard to pinpoint. Some suggestions.

-- Make sure both variables are character.
-- Make sure the alias does not have either leading or trailing blanks in it (print alias with a hex format to see what SAS thinks is there).
-- You might try the code
to see if that helps.

Doc Muhlbaier
Posts: 74

Re: Finding String

Thank you all
Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation