Date: Tue, 19 Sep 2006 04:55:17 -0400
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: macro bug I just can't see
Hi Michael, hi Jim,
not the case here, but a litte peace from history:
in PL1 (the roots of the SAS language(s)) you had sometimes the problem,
that you needed a character which was also a delimiter for strings or
statements (',",;, ...). In PL1 the trick was to use the same char twice. At
some locations in SAS that works also. Try
data a;
y='Jim''s answer is correct';
put y=;
run;
if you use '' in a '-delimited string it is no longer treated as
"end-of-string". Same for ;;
So a good idea might be to avoid that and use ; ; instead.
Regards,
Gerhard
On Tue, 19 Sep 2006 04:28:46 -0400, Jim Groeneveld <jim2stat@YAHOO.CO.UK> wrote:
>Hi Michael,
>
>Just like data _null_ already said: you have a double semicolon after:
>%then %let result = &result &word;;
>The second one is not a semicolon that ends the macro statement,
>but it is a semicolon that ends an empty SAS statement.
>As a result your macro call in the %LET statement generates
>%LET Rest = ; Anno AAA b Cc;
>which clearly generates the error message.
>
>Regards - Jim.
>--
>Jim Groeneveld, Netherlands
>Statistician, SAS consultant
>home.hccnet.nl/jim.groeneveld
>
>My computer remains home while I will attend PhUSE 2006 in Dublin.
>
>
>On Mon, 18 Sep 2006 14:45:35 -0400, Michael Friendly <friendly@YORKU.CA> wrote:
>
>>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:
|