Date: Mon, 28 Jan 2008 08:14:18 -0800
Reply-To: karma <dorjetarap@GOOGLEMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: karma <dorjetarap@GOOGLEMAIL.COM>
Organization: http://groups.google.com
Subject: Re: checking for the existence of variables
Content-Type: text/plain; charset=ISO-8859-1
On Jan 28, 3:21 pm, datan...@GMAIL.COM ("data _null_,") wrote:
> IN is not a macro operator. Plus CHECKVAR did not work. I don't
Ah ok, that would be the problem then, thanks for that.
I have to check whether a set of variables exist in a dataset. And if
not, then to generate a list of errors. I've managed to do this, but
each time I check for the existence of a variable in a dataset, I have
to run a query on the metadata, I was hoping there was a more
effiecient way of doing it. Part of my code is below.
%macro exists(dsn);
%sysfunc(exist(&dsn))
%mend exists;
%macro empty(lib,dsn);
proc sql noprint;
SELECT left(put(nobs,8.))
INTO: dnobs
FROM dictionary.tables
WHERE libname=upcase("&lib") AND memname=upcase("&dsn");
quit;
%mend empty;
%macro checkvar(lib,dsn,var);
proc sql noprint;
SELECT left(put(count(*),8.))
INTO: exist
FROM dictionary.columns
WHERE libname=upcase("&lib") AND
memname=upcase("&dsn") AND name=upcase("&var");
quit;
%mend checkvar;
%macro checkdata;
%let exist=;
%let dnobs=;
%let chklist=;
%put >>> *** AE dataset issues.***;
%if %exists(dmdata.ae) %then %do;
%empty(dmdata,ae);%put &dnobs;
%if &dnobs %then %do;
*** STUDYID;
%checkvar(dmdata,ae,studyid);
%if &exist %then %let chklist=&chklist STUDYID;
%else %put !STUDYID does not exist.;