SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
lillymaginta1
Obsidian | Level 7

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
PaigeMiller
Diamond | Level 26

@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
lillymaginta1
Obsidian | Level 7
I meant regardless if the word drug is listed as 'Drug' or 'drug' which is shown in the example above
PaigeMiller
Diamond | Level 26

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
singhsahab
Lapis Lazuli | Level 10
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;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 4 replies
  • 2810 views
  • 0 likes
  • 3 in conversation