Help using Base SAS procedures

Need to find like name in a variable

Reply
New Contributor
Posts: 3

Need to find like name in a variable

So.... I am having an issue trying to find a character string within another variable.  The problem is that the string that I am looking to find is in another variable.

My data looks like this:

Generic Name          FormalName  

drugABCD               drugABCDEFG  

I need to look in "formal name" to find what is in "generic name".

Here is the code that I used but it is NOT working:

code.jpg

Regular Contributor
Posts: 217

Re: Need to find like name in a variable

Posted in reply to HockeyMom2508

Dear HMom;

Please clarify for me your variable names.  Your example name and the names in your code confused me.  I'm assuming that you want to find out if the value in GenericName is in the variable FormalName.

1654  data have;
1655     length GenericName FormalName Gen_Name $20.;
1656     GenericName = upcase('drugABCD');
1657     FormalName  = upcase('drugABCDEFG');
1658     Gen_name    = scan(FormalName,1,' ');
1659  put _all_;
1660  run;

GenericName=DRUGABCD FormalName=DRUGABCDEFG Gen_Name=DRUGABCDEFG _ERROR_=0 _N_=1
NOTE: The data set WORK.HAVE has 1 observations and 3 variables.


1679
1680  data temp1;
1681      set have;
1682    x = index(FormalName,(substr(strip(gen_name),1,(length(GenericName)))));
1683  put x;
1684  run;

1
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEMP1 has 1 observations and 4 variables.

New Contributor
Posts: 3

Re: Need to find like name in a variable

I need to be sure that whatever is contained in the variable gen_name on that particular row is somewhere in prod_serv_nm

New Contributor
Posts: 3

Re: Need to find like name in a variable

Posted in reply to HockeyMom2508

I had to add in "strip"......

THANK YOU!

Valued Guide
Posts: 2,177

Re: Need to find like name in a variable

Posted in reply to HockeyMom2508

did you try the find() function?

e.g.

found =  find( prod_serv_nm, gen_name, 't' ) ;

the 't' directs the search to trim before hunting

Ask a Question
Discussion stats
  • 4 replies
  • 223 views
  • 1 like
  • 3 in conversation