05-23-2014 03:04 PM
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
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:
05-23-2014 03:24 PM
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_;
GenericName=DRUGABCD FormalName=DRUGABCDEFG Gen_Name=DRUGABCDEFG _ERROR_=0 _N_=1
NOTE: The data set WORK.HAVE has 1 observations and 3 variables.
1680 data temp1;
1681 set have;
1682 x = index(FormalName,(substr(strip(gen_name),1,(length(GenericName)))));
1683 put x;
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEMP1 has 1 observations and 4 variables.