BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta1
Obsidian | Level 7
data have;
infile cards ;
input ID   drugname ;	 
cards;
001 sodium benzoate 
001 oral sodium 
003 oral potassium 
004 oral oral Sodium 
004 Sodium 
;

I want to retain 1 if the word sodium exist anywhere in the variable "drugname". The word can be written in capital and small letters.

Output 

ID sodium 
001 1
001 1
003 0
004 1
004 1
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
infile cards ;
input ID   drugname & $20.;	 
cards;
001 sodium benzoate 
001 oral sodium 
003 oral potassium 
004 oral oral Sodium 
004 Sodium 
;

data want;
 set have;
 sodium=^^findw(drugname,'sodium',' ','i');
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

data have;
infile cards ;
input ID   drugname & $20.;	 
cards;
001 sodium benzoate 
001 oral sodium 
003 oral potassium 
004 oral oral Sodium 
004 Sodium 
;

data want;
 set have;
 sodium=^^findw(drugname,'sodium',' ','i');
run;
Reeza
Super User

FINDW()?

 

if findw(lowcase(drugname), "sodium") > 0;

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lefunctionsref&docsetTarg...

 


@lillymaginta1 wrote:
data have;
infile cards ;
input ID   drugname ;	 
cards;
001 sodium benzoate 
001 oral sodium 
003 oral potassium 
004 oral oral Sodium 
004 Sodium 
;

I want to retain 1 if the word sodium exist anywhere in the variable "drugname". The word can be written in capital and small letters.

Output 

ID sodium 
001 1
001 1
003 0
004 1
004 1

 

lillymaginta1
Obsidian | Level 7
Thank you both!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 996 views
  • 2 likes
  • 3 in conversation