Date: Thu, 5 Apr 2001 12:25:19 -0400
Reply-To: "Kerrison, Foster" <FKerrison@NT.DMA.STATE.MA.US>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Kerrison, Foster" <FKerrison@NT.DMA.STATE.MA.US>
Subject: Re: Macro to test if a File Exists
Content-Type: text/plain
Samir,
I dont know what system you run under, but here is my filetest macro for
MVS. You need to adjust for windows or unix as appropriate. This uses a
libname reference and you can adapt that into your code to achieve what you
want.
This checks to see if the file exists, and runs a contents if it does,
otherwise it creates the file under the specified libname. The double macro
(lib and in_file) may be overkill but I need it to run other macros so thats
why I use it like ithis. If anyone has comments on improving it they are
always welcome.
Hope this helps.
Foster Kerrison.
%MACRO IN_FILE(DDNAME,DSNAME,SPACE,UNIT,ENGINE) ;
%IF %SYSFUNC(FILEEXIST(&DDNAME))=1 %THEN %DO;
LIBNAME TEST "&DDNAME" DISP=SHR ;
PROC DATASETS ;
CONTENTS DATA = TEST._ALL_ ;
RUN;
%END;
%ELSE %DO;
LIBNAME &LIBNAME &ENGINE "&DDNAME" DISP=(NEW,CATLG,DELETE)
%IF %BQUOTE(&SPACE) NE %THEN %DO;
SPACE=&SPACE
%END;
UNIT=&UNIT;
%END;
%MEND IN_FILE ;
%MACRO LIB(LIBNAME,DSNAME,DDNAME,SPACE=(CYL,(1,1),RLSE),UNIT=TESTDA,
ENGINE=);
%IN_FILE(&DDNAME,&DSNAME,&SPACE,&UNIT,&ENGINE) ;
%MEND LIB;
%LIB(OUT,CLMS,XXXXX.YYYYYYY0.ZZZZZZZZ.AUG00.SASFILE)
> -----Original Message-----
> From: SM [SMTP:samir.mishra@NORKOM.COM]
> Sent: Thursday, April 05, 2001 11:49 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Macro to test if a File Exists
>
> Anyone have a macro to test if a file exists? I need to check if a file
> exists, and in some instances if a directory exists. I've done this
> before,
> I know it's not easy and I am hoping someone can save me some time.
>
> Ideally I'd like the macro to return a value so that I can use it as
> below -
> %let filetest = %existfil(filename);
>
> Thanks in advance.
>
> Samir.
|