Date: Tue, 21 Jun 2005 21:55:22 -0700
Reply-To: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject: Re: Checking for existence of macro
In-Reply-To: <0E5377DC9E9CE34C98D7CDA4EE29154A02B33190@SEW01070.maple.fg.rbc.com>
Content-Type: text/plain; charset="iso-8859-1"
Harry Droogendyk wrote:
> Jack's code will test for the existence of the WORK macro
> catalog, not the presence of the macros themselves.
It will check for the existence of a catalog entry with a type of "macro"
and the appropriate name.
It's true that there are ways for macro catalog entries and the actual
macros to get out of sync, but would they ever happen to naïve users?
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> Behalf Of Harry Droogendyk
> Sent: Tuesday, June 21, 2005 8:24 pm
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: [SAS-L] Checking for existence of macro
>
> Jack's code will test for the existence of the WORK macro
> catalog, not the presence of the macros themselves.
>
> Here's some code I use to check for the presence of .sas
> files in the SASAUTOS path ( even if altered by an OPTIONS
> statement in your program ). At this installation, we don't
> use macro catalogs or point to macro locations via filerefs
> so the code doesn't support those two locations. Having said
> that, to extend the code below to examine catalogs and other
> filerefs ( using pathname function ) won't be an arduous
> task. Granted, the presence of a .sas file within a
> directory listed in the SASAUTOS path doesn't -necessarily-
> mean that the .sas file contains a macro, but if you obey the
> docs and store only one macro within each file where the
> macro bears the same name as the file etc.. it'll be fine.
>
> %macro list_sasautos(help);
>
> %if &help = ? or %upcase(&help) = HELP %then %do;
> %put;
> %put;
> %put %nrstr(%list_sasautos;);
> %put;
> %put %nrstr(Lists the .sas files found within
> directories found in:);
> %put %nrstr( - pathname('sasautos') - config file
> SASAUTOS defintion);
> %put %nrstr( - getoptions('sasautos') - SASAUTOS
> altered by options statement);
> %put;
> %put %nrstr(Note that this macro does not currently
> support:);
> %put %nrstr( - file references other than SASAUTOS);
> %put %nrstr( - macro catalogs);
> %put;
> %goto exit;
> %end;
>
> data _sasautos ( keep = path member );
> length sasautos $32000;
> sasautos = translate(getoption('sasautos') ||
> pathname('sasautos'),"'",'"');
>
> b = 1;
> do until(b > length(sasautos));
> if substr(sasautos,b,1) = "'" then do;
> end = index(substr(sasautos,b+1),"'");
> path = substr(sasautos,b+1,end-1);
> * getoption returns SASAUTOS, we'll
> get path for those from pathname() stuff ;
> if path ne 'SASAUTOS' then do;
> problem = filename('dir',path);
> if not(problem) then do;
> d = dopen('dir');
> if d then do;
> num = dnum(d);
> do _i = 1 to num;
> member = dread(d,_i);
> if
> upcase(scan(member,-1,'.')) = 'SAS' then
>
> output;
> end;
> rc = dclose(d);
> end;
> end;
> end;
> b = b + end + 1;
> end;
> b + 1;
> end;
> run;
>
> proc print data=_sasautos;
> run;
>
> %exit:
>
> %mend list_sasautos;
>
> -----Original Message-----
> From: owner-sas-l@listserv.uga.edu
> [mailto:owner-sas-l@listserv.uga.edu]On Behalf Of Jack Hamilton
> Sent: Tuesday, June 21, 2005 10:58 PM
> To: golfplayer92@YAHOO.COM; SAS-L@LISTSERV.UGA.EDU
> Subject: RE: [SAS-L] Checking for existence of macro
>
>
> If you only care about macros in your WORK library, you could
> use the CEXIST
> function:
>
> =====
> 16 %macro test(dummy);
> 17 /* Nothing here */
> 18 %mend test;
> 19
> 20 %put CEXIST returns %sysfunc(cexist(work.sasmacr.test.macro));
> CEXIST returns 1
> 21
> 22 %put CEXIST returns %sysfunc(cexist(work.sasmacr.noexist.macro));
> CEXIST returns 0
> =====
>
> As previously noted, this won't find macros in other
> catalogs. Also, it
> won't search SASAUTOS to find macros which will be found when called.
>
>
>
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> > Behalf Of golfplayer92@YAHOO.COM
> > Sent: Tuesday, June 21, 2005 4:46 pm
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: [SAS-L] Checking for existence of macro
> >
> > Hello all,
> >
> > I see a lot of archived messages on this list about checking for the
> > existence of a macro variable. However, I'm interested in
> > checking for
> > the existence of a macro, i.e. something defined with %macro. I
> > tinkered with the below code:
> >
> > proc catalog c=work.sasmacr ;
> > contents out=mac ;
> > run ;
> >
> > data _null_ ;
> > set mac ;
> > retain mexist 0 ;
> > if name = xxxx then mexist = 1 ;
> > if eof then call symput ("mexist", left(put(mexist,1.))) ;
> > run ;
> >
> > Is there a more elegant way to do this?
> >
> > thanks for the thoughts.
> >
> > ---wayne
> >
> ______________________________________________________________
> ____________________________________________________________________
>
> This e-mail may be privileged and/or confidential, and the
> sender does not waive any related rights and obligations.
> Any distribution, use or copying of this e-mail or the
> information it contains by other than an intended recipient
> is unauthorized.
> If you received this e-mail in error, please advise me (by
> return e-mail or otherwise) immediately.
>
> Ce courrier électronique est confidentiel et protégé.
> L'expéditeur ne renonce pas aux droits et obligations qui s'y
> rapportent.
> Toute diffusion, utilisation ou copie de ce message ou des
> renseignements qu'il contient par une personne autre que le
> (les) destinataire(s) désigné(s) est interdite.
> Si vous recevez ce courrier électronique par erreur, veuillez
> m'en aviser immédiatement, par retour de courrier
> électronique ou par un autre moyen.
>
|