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-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1901 views
  • 0 likes
  • 3 in conversation