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 (September 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 19 Sep 2006 01:08:17 +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
Comments: To: datanull@GMAIL.COM
In-Reply-To:  <7367b4e20609181701l205c0ef8yc8821b6456097dd1@mail.gmail.com>
Content-Type: text/plain; format=flowed

Uhhh no his code didnt work, hence his post.

Now if we eliminate the extra semi colon his code only handles one value to delete at a time and well suffers from the same problem with comma delimited lists. All I was doing was reworking the code so that it was in my opinion easier to read and would be eaiser to modify to what every poster desires maybe. Nothing more nothing less. I am sorry if I mislead anyone.

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> Reply-To: "data _null_;" <datanull@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: macro bug I just can't see Date: Mon, 18 Sep 2006 20:01:30 -0400

On 9/18/06, toby dunn <tobydunn@hotmail.com> wrote: >Data _Null_ ; > >I dont ever think I write superior code, I just hack at this gig.

I understand, but you posted the code out of context to Michael's question. He had code that worked save for the extra semicolon. Your out of context post seemed to suggest that you had a better solution. Or so it seemed to me.

>As for the comma delimiter, yeah I gave it some thought and well the code >would have to be tweeked to accept a comma. On the other hand commas are >the worst delimiter in macro lists and should be avoided at all costs >unless >it is the case where you build a comma delimited list and use it with no >modifications in a SQL statement.

I agree that commas delimited lists and macros don't easily work together. But if a macro has a parameter one should expect that any value can and will be passed at one time or another.

But then if we used SCL all these problems would disappear. :-)

>Which is probably why I didnt even think >of a comma as a delimiter, it simply doesnt make good sense to use it as a >delimiter 99.99% of the time. > > > >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> >Reply-To: "data _null_;" <datanull@GMAIL.COM> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: macro bug I just can't see >Date: Mon, 18 Sep 2006 16:18:41 -0400 > >I thought you were offering your program as a superior replacement to >the code Michael posted, were he mentioned plural word removal. I >thought if that were the case you would want to revise your program to >be more suitable to the task. > >You may also want to test the macro with alternate delimiters. I >don't reckon a comma delimiter is gonna fly. > >On 9/18/06, toby dunn <tobydunn@hotmail.com> wrote: > >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: > > > > > >


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