Date: Mon, 31 Aug 2009 11:43:01 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Macro quoting for &
In-Reply-To: <54F32716-2C2D-4599-A02A-790A863AB94A@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
I think it's worth highlighting something Mark assumes and Ian explicitly
notes on, but doesn't expound upon.
%scan( ), or %sysfunc(scan( )), do not take " " around the characters in any
of their arguments, particularly the delimiter argument.
%scan(word,1,"\")
searches for either \ or " as a delimiter.
Correct:
%scan(word,1,\)
So:
%scan("C:\Program Files\test.xls",3,"\")
returns test.xls as expected
but
%scan(AS"C:\Program Files\test.xls",3,"\")
returns Program Files, not test.xls, as " is a delimiter.
More than likely it won't affect your ouptut, since in most cases " " will
either be around your entire string (thus not being useful as a delimiter)
or will be immediately before/after a \ (consecutive delimiters, so
ignored); but it is a good idea to not use " ", to avoid potential problems.
-Joe
On Sun, Aug 30, 2009 at 5:47 PM, Ian Whitlock <iw1sas@gmail.com> wrote:
> Summary: Remarks about SCAN or %SCAN
> #iw-value=1
>
> Kevin,
>
> I note that others have helped you with the quoting part of your
> problem,
> but it is unclear if you realize how the functions work.
>
> The third argument is a list of delimiters. You have listed " twice and
> / four times. The chances are that you do not want " as a delimiter,
> particularly because you mention a list of folder names and " is used by
> Windows to indicate the characters of a folder name, e.g. "x y" is a
> folder
> name that has a space in it.
>
> Now the fact that you go out of the way to write //// suggests that
> you think
>
> %scan (a/b////c,2,"////")
>
> is c. It is not it is b.
>
> Now what about
>
> %scan (a/b////c,3,"////")
>
> Here the value is c because consecutive delimiters are ignored. It is
> curious that
> all the documentation prior to 9.2 did not find it necessary to spell
> out this
> behavior. The documentation for 9.2 got very much better, possibly
> because a fourth
> parameter was added which could change this behavior.
>
> However, I did not see anything to allow a single delimiter consisting
> of multiple
> characters. If you really need this feature you could write a macro
> function
> using %INDEX and %SUBSTR to locate and extract the delimited names.
>
> Ian Whitlock
> =================
>
> Date: Fri, 28 Aug 2009 14:09:24 -0400
> From: Kevin Viel <citam.sasl@GMAIL.COM>
> Subject: Macro quoting for &
>
>
> 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.
>
|