|
Data _Null_ ;
The error is %Evals in ability to do a simple job like honor a simple Macro quoted hunk of text. I have had a problem with %Eval unquoting values and this is where the rubber meets the asphault and it fails miserably.
I have sent emails to some peeps at SI asking when does %Eval strip the macro quoting and when doesnt it and where at in the process does it do it at. No one has answered as I am working on a macro quoting paper. So I am slowly getting the feeling either they dont know ( I doubt this the one guy who handles the macro facilty at SI knowns) or they dont care to divulge it and make our lives easier in some small way.
Ian found this simple problem many moons ago and I have yet to see an acceptable answer to why %Eval would choose to honor the macro quoting in one instance and not in the other. Seems to me either it should honor the quoting like every other part of the macro facilty (with the exception of printing stuff to the log that is noted in the documentation) or not at all:
315 %Put %Eval( %Str(+) LE %Str(-) ) ;
1
316 %Put %Eval( %Str(+3) LE %Str(-7) ) ;
0
317 %Put %Eval( %Str(1+3) LE %Str(-7) ) ;
0
Toby Dunn
"Don't bail. The best gold is at the bottom of barrels of crap."
Randy Pausch
"Be prepared. Luck is where preparation meets opportunity."
Randy Pausch
> Date: Tue, 4 Mar 2008 10:12:27 -0500
> From: datanull@GMAIL.COM
> Subject: Re: Bug in %DO %WHILE while processing a 10-digit numeric value?
> To: SAS-L@LISTSERV.UGA.EDU
>
> I tried this program using your "LIST" and it did not fail.
>
> 26 %macro test;
> 27 %let list = Achievement 4387610624 43876106244387610624;
> 28 /* %let list = Achievement 9007199300000000 90071993000000000
> wwwwwwwwwwwwwwwwwwwwwwwww;*/
> 29 %let wordcnt1 = 1;
> 30 %let word = %scan(&list,&wordcnt1,%str( ));
> 31 %do %while(%bquote(&word) ne);
> 32 %let wordcnt1 = %eval(&wordcnt1 + 1);
> 33 %let word = %scan(&list,&wordcnt1,%str( ));
> 34 %end;
> 35 %put number of words: %eval(&wordcnt1 - 1);
> 36 %mend test;
> 37 %test;
> ERROR: Overflow has occurred; evaluation is terminated.
> ERROR: The condition in the %DO %WHILE loop, , yielded an invalid or
> missing value, . The macro will stop
> executing.
> ERROR: The macro TEST will stop executing.
>
>
> On Tue, Mar 4, 2008 at 10:04 AM, Yu Zhang wrote:
>> Dear All,
>>
>> I found it is really interesting. I never got this program failed. please
>> look at the log. What ERROR message you get when program fails?
>>
>> Thanks!
>>
>> Yu
>>
>> 337 %macro test;
>>
>> 338
>>
>> 339 %let list = Achievement 9007199300000000 90071993000000000
>> wwwwwwwwwwwwwwwwwwwwwwwww;
>>
>> 340 %let wordcnt1 = 1;
>>
>> 341 %let word = %qscan(%quote(&list), &wordcnt1, %str( ));
>>
>> 342
>>
>> 343 %do %while (%quote(&word) ne %str( ));
>>
>> 344
>>
>> 345 %let wordcnt1 = %eval(&wordcnt1 + 1);
>>
>> 346 %let word = %qscan(%quote(&list), &wordcnt1, %str( ));
>>
>> 347
>>
>> 348 /* IF THE WORD IS NUMERIC AND HAS A LENGTH OF 10 OR GREATER, */
>>
>> 349 /* THIS MACRO BLOWS UNLESS THE LENGTH IS SHORTENED TO 9. */
>>
>> 350
>>
>> 351 %end;
>>
>> 352
>>
>> 353 %put number of words: %eval(&wordcnt1 - 1);
>>
>> 354 %mend test;
>>
>> 355 %test
>>
>> MLOGIC(TEST): Beginning execution.
>>
>> MLOGIC(TEST): %LET (variable name is LIST)
>>
>> MLOGIC(TEST): %LET (variable name is WORDCNT1)
>>
>> MLOGIC(TEST): %LET (variable name is WORD)
>>
>> SYMBOLGEN: Macro variable LIST resolves to Achievement 9007199300000000
>> 90071993000000000
>>
>> wwwwwwwwwwwwwwwwwwwwwwwww
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 1
>>
>> SYMBOLGEN: Macro variable WORD resolves to Achievement
>>
>> SYMBOLGEN: Some characters in the above value which were subject to macro
>> quoting have been
>>
>> unquoted for printing.
>>
>> MLOGIC(TEST): %DO %WHILE(%quote(&word) ne ) loop beginning; condition is
>> TRUE.
>>
>> MLOGIC(TEST): %LET (variable name is WORDCNT1)
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 1
>>
>> MLOGIC(TEST): %LET (variable name is WORD)
>>
>> SYMBOLGEN: Macro variable LIST resolves to Achievement 9007199300000000
>> 90071993000000000
>>
>> wwwwwwwwwwwwwwwwwwwwwwwww
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 2
>>
>> SYMBOLGEN: Macro variable WORD resolves to 9007199300000000
>>
>> SYMBOLGEN: Some characters in the above value which were subject to macro
>> quoting have been
>>
>> unquoted for printing.
>>
>> MLOGIC(TEST): %DO %WHILE(%quote(&word) ne ) condition is TRUE; loop will
>> iterate again.
>>
>> MLOGIC(TEST): %LET (variable name is WORDCNT1)
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 2
>>
>> MLOGIC(TEST): %LET (variable name is WORD)
>>
>> SYMBOLGEN: Macro variable LIST resolves to Achievement 9007199300000000
>> 90071993000000000
>>
>> wwwwwwwwwwwwwwwwwwwwwwwww
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 3
>>
>> SYMBOLGEN: Macro variable WORD resolves to 90071993000000000
>>
>> SYMBOLGEN: Some characters in the above value which were subject to macro
>> quoting have been
>>
>> unquoted for printing.
>>
>> MLOGIC(TEST): %DO %WHILE(%quote(&word) ne ) condition is TRUE; loop will
>> iterate again.
>>
>> MLOGIC(TEST): %LET (variable name is WORDCNT1)
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 3
>>
>> MLOGIC(TEST): %LET (variable name is WORD)
>>
>> SYMBOLGEN: Macro variable LIST resolves to Achievement 9007199300000000
>> 90071993000000000
>>
>> wwwwwwwwwwwwwwwwwwwwwwwww
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 4
>>
>> SYMBOLGEN: Macro variable WORD resolves to wwwwwwwwwwwwwwwwwwwwwwwww
>>
>> SYMBOLGEN: Some characters in the above value which were subject to macro
>> quoting have been
>>
>> unquoted for printing.
>>
>> MLOGIC(TEST): %DO %WHILE(%quote(&word) ne ) condition is TRUE; loop will
>> iterate again.
>>
>> MLOGIC(TEST): %LET (variable name is WORDCNT1)
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 4
>>
>> MLOGIC(TEST): %LET (variable name is WORD)
>>
>> SYMBOLGEN: Macro variable LIST resolves to Achievement 9007199300000000
>> 90071993000000000
>>
>> wwwwwwwwwwwwwwwwwwwwwwwww
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 5
>>
>> SYMBOLGEN: Macro variable WORD resolves to
>>
>> SYMBOLGEN: Some characters in the above value which were subject to macro
>> quoting have been
>>
>> unquoted for printing.
>>
>> MLOGIC(TEST): %DO %WHILE() condition is FALSE; loop will not iterate again.
>>
>> MLOGIC(TEST): %PUT number of words: %eval(&wordcnt1 - 1)
>>
>> SYMBOLGEN: Macro variable WORDCNT1 resolves to 5
>>
>> number of words: 4
>>
>> MLOGIC(TEST): Ending execution.
>>
>>
>>
>> On Tue, Mar 4, 2008 at 8:25 AM, Curtis Reid wrote:
>>
>>> I liked this one better. This one was very simple to fix and easier to
>>> read. I'm just surprised why if a numeric value less than 10 digits
>>> didn't cause problems while a numeric value greater than 10 digits would
>>> not work. It does not matter how big the text is; it will work fine.
>>>
>>> (A quick background: I was parsing a list of file and one of the elements
>>> contained the file size. I was using this macro to find out how
>>> many "words" or "elements" there are in a line and then strip out whatever
>>> I needed. Until I came across an file size that is 10 digits in length,
>>> the macro just refused to work. That's why I didn't care if I cut it off
>>> to 9 digits as long I got it working.)
>>>
>>> Additionally, I apologize to others for putting in a correction code; I
>>> should have removed OR added a better note saying that this section was a
>>> correction code to make it work.
>>>
>>> Thank you to everyone!
>>>
>>> --Curtis E. Reid
>>>
>>> On Mon, 3 Mar 2008 15:20:01 -0500, data _null_,
>>> wrote:
>>>
>>>>Add a bit of TEXT in the %WHILE expression to convince SAS that these
>>>>are not numbers. I used _ before and after.
>>>>
>>>>144 %macro test;
>>>>145 %let list = Achievement 4387610624 43876106244387610624;
>>>>146 %let wordcnt1 = 1;
>>>>147 %let word = %scan(&list,&wordcnt1,%str( ));
>>>>148 %do %while(%bquote(_&word._) ne __);
>>>>149 %let wordcnt1 = %eval(&wordcnt1 + 1);
>>>>150 %let word = %scan(&list,&wordcnt1,%str( ));
>>>>151 %end;
>>>>152 %put number of words: %eval(&wordcnt1 - 1);
>>>>153 %mend test;
>>>>154 %test;
>>>>number of words: 3
>>>
>>
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan |