Date: Mon, 18 Sep 2006 15:24:27 -0400
Reply-To: "data _null_;" <datanull@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "data _null_;" <datanull@GMAIL.COM>
Subject: Re: macro bug I just can't see
In-Reply-To: <BAY123-F35453ADFFF5F086EB6E38EDE2D0@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I think you need to test this macro a bit more. When you put two
words in WordsToRM it doesn't work.
201 %Let List = Anno AAA b mean Cc;
202 %Put NewList = %RemoveWrd(List = &List , WordsToRM = mean Anno );
NewList = Anno AAA b mean Cc
On 9/18/06, toby dunn <tobydunn@hotmail.com> wrote:
> Micheal ,
>
> %Macro RemoveWrd( List = , WordsToRM = , DLM = %Str( ) ) ;
> %Local I Stop NewList ;
>
> %Let Stop = %Eval( %SysFunc( CountC( &List , &DLM ) ) + ( %Length( &List ) >
> 0 ) ) ;
>
> %Do I = 1 %To &Stop ;
> %If ( %Index( %Scan( %Upcase(&List) , &I , &DLM ) , %Upcase( &WordsToRM )
> ) = 0 )
> %Then %Do ;
> %Let NewList = &NewList %Scan( &List , &I , &DLM ) ;
> %End ;
> %End ;
>
> &NewList
>
> %Mend RemoveWrd ;
>
> %Let List = Anno AAA b mean Cc ;
> %Put NewList = %RemoveWrd( List = &List , WordsToRM = Mean ) ;
> %Put NewList = %RemoveWrd( List = &List , WordsToRM = Anno ) ;
>
>
>
>
> Toby Dunn
>
> When everything is coming at you all at once, your in the wrong lane.
>
> A truly happy person is someone who can smile and enjoy the scenery on a
> detour.
>
>
>
>
>
> From: Michael Friendly <friendly@YORKU.CA>
> Reply-To: Michael Friendly <friendly@YORKU.CA>
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: macro bug I just can't see
> Date: Mon, 18 Sep 2006 14:45:35 -0400
>
> Here's a macro designed to remove a word (or better yet, words) from a
> string, as when you want to construct a variable list, but remove BY or
> ID variables. I'm getting a run-time error that I just can't see, even
> though I've written this sort of macro many times before. Can someone help?
>
> %macro remwords(string,remove,dlm=%str( ));
> %*--------------------------------------------------;
> %* Remove any word contained in Remove from Strong
> %*--------------------------------------------------;
> %local count word;
> %let count=1;
> %let word = %scan(&string,&count,&dlm);
> %let result=;
> %do %while(%quote(&word)^= );
> %if(%index(
> %upcase(&dlm.&remove.&dlm),
> %upcase(&dlm.&word.&dlm) )=0)
> %then %let result = &result &word;;
> %put REMWORDS: word=&word result=&result;
> %let count = %eval(&count+1);
> %let word = %scan(&string,&count,&dlm);
> %end;
> &result
> %mend;
>
> %let words = Anno AAA b mean Cc;
> %put words: &words;
> %let rest = %remwords(&words, mean);
> %let rest = %remwords(&rest, anno);
> %put rest: &rest;
>
> ---- log -----
>
> 1 %macro remwords(string,remove,dlm=%str( ));
> 2 %*--------------------------------------------------;
> 3 %* Remove any word contained in Remove from Strong
> 4 %*--------------------------------------------------;
> 5 %local count word;
> 6 %let count=1;
> 7 %let word = %scan(&string,&count,&dlm);
> 8 %let result=;
> 9 %do %while(%quote(&word)^= );
> 10 %if(%index(
> 11 %upcase(&dlm.&remove.&dlm),
> 12 %upcase(&dlm.&word&dlm) )=0)
> 13 %then %let result = &result &word;;
> 14 %put REMWORDS: word=&word result=&result;
> 15 %let count = %eval(&count+1);
> 16 %let word = %scan(&string,&count,&dlm);
> 17 %end;
> 18 &result
> 19 %mend;
> 20
> 21 %let words = Anno AAA b mean Cc;
> 22 %put words: &words;
> words: Anno AAA b mean Cc
> 23 %let rest = %remwords(&words, mean);
> REMWORDS: word=Anno result=Anno
> REMWORDS: word=AAA result=Anno AAA
> REMWORDS: word=b result=Anno AAA b
> REMWORDS: word=mean result=Anno AAA b
> REMWORDS: word=Cc result=Anno AAA b Cc
> NOTE: Line generated by the macro variable "RESULT".
> 23 Anno AAA b Cc
> 2 The SAS System 14:36 Monday, September
> 18, 2006
>
> ____
> 180
>
> ERROR 180-322: Statement is not valid or it is used out of proper order.
>
> 24 %let rest = %remwords(&rest, anno);
> 25 %put rest: &rest;
> rest:
>
|