Verifies the existence of a SAS data library member
Category: SAS File I/O
EXIST ( member- name < ,member-type < , generation >>)
member-name
specifies the SAS data library member. If member-name is blank or a null string, then EXIST uses the value of the _LAST_ system variable as the member-name .
member-type
specifies the type of SAS data library member. A few common member types are ACCESS, CATALOG, DATA, and VIEW. If you do not specify a member-type , then the member type DATA is assumed.
generation
specifies the generation number of the SAS data set whose existence you are checking. If member-type is not DATA, generation is ignored.
Positive numbers are absolute references to a historical version by its generation number. Negative numbers are relative references to a historical version in relation to the base version, from the youngest predecessor to the oldest. For example, -1 refers to the youngest version or, one version back from the base version. Zero is treated as a relative generation number.
EXIST returns 1 if the library member exists, or 0 if member-name does not exist or member-type is invalid. Use CEXIST to verify the existence of an entry in a catalog.
This example verifies the existence of a data set. If the data set does not exist, then the example displays a message in the log:
%let dsname=sasuser.houses; %macro opends(name); %if %sysfunc(exist(&name)) %then %let dsid=%sysfunc(open(&name,i)); %else %put Data set &name does not exist.; %mend opends; %opends(&dsname);
This example verifies the existence of the SAS data view TEST.MYVIEW. If the view does not exist, then the example displays a message in the log:
data _null_; dsname="test.myview"; if (exist(dsname,"VIEW")) then dsid=open(dsname,"i"); else put dsname 'does not exist.'; run;
This example verifies the existence of a generation data set by using positive generation numbers (absolute reference):
data new(genmax=3); x=1; run; data new; x=99; run; data new; x=100; run; data new; x=101; run; data _null_; test=exist('new', 'DATA', 4); put test=; test=exist('new', 'DATA', 3); put test=; test=exist('new', 'DATA', 2); put test=; test=exist('new', 'DATA', 1); put test=; run;
These lines are written to the SAS log:
test=1 test=1 test=1 test=0
You can change this example to verify the existence of the generation data set by using negative numbers (relative reference):
data new2(genmax=3); x=1; run; data new2; x=99; run; data new2; x=100; run; data new2; x=101; run; data _null_; test=exist('new2', 'DATA', 0); put test=; test=exist('new2', 'DATA', -1); put test=; test=exist('new2', 'DATA', -2); put test=; test=exist('new2', 'DATA', -3); put test=; test=exist('new2', 'DATA', -4); put test=; run;
These lines are written to the SAS log:
test=1 test=1 test=1 test=0 test=0
Functions:
'CEXIST Function' on page 434
'FEXIST Function' on page 526
'FILEEXIST Function' on page 528