Previous Page | Next Page

Functions and CALL Routines

EXIST Function



Verifies the existence of a SAS library member.
Category: SAS File I/O

Syntax
Arguments
Details
Examples
Example 1: Verifying the Existence of a Data Set
Example 2: Verifying the Existence of a Data View
Example 3: Determining If a Generation Data Set Exists
See Also

Syntax

EXIST(member-name<,member-type<, generation>>)


Arguments

member-name

is a character constant, variable, or expression that specifies the SAS 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

is a character constant, variable, or expression that specifies the type of SAS library member. A few common member types include ACCESS, CATALOG, DATA, and VIEW. If you do not specify a member-type, then the member type DATA is assumed.

generation

is a numeric constant, variable, or expression that 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.


Details

If you use a sequential library, then the results of the EXIST function are undefined. If you do not use a sequential library, then EXIST returns 1 if the library member exists, or 0 if member-name does not exist or member-type is invalid.

Use the CEXIST function to verify the existence of an entry in a catalog.


Examples


Example 1: Verifying the Existence of a Data Set

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);


Example 2: Verifying the Existence of a Data View

This example verifies the existence of the SAS 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;


Example 3: Determining If a Generation Data Set Exists

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


See Also

Functions:

CEXIST Function

FEXIST Function

FILEEXIST Function

Previous Page | Next Page | Top of Page