Previous Page | Next Page

SAS Component Language Dictionary

EXIST



Verifies the existence of a member of a SAS data library
Category: SAS Table

Syntax
Details
Examples
Example 1: Verifying the Existence of a SAS Table
Example 2: Verifying the Existence of a SAS Data View
Example 3: Determining if a Data Set Generation Exists
Example 4: Querying for the Existence of an Audit Trail File
See Also

Syntax

rc=EXIST(member-name<,member-type<,generation>> );

rc

contains the return code for the operation:

1

The library member exists.

0

Either member-name does not exist or member-type is invalid.

Type: Numeric

member-name

is the name of the SAS data library member.

Type: Character

member-type

is the type of SAS data library member:

'ACCESS'

indicates an access descriptor that was created using SAS/ACCESS software.

'AUDIT'

indicates the existence of an associated audit file.

'CATALOG'

indicates a SAS catalog or catalog entry.

'DATA'

indicates a SAS data file. (This is the default.)

'MDDB'

indicates an MDDB.

'VIEW'

indicates a SAS data view.

Type: Character

generation

is the generation number of the SAS table whose existence you are checking. If member-type is not DATA, generation is ignored.

Type: Numeric


Details

If member-name is not specified, EXIST verifies the existence of the member specified by the system variable _LAST_. If member-type contains an invalid value, EXIST returns the value 0.


Examples


Example 1: Verifying the Existence of a SAS Table

Call the FSEDIT function only if the SAS table specified in the variable TABLENAME exists. If the table does not exist, display a message on the message line.

if (exist(tablename)) then call fsedit(tablename);
else _msg_='Table '||tablename||' does not exist.';


Example 2: Verifying the Existence of a SAS Data View

Verify the existence of the SAS table view TEST.MYVIEW:

rc=exist('test.myview','view');


Example 3: Determining if a Data Set Generation Exists

Determine if the third generation of the data set work.one exists:

rc=exist('work.one','data',3);


Example 4: Querying for the Existence of an Audit Trail File

You can query for the existence of an audit trail file via the EXIST function. An audit trail file is an optional SAS file that can be created to log changes to SAS data. To test the EXIST function, follow these steps:

  1. Create a data set with an audit file by entering the following code in the SAS Editor and then submitting it:

    data sasuser.class;
       set sashelp.class;
    run;
    proc datasets lib=sasuser;
       audit class;
       initiate;
      quit;

  2. Test for the existence of the audit file by entering the following code in an SCL file:

    INIT:
       hasAudit=exist('sasuser.class','AUDIT');
       put hasAudit=;
    return;

    When you compile and then execute the SCL code, the SAS log displays 'hasAudit=1', indicating that the audit file exists.

  3. Now delete SASUSER.CLASS and then recreated it without an audit file by entering and then submitting in the SAS Editor the following DATA step:

    data sasuser.class; set sashelp.class; run;

    When you execute the SCL code from step 2 , the SAS log displays 'hasAudit=0' (indicating that the audit file does not exist).


See Also

CEXIST

FEXIST

FILEEXIST

Previous Page | Next Page | Top of Page