Date: Mon, 18 Sep 2006 19:58:27 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: macro bug I just can't see
In-Reply-To: <7367b4e20609181224q7f93e8ds5ecd241ab084ea5d@mail.gmail.com>
Content-Type: text/plain; format=flowed
I didnt need to test it any further as it was only set up to have one value
in the wordstorm, I guess in hind sight I should have not has an 's' in the
parameter name. But if one is so inclined to want more than one word in the
list then:
%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 %SysFunc( IndexW( %Upcase( &WordsToRM ) , %Scan( %Upcase(&List) , &I
, &DLM ) , &DLM ) ) = 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 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: "data _null_;" <datanull@gmail.com>
To: "toby dunn" <tobydunn@hotmail.com>
CC: SAS-L@listserv.uga.edu
Subject: Re: macro bug I just can't see
Date: Mon, 18 Sep 2006 15:24:27 -0400
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:
>
|