- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-07-2021 07:47 AM
(2809 views)
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
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
--
Paige Miller
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I meant regardless if the word drug is listed as 'Drug' or 'drug' which is shown in the example above
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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...
--
Paige Miller
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;