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
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;
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;
FINDW()?
if findw(lowcase(drugname), "sodium") > 0;
@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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.