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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.