BookmarkSubscribeRSS Feed
HockeyMom2508
Calcite | Level 5

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

4 REPLIES 4
jwillis
Quartz | Level 8

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.

HockeyMom2508
Calcite | Level 5

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

HockeyMom2508
Calcite | Level 5

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

THANK YOU!

Peter_C
Rhodochrosite | Level 12

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1176 views
  • 1 like
  • 3 in conversation