|
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 -
|