Date: Mon, 14 Jul 1997 08:24:09 -0700
Reply-To: Lund Peter <Peter.Lund@OFM.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Lund Peter <Peter.Lund@OFM.WA.GOV>
Subject: Re: Testing Existence of a Macro Variable
Content-Type: text/plain; charset="us-ascii"
Keith-
You can query the SASHELP.VMACRO view to get the information you
need. The following query will create a macro variable &Exist which
contains a 0 (zero) if your macro variable &StartDt does not exist and
a 1 (one) if it does:
proc sql noprint;
select count(*) into :exist
from sashelp.vmacro
where name eq "STARTDT";
quit;
You could always replace the hard-coded STARTDT with a macro reference
and make this more generic, testing for the existence of any macro
variable:
%let macvar = StartDt;
proc sql noprint;
select count(*) into :exist
from sashelp.vmacro
where name eq upcase("&macvar");
quit;
HTH-
Pete Lund
WA State Office of Financial Management
----------
From: Keith L. Gregory, Ph.D.[SMTP:klg@DNAI.COM]
Sent: Sunday, July 13, 1997 1:20 PM
To: Multiple recipients of list SAS-L
Subject: Testing Existence of a Macro Variable
I've looked high and low for what should be a very basic macro
function,
that is, one which tests for the existence of a macro variable in the
macro environment. In particular, I have a bunch of macros which all
assume the existence of a global macro variable STARTDT . If they were
called without STARTDT having been set earlier in the program as a
global
macro variable, things just wouldn't be the same... How can my macros
test to see if this prerequisite macro variable has been defined? I'd
like to avoid warning messages if it is not defined, too; as a matter
of
good coding, I only like warning message when things are not in
control.
I've tried a bunch of kludges, but haven't been successful. They also
tend to produce warning messages, but I can live with that.
-------------------------------------------------------------
Keith L. Gregory, Ph.D.
Statistical Information Technology Consultant
Information Development & Decisions
e-mail: klg@dnai.com