Date: Tue, 27 Jun 2006 17:24:42 +0000
Reply-To: iw1junk@COMCAST.NET
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <iw1junk@COMCAST.NET>
Subject: Re: Testing for left paren in a macro variable
Ed,
I strongly agree with Ron's advice to not rely on quirks in the SAS
compiler to write code with unbalanced parentheses! Some helpful
person has been running around adding missing parenetheses and semicolons
to code. Someday someone will say "errors are errors, and not to be
corrected." Incidentally I would vote for a system option DO_AS_IS.
Peter Crawford and Ron Fehd have been down the autocall road several times.
A quick search on Crawford and autocall and macro turned up
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0301B&L=sas-l&P=R14211&D=1&O=D
which includes
%macro mstripper( string )
/des='strip bounding (parentheses)';
%local mstripped ;
%if "%qsubstr( &string, 1,1)" eq "("
& "%qsubstr( &string,
%length( &string ),1)" eq ")"
%then %do;
%let mstripped =
%qsubstr( &string
, 2
, %length( &string) -2
) ;
%end;
%else %do;
%let mstripped = &string ;
%end;
&mstripped
%mend mstripper ;
I did not look further, but I think Peter also gave a complete solution to
your problem. Or you could add
%macro addautolib ( spec , position=before ) ;
%local newspec ;
%if %upcase(%substr(&position,1,1)) = B %then
%let newspec = &spec %mstripper(%sysfunc(getoption(SASAUTOS)));
%else
%let newspec = %mstripper(%sysfunc(getoption(SASAUTOS))) &spec ;
options sasautos = ( &newspec);
%mend addautolib ;
My test code
options sasautos = (sasautos) ;
%addautolib("c:\junk")
%put %sysfunc(getoption(sasautos)) ;
%addautolib("c:\" othrmacs)
%put %sysfunc(getoption(SASAUTOS));
To correct misunderstandings about what %NRBQUOTE does - it does not quote
%'s and &'s. It resolves as far as it can. Then that result is quoted.
However, you may have trouble defining a variable MAC whose value contains
a reference to an undefined macro or variable without quoting it in the
first place and thus making it a non-reference, so the distinction is
academic unless you have enough knowledge. Hint: I gave such an example in
the last month or two.
%SUPERQ does not hide &'s and %'s in it's argument. It expects the
argument to evaluate to a variable name. It then hides everything in the
value of the named variable.
Ian Whitlock
================
Date: Tue, 27 Jun 2006 10:29:34 -0400
Reply-To: "Fehd, Ronald J. (CDC/CCHIS/NCHM)" <rjf2@CDC.GOV>
Sender: "SAS(r) Discussion"
From: "Fehd, Ronald J. (CDC/CCHIS/NCHM)" <rjf2@CDC.GOV>
Subject: Re: Testing for left paren in a macro variable
Content-Type: text/plain; charset="us-ascii"
> From: Ed Heaton
> Here at Westat, we have multiple autocall libraries. Two of
> them are specified in our autoexec.sas with something like...
>
> Options sasAutos=( "I:\SasMacro" __stdMac ) ;
>
> I'm creating a macro to add an autocall library to the mix.
> I want the new one to be the first searched. E.g., to add
> C:\temp\ as an autocall library, I need to submit something like...
>
> Options sasAutos=( "C:\temp\" "I:\SasMacro" __stdMac ) ;
>
> The plan was to strip the parentheses - if they exist - and
> then build the new Options statement. However, I had a
> brainstorm yesterday and tried...
>
> Options sasAutos=( "C:\temp\" ( "!ACCTMACS" "I:\SasMacro"
> __stdMac ) ) ;
>
> and it works just fine. So really, all my macro needs to do is...
>
> Options sasAutos=( &newAutocallLib &sysFunc( getOption(sasAutos) ) ) ;
>
> But I'm learning more about macro quoting.
Ed
this will work:
Options sasAutos=( &newAutocallLib &sysFunc( getOption(sasAutos
) );
count: 3 open (
2 close )
why?
1. second open paren returned by getoption is ignored
2. final close paren is provided by getoption
see also:
Options sasAutos=( &newAutocallLib &sysget(sasAutos);
YeahBut do you want to write code
that has apparently, obviously, unbalanced enclosures?
Ron Fehd the SASautos
or macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Tutorials
A SASautos Companion: Reusing Macros
http://www2.sas.com/proceedings/sugi30/267-30.pdf