|
On Fri, 28 Aug 2009 15:57:57 -0400, Chang Chung
<chang_y_chung@HOTMAIL.COM> wrote:
>On Fri, 28 Aug 2009 14:09:24 -0400, Kevin Viel <citam.sasl@GMAIL.COM>
wrote:
>
>>This is a simplification of a macro I have written, without any attempts
>>to use appropriate quoting. I would appreciate suggestions about the
>>right macro functions. The ampersand is contained within a folder name
on
>>Windows and the macro variable containing it will be used in system
>>commands using the X statement and Call Execute().
>>
>>75 %macro qtest ( list = ) ;
>>76
>>77 %let i = 1 ;
>>78 %let value = %scan( &list. , &i. , "////" ) ;
>>79
>>80 %do %while ( &value ne ) ;
>>81
>>82 %put &value ;
>>83
>>84 %let i = %eval( &i. + 1 ) ;
>>85 %let value = %scan( &list. , &i. , "////" ) ;
>>86 %end ;
>>87
>>88
>>89
>>90
>>91 %mend qtest ;
>>92
>>93 options Nomlogic ;
>>94 %qtest ( list = 1&A////Old )
>>WARNING: Apparent symbolic reference A not resolved.
>>WARNING: Apparent symbolic reference A not resolved.
>>WARNING: Apparent symbolic reference A not resolved.
>>WARNING: Apparent symbolic reference A not resolved.
>>WARNING: Apparent symbolic reference A not resolved.
>>1&A
>>WARNING: Apparent symbolic reference A not resolved.
>>Old
>>WARNING: Apparent symbolic reference A not resolved.
>>
>>Thank you,
>>
>>Kevin
>
>Hi, Kevin,
>
>The first warning occurs when the %qtest macro is called as the parameter
>value "1&A////Old" is assigned to the parameter(list). There is nothing
>macro author can do to prevent this warning, thus the macro user is
>responsible for the warning. The user should have quoted the parameter
>value.
>
>Once the parameter is passed into the macro, however, then the macro
author
>is responsible for macro quoting. %superq() is a run time quoting function
>that is very useful. SAS Institute provides %qscan(), which returns a
quoted
>word. Combined, something like below seems reasonable to me. Hope this
helps
>a bit.
>
>Cheers,
>Chang
>
>%macro qItems(list=, dlm=/);
> %local i item;
> %let i = 1;
> %do %while (1);
> %let item = %qscan(%superq(list), &i, &dlm);
> %if (%superq(item)=) %then %return;
> %put i=&i item=&item;
> %let i = %eval(&i + 1);
> %end;
>%mend qItems;
>
>%qItems(list=%nrstr(&)A/B)
>/* on log
>i=1 item=&A
>i=2 item=B
>*/
Thanks to both of you.
This sheds some light on the issue, but what happens if the call to %
qItems is *within* a macro itself?
For instance, within the Do-While loop above, %qItems2(list=&item.)?
Thanks,
Kevin
|