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.
|
|
0
|
|
|
|
Reply
|
GNV
|
12/29/2009 4:06:57 AM |
|
On Dec 28, 11:06=A0pm, GNV Resident <sfe...@gmail.com> wrote:
> Hello.
>
> Now I am studying for SAS Advanced Programming in SAS 9.
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
> 3 Which of the following correctly references the macro named Printdsn
> as shown
> here:
> %macro printdsn(dsn,vars);
> %if &vars=3D %then %do;
> proc print data=3D&dsn;
> title "Full Listing of %upcase(&dsn) data set";
> run;
> %end;
> %else %do;
> proc print data=3D&dsn;
> var &vars;
> title "Listing of %upcase(&dsn) data set";
> run;
> %end;
> %mend;
>
> a %printdsn(sasuser.courses, course_title days);
> b %printdsn(dsn=3Dsasuser.courses, vars=3Dcourse_title days)
> c %printdsn(sasuser.courses, course_title days)
> d %printdsn(sasuser.courses, course_title, days)
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
>
> 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.
|
|
0
|
|
|
|
Reply
|
Frank
|
12/29/2009 3:30:01 PM
|
|
Your answer sheet is wrong. A, B and C are correct calls. Only D is
wrong because it specifies a third positional parameter not defined in
the macro.
Of A,B and C I would prefer B as the proper way to CALL the macro as
the calling program will continue to work even if the the macro
definition is changed to add other positional parameters or change the
relative order of VARS and DSN parameters.
Now about the coding of the actual macro there are many things that
could be done to make it easier to use and maintain.
- Tom Abernathy
as it depend on the order of the parameters
On Dec 29, 10:30=A0am, Frank DiIorio <frankdiio...@gmail.com> wrote:
> On Dec 28, 11:06=A0pm, GNV Resident <sfe...@gmail.com> wrote:
>
>
>
>
>
> > Hello.
>
> > Now I am studying for SAS Advanced Programming in SAS 9.
>
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > 3 Which of the following correctly references the macro named Printdsn
> > as shown
> > here:
> > %macro printdsn(dsn,vars);
> > %if &vars=3D %then %do;
> > proc print data=3D&dsn;
> > title "Full Listing of %upcase(&dsn) data set";
> > run;
> > %end;
> > %else %do;
> > proc print data=3D&dsn;
> > var &vars;
> > title "Listing of %upcase(&dsn) data set";
> > run;
> > %end;
> > %mend;
>
> > a %printdsn(sasuser.courses, course_title days);
> > b %printdsn(dsn=3Dsasuser.courses, vars=3Dcourse_title days)
> > c %printdsn(sasuser.courses, course_title days)
> > d %printdsn(sasuser.courses, course_title, days)
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > 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. =A0Notice that [a] is
> identical to [c] save for the semicolon. =A0One 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 -
|
|
0
|
|
|
|
Reply
|
Tom
|
12/30/2009 10:43:26 PM
|
|
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
--- frankdiiorio@GMAIL.COM wrote:
From: Frank DiIorio <frankdiiorio@GMAIL.COM>
To: SAS-L@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.
|
|
0
|
|
|
|
Reply
|
mlhoward (1825)
|
1/5/2010 3:22:16 PM
|
|
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 -
>
|
|
0
|
|
|
|
Reply
|
iebupdte
|
1/5/2010 5:16:40 PM
|
|
Summary: Language features and documentation
#iw-value=1
Frank,
I agree with Tom and the OP that there is nothing wrong with answer
B. It is the prerogative of the user to decide whether to call
the macro with key word parameters, not that of the macro author.
It is an imortant point because key word parameters make the
user's code more readable. It also has the advantage that the
code will still work when the macro author learns the advantage
of key word parameters and changes his code.
Since I know of no documentation stating the possibility, one
might argue that it is a feature that one should not make use
of. However, I cannot imagine how the macro facility could work
this way without the intent its author, thus I think it is more
a matter of a wise programmer failing to transmit the geniusness
of his design to the documentation people rather than something
that might be taken away. (I suppose one could say it is a bug in
the design because this feature requires one to quote equal signs
when calling with positional parameters.)
On the other hand, I have not tested it in version 9.2. Does
anyone know if the ability has been removed in 9.2?
Should the documentation be the standard for deciding how the
language works, or is it merely a guide to help programmers in
writing code? While I think the answer must depend on the language,
it seems to me that the style of SAS documentation puts it in the
latter category.
Ian Whitlock
==============
Date: Tue, 29 Dec 2009 07:30:01 -0800
From: Frank DiIorio <frankdiiorio@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Regarding SAS Macro
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;
> poc 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.
|
|
0
|
|
|
|
Reply
|
iw1sas
|
1/5/2010 5:51:38 PM
|
|
Regarding choice [a]: This is the way I would normally call the
macro. Why? Because the trailing semicolon is not superfluous at all;
it conveys a very important message, namely that the macro called
(in the way shown) acts as a stand-alone statement.
Macros can generate anything, from lists of pixel values used
to create bit maps, to complete sas programs, to variable name prefixes.
The semicolon shows what kind of macro we are dealing with. It is just
as important as correct indentation in order to make the program
more readable, and in terms of execution time, it costs no more
than a couple of extra spaces.
Of course it appears that the moron (pardon my French) who wrote
the test does not use indentation either.
Imagine this series of macro calls in a program:
%dataset(x)
%printdsn(test,a b c);
run;
What does it do? Could be something like some a proc datasets and a proc
print. Or may be the code generated looks something like this:
MPRINT(DATASETS): data x;
MPRINT(DATASETS): set
MPRINT(PRINTDSN): test.printa test.printb test.printc
;
run;
I know, a strange way of coding things. Believe me, I have seen worse.
A semicolon after the %datasets (though syntactically superfluous) would
tell you at first glance that %dataset(x) is a self-contained statement
or set of statements.
Regards,
Søren
On Tue, 29 Dec 2009 07:30:01 -0800, Frank DiIorio <frankdiiorio@GMAIL.COM>
wrote:
>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.
|
|
0
|
|
|
|
Reply
|
s.lassen (140)
|
1/7/2010 6:36:41 AM
|
|
|
6 Replies
335 Views
(page loaded in 0.195 seconds)
|