Hi Everyone,
I want to retain 1 if the word 'drug' was found in a string, including upper and lower case words.
data have;
infile cards ;
input ID name ;
cards;
001 This is a drug
001 A drug
003 Drug
004 None
004 None
;
Output data
ID Name Var
001 This is a drug 1
001 A drug 1
003 Drug 1
004 None 0
004 None 0
@lillymaginta1 wrote:
Hi Everyone,
I want to retain 1 if the word 'drug' was found in a string, including upper and lower case words.
data have; infile cards ; input ID name ; cards; 001 This is a drug 001 A drug 003 Drug 004 None 004 None ;
Output data
ID Name Var 001 This is a drug 1 001 A drug 1 003 Drug 1 004 None 0 004 None 0
Not really sure what "including upper and lower case words" means here, and I don't want to guess. Does your data show an example? Does your data show an opposite example?
You can use the FINDW function, with the 'i' modifier which will ignore the case of the letters. Example: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lefunctionsref&docsetTarg...
data have;
infile cards ;
input ID $3. name $30. ;
if findw(name,'Drug',' ','i') then var=1;
else var=0;
cards;
001 This is a drug
001 A drug
003 Drug
004 None
004 None
;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.