/******************* URBAN INSTITUTE MACRO LIBRARY *********************
: Dataset_exists
Macro: Returns TRUE (1) if a data set exists, FALSE (0) if not.
Description
: Function
Use
: Peter Tatian
Author
***********************************************************************/
Dataset_exists(
%macro /* Macro name */
dsn, quiet=Y, /* Suppress log messages (Y/N) */
memtype=data /* SAS file type (def. data set) */
);
/*************************** USAGE NOTES *****************************
:
SAMPLE CALLDataset_exists( Dat.MyFile, Quiet=N )
%true (1) if data set Dat.Myfile exists, false (0) otherwise
returns *********************************************************************/
/*************************** UPDATE NOTES ****************************
11/15/04 Added MEMTYPE= option to specify type of file (ACCESS,
DATA (def.), or VIEW).
CATALOG, *********************************************************************/
***** ***** ***** MACRO SET UP ***** ***** *****;
%
***** ***** ***** ERROR CHECKS ***** ***** *****;
%
***** ***** ***** MACRO BODY ***** ***** *****;
%
%if %sysfunc(exist(&dsn,&memtype)) %then %do;
1
%if %mparam_is_no( &quiet ) %then %do;
%Note_mput( macro=Dataset_exists, msg=The data set &dsn (%upcase(&memtype)) exists. )
%end;
%end;%else %do;
0
%if %mparam_is_no( &quiet ) %then %do;
%Note_mput( macro=Dataset_exists, msg=The data set &dsn (%upcase(&memtype)) does not exist. )
%end;
%end;
***** ***** ***** CLEAN UP ***** ***** *****;
%
%mend Dataset_exists;
/************************ UNCOMMENT TO TEST ***************************
options mprint nosymbolgen nomlogic;** Autocall macros **;
"K:\Metro\PTatian\UISUG\Uiautos";
filename uiautos =(uiautos sasautos);
options sasautos
data Exists;
run;
data _null_;= %Dataset_exists( Exists, Quiet=n );
x = %Dataset_exists( NoExist, Quiet=n );
y
= y=;
put x
run;/**********************************************************************/
Check if Dataset Exists
Purpose: Returns TRUE (1) if a data set exists, FALSE (0) if not.