Date: Tue, 5 Jan 2010 11:16:40 -0600
Reply-To: "Data _null_;" <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Data _null_;" <iebupdte@GMAIL.COM>
Subject: Re: Regarding SAS Macro
In-Reply-To: <2919ae25-6f03-423d-a8d3-ea367bf76cbb@u37g2000vbc.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
You may be interested to read Chang Chung's award winning SFG paper
"Is This Macro Parameter Blank?"
http://support.sas.com/resources/papers/proceedings09/022-2009.pdf
While %LENGTH and %BQUOTE work most of the time there are situations
where I believe %SUPERQ is considered a better choice.
On 1/5/10, Tom Abernathy <tom.abernathy@gmail.com> wrote:
> To test for empty macro variables I usually use either :
> %if (^%length(&vars)) %then ...
> %if (%bquote(&vars) ^=) %then ...
>
> The difference is whether VARS is total empty or contains blank
> characters.
> For example if you set VARS to blanks with a statement like this:
> %let vars=%str( );
>
> then the length is > 0 but it still is an empty string, so the test
> with length will say it is not empty and the test with BQUOTE will say
> it is empty.
>
>
> On Jan 5, 10:30 am, iebup...@GMAIL.COM ("Data _null_;") wrote:
> > No check for exists. Just is &VARS blank or does it have word(s).
> > &VARS should be macro quoted with %SUPERQ, if this was a real macro
> > and not just example.
> >
> > On 1/5/10, Mary <mlhow...@avalon.net> wrote:
> >
> >
> >
> > > Question: What does it mean to do this statement?
> >
> > > %if &vars= %then %do;
> >
> > > Would this translate to:
> >
> > > %if course_title days= %then %do;
> >
> > > What does it mean to do this? Does it check if variables exist? How?
> >
> > > -Mary
> >
> > > --- frankdiio...@GMAIL.COM wrote:
> >
> > > From: Frank DiIorio <frankdiio...@GMAIL.COM>
> > > To: SA...@LISTSERV.UGA.EDU
> > > Subject: Re: Regarding SAS Macro
> > > Date: Tue, 29 Dec 2009 07:30:01 -0800
> >
> > > On Dec 28, 11:06 pm, GNV Resident <sfe...@gmail.com> wrote:
> > > > Hello.
> >
> > > > Now I am studying for SAS Advanced Programming in SAS 9.
> >
> > > > ================================
> > > > 3 Which of the following correctly references the macro named Printdsn
> > > > as shown
> > > > here:
> > > > %macro printdsn(dsn,vars);
> > > > %if &vars= %then %do;
> > > > proc print data=&dsn;
> > > > title "Full Listing of %upcase(&dsn) data set";
> > > > run;
> > > > %end;
> > > > %else %do;
> > > > proc print data=&dsn;
> > > > var &vars;
> > > > title "Listing of %upcase(&dsn) data set";
> > > > run;
> > > > %end;
> > > > %mend;
> >
> > > > a %printdsn(sasuser.courses, course_title days);
> > > > b %printdsn(dsn=sasuser.courses, vars=course_title days)
> > > > c %printdsn(sasuser.courses, course_title days)
> > > > d %printdsn(sasuser.courses, course_title, days)
> > > > ================================
> >
> > > > Please take a look at the above problem. In reality, I tried to both
> > > > cases (b) and (c) and obtained that
> > > > they have the same result. I think that means both choices could be
> > > > right answers. But, the answer
> > > > sheet shows that (c) only is the answer. I can't understand why it
> > > > should be.
> >
> > > > Can someone explain why the answer is (c)?
> >
> > > > Thank you so much.
> >
> > > [c] is correct because the %macro statement defines two positional
> > > (not keyword, as used in [b]) parameters. Notice that [a] is
> > > identical to [c] save for the semicolon. One could argue that the
> > > semicolon, though unnecessary, does not make the macro call wrong, but
> > > then that would incite one to start railing about how goofy it is to
> > > measure someone's competence in a process (programming, debugging,
> > > design, etc.) by a multiple choice test.- Hide quoted text -
> >
> > - Show quoted text -
>
|