LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 19 Feb 2009 16:27:34 -0600
Reply-To:   Joe Matise <snoopy369@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Joe Matise <snoopy369@GMAIL.COM>
Subject:   Re: index function, %let, and other things
Comments:   To: vamshidargoli@gmail.com
In-Reply-To:   <93d51524-0c02-43d7-94cc-163437ae9b9b@v18g2000pro.googlegroups.com>
Content-Type:   text/plain; charset=ISO-8859-1

Because compress (and the others) are data step functions, and %let is a macro element. The two are not compatible in that way. You should not be using %let here.

%let drugs101="MIRTAZAPINE BUPROPION PHENELZINE TRANYLCYPROMINE NEFAZODONE TRAZODONE ISOCARBOXAZID MAPOTILINE";

data test; hicldesc = 'PHENELZINE'; do i=1 to 8; info= index(hicldesc,compress(upcase(scan(&drugs101,i)))); if info > 0 then rxcat1=101; put hicldesc= info= rxcat1= i=; if rxcat1=101 then leave; end;

run;

There are also further improvements to be made, notably that you could just use FIND (or, INDEX) on the whole string at once if you don't care about which word it is. Also, why are you using index? Are you expecting to have partially complete data (do you want to match BUPROPI to BUPROPION for example, or PROPION to same, etc.)?

-Joe

On Thu, Feb 19, 2009 at 4:10 PM, <vamshidargoli@gmail.com> wrote:

> Hi > > I am trying to do something simple. I am not getting something, when > trying to make this code work. My objective is if a word in a variable > corresponmds to one of the words in a text string then create a flag. > > > data meds.meds_table17; > set meds.table17_26759; > > %let drugs101="MIRTAZAPINE BUPROPION PHENELZINE TRANYLCYPROMINE > NEFAZODONE > TRAZODONE ISOCARBOXAZID MAPOTILINE"; > %let drugs102=FLUOXETINE PAROXETINE VENLAFLAXINE DULOXETINE > REBOXETINE > FLUVOXAMINE CITALOPRAM EXCITALOPRAM DESVENLAFAXINE; > %let drugs103=IMIPRAMINE AMITRIPTYLINE DESIPRAMINE DOXEPIN > NORTRIPTYLINE PROPTRIPTYLINE > TRIMIPRAMINE AMOXAPINE CLOMIPRIMINE; > /* > wordCount = 1; > do while ( scan( &drugs101", wordCount) ^= ''); > wordCount+1; > end; > wordCount+(-1); > *put wordCount=;*/ > > do i=1 to 8; > %let chk="'"||compress(upcase(scan(&drugs101,i)))||"'"; > if index(hicldesc,&chk)~=0 then rxcat1=101; > > info=index(hicldesc,&chk) > put hicldesc= info= chk= rxcat1= i= &chk1; > if rxcat1=101 then goto out; > end; > out: > > run; > > SAS does not like this statement > > %let chk="'"||compress(upcase(scan(&drugs101,i)))||"'"; > > Can I know why? > > TIA >


Back to: Top of message | Previous page | Main SAS-L page