Chapter Contents

Previous

Next
DSNEXST

DSNEXST



Checks to see whether the specified physical file exists and is available

Valid: anywhere
OS/390 specifics: all


Syntax
Details
See Also

Syntax

DSNEXST 'physical-filename ';

'physical-filename '
is the name of a physical file. Quotation marks around the name are optional; however, the data set name must always be fully qualified. In this case, physical-filename cannot specify a UNIX System Services file.


Details

DSNEXST is a global statement. The first time the statement is issued, it creates the macro variable &SYSDEXST and assigns a value of 1 to it if the data set exists and is available for allocation or a value of 0 if the data set does not exist.

The following example allocates a data set differently depending on whether the data set already exists or not.

%macro mydsn;
   dsnexst 'my.data.set';
   filename myds 'my.data.set'
%if &sysdexst %then %do;
   disp=old;
   %end;

%else %do;
   disp=(new,catlg) space=(cyl,(1,1)) blksize=6160
      dsorg=ps recfm=fb lrecl=80 unit=disk
      volser='MYVOL';
   %end;

%mend mydsn;

%mydsn

The next example shows how you can submit some SAS statements if a data set already exists and bypass them if it does not.

%macro copylib;
   dsnexst 'my.data.library';
%if &sysdexst %then %do;
   libname mylib 'my.data.library' disp=shr;
   proc copy in=mylib out=work;
   run;
   %end;

%mend;

%copylib

In situations where there could be more than one user of the data set, the following example shows how you can use the &SYS99ERR automatic macro variable to distinguish between "data set does not exist" and "data set exists but is not available."

%macro dsexist(loc);
  dsnexst &loc;
  %if &sysdexst=0 and &sys99err=1708
    %then %do;
    %put &loc does not exist;
    %end;
  %else %do;
    %put &loc exists;
    %end;
  %mend;

%dsexist(my.data.set)

See Also


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.