Date: Wed, 13 Nov 2002 18:27:31 +0100
Reply-To: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Subject: Re: Macro Vars with Equals, Parens, etc.
Content-Type: text/plain; charset="iso-8859-1"
Hi Bob,
Only your first argument value (x=5) is incorrect, the rest is correct, as
the following example shows, where the faulthy one has been moved to the
end.
%macro myquery(dsn, clause);
proc sql;
title "Clause = &Clause";
select *
from &dsn
where &clause;
quit;
%mend;
data test;
do x = 1 to 100;
y = x * 10;
z = y + 2;
output;
end;
run;
%*myquery(test, x > 50);
%PUT @@@@@@@@@ !!! CORRECT @@@@@@@@@;
%myquery(test, %quote(x = 5));
%PUT @@@@@@@@@ !!! CORRECT @@@@@@@@@;
%myquery(test, %str(x = 5));
%PUT @@@@@@@@@ !!! CORRECT @@@@@@@@@;
%let clause= %str(x=5);
%myquery(test, &clause);
%PUT ********* NOT CORRECT *********;
%myquery(test, x = 5);
Regards - Jim.
--
Y. (Jim) Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070
senior statist./data man. P.O. Box 1 fax. +31 412 407 080
J.Groeneveld@ITGroups.com 5350 AA BERGHEM, NL www.imrotramarko.com
My computer does what I tell it to do; sometimes it says my instructions are
illegal.
Notice of confidentiality: this e-mail may contain confidential information
intended for the addressed recipient only.
If you have received this e-mail in error please delete this e-mail and
please notify the sender so that proper delivery can be arranged.
> -----Original Message-----
> From: Bob Burnham [mailto:robert.a.burnham@DARTMOUTH.EDU]
> Sent: 13 November 2002 17:34
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Q: Macro Vars with Equals, Parens, etc.
>
>
> I'm wondering if anyone can pass on some sage advice about macro
> quoting some strings that have special meaning to the macro
> facility. Here is a quick example of something I'd like to do:
>
> %macro myquery(dsn, clause);
> proc sql;
> select *
> from &dsn
> where &clause;
> %mend;
>
> So, I'd like to be able to pass in an SQL clause and see the
> results printed to the screen -- pretty simple I thought.
>
> So, I created some test data:
>
> data test;
> do x = 1 to 100;
> y = x * 10;
> z = y + 2;
> output;
> end;
> run;
>
> Then ran a quick test:
>
> %myquery(test, x > 50);
>
> Fine. No problems.
>
> /* These don't work. . . */
>
> However, as soon as I started trying things like:
>
> %myquery(test, x = 5);
> %myquery(test, %quote(x = 5));
> %myquery(test, %str(x = 5));
>
> %let clause= %str(x=5);
> %myquery(test, &clause);
>
> I started getting the error message that the "keyword parameter
> x is not defined" (or something similar).
>
> I've done a Google search and been flipping through my manuals,
> but I'm not coming up with anything. Does anyone no the secret
> to quoting something like this? In the best of all possible
> worlds, it would also handle complex SQL expressions with lots
> of parentheses, etc.
>
> Thank you very much. I look forward to any responses.
>
> Bob
>
> --
> Bob Burnham
> bburnham@dartmouth.edu
> http://www.dartmouth.edu/~bburnham
>
|