DATA Step, Macro, Functions and more

FindW Function a little help

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 119
Accepted Solution

FindW Function a little help

Hi,

 

I cannot figure out why this code is not returning antibiotics = 1 for the comment that has antibiotics in it.

 

Code below:

-----------------------

Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ;  
Libname myformat'/folders/myfolders/sasuser.v94' ; 
Options fmtsearch=(myformat) ;

Data review.antibiotics ; 

Set learn.Medical ; If FindW(Comment,'antibiotics','i') then antibiotics = 1 ; run ; proc print data=learn.medical noobs ; run ; proc print data=review.antibiotics noobs ; run ;

 Below are the results

Patno 	Clinic 	VisitDate 	Weight 	HR 	DX 	Comment 	antibiotics
001 	Mayo Clinic 	10/21/2006 	120 	78 	7 	Patient has had a persistent cough for 3 weeks 	.
003 	HMC 	09/01/2006 	166 	58 	8 	Patient placed on beta-blockers on 7/1/2006 	.
002 	Mayo Clinic 	10/01/2006 	210 	68 	9 	Patient has been on antibiotics for 10 days 	/*WHY ANTIBIOTICS = . NOT = 1?*/
004 	HMC 	11/11/2006 	288 	88 	9 	Patient advised to lose some weight 	.
007 	Mayo Clinic 	05/01/2006 	180 	54 	7 	This patient is always under high stress 	.
050 	HMC 	07/06/2006 	199 	60 	123 	Refer this patient to mental health for evaluation 	

Accepted Solutions
Solution
2 weeks ago
PROC Star
Posts: 1,282

Re: FindW Function a little help

Posted in reply to ManitobaMoose

I gave you the right syntax earlier. here again

 

If FindW(Comment,'antibiotics',' ','i') then antibiotics = 1 ; 

View solution in original post


All Replies
PROC Star
Posts: 1,282

Re: FindW Function a little help

[ Edited ]
Posted in reply to ManitobaMoose

because 'i' is in place of delimiter specification in your code rather than in place of modifier to ignore case sensitivity

 

This will work Findw(comment,'antibiotics')

 

or Findw(k,'antibiotics',' ','i');

Frequent Contributor
Posts: 119

Re: FindW Function a little help

Posted in reply to novinosrin

Ok. Thanks. Then, where would I put the 'i' ignore case modifier?

PROC Star
Posts: 1,282

Re: FindW Function a little help

Posted in reply to ManitobaMoose
If FindW(Comment,'antibiotics',' ','i') then antibiotics = 1 ; 
Super User
Posts: 22,818

Re: FindW Function a little help

Posted in reply to novinosrin

Or:

 

Findw(comment,'antibiotics', , 'i')

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p16rdsa30vmm43n1ej4936nwa01t.htm&...

 

FINDW(stringwordcharacter(s)modifier(s) <, start-position>)

 

modifier

specifies a character constant, variable, or expression in which each non-blank character modifies the action of the FINDW function.

Tip
If you use the modifier argument, then it must be positioned after the character argument.
Frequent Contributor
Posts: 119

Re: FindW Function a little help

Hi,

 

I am still getting the same results with the code below:

 

Data review.antibiotics ; 
	Set learn.Medical ; 
	If Findw(Comment,'antibiotics', ,'i') then antibiotics = 1 ; /*output review.antibiotics*/ ;  
run ; 

proc print data=learn.medical noobs ; 
run ; 
proc print data=review.antibiotics noobs ; 
run ;

Patno Clinic VisitDate Weight HR DX Comment antibiotics

001Mayo Clinic10/21/2006120787Patient has had a persistent cough for 3 weeks.
003HMC09/01/2006166588Patient placed on beta-blockers on 7/1/2006.
002Mayo Clinic10/01/2006210689Patient has been on antibiotics for 10 days.
004HMC11/11/2006288889Patient advised to lose some weight.
007Mayo Clinic05/01/2006180547This patient is always under high stress.
050HMC07/06/200619960123Refer this patient to mental health for evaluation.
Solution
2 weeks ago
PROC Star
Posts: 1,282

Re: FindW Function a little help

Posted in reply to ManitobaMoose

I gave you the right syntax earlier. here again

 

If FindW(Comment,'antibiotics',' ','i') then antibiotics = 1 ; 
Frequent Contributor
Posts: 119

Re: FindW Function a little help

Posted in reply to novinosrin

Thanks!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 153 views
  • 2 likes
  • 3 in conversation