Tips:Checking for a data set

From sasCommunity
Jump to: navigation, search
 %MACRO DATA_EXIST(INPUT);
  %IF %SYSFUNC(EXIST(&INPUT)) %THEN %DO;
 	%PUT DATA EXISTS;
  %END;
  %ELSE %DO;
 	%PUT DATA DOES NOT EXISTS;
  %END;
 %MEND;
 
 %DATA_EXIST(SASUSER.IMPW);

Very often, a directory is cluttered with so many data sets that it is impossible to look for a particular data file. To relieve such unnecessary distress, we can use a simple DATA step function named 'EXIST' to check for the existence of a certain SAS data file. A simple macro to achieve this is shown to the right. Further simplification mimics a macro function.

%MACRO D_EXIST(INPUT);
 %SYSFUNC(EXIST(&INPUT))
%MEND D_EXIST;

The macro %D_EXIST could be called from within an expression.

 %IF %D_EXIST(SASHELP.CLASS) %THEN %DO;

The function EXIST can also be used to find other type of data sets in the directory by changing the types of members that it should look for.

Submitted by Murphy Choy. Contact me at my Discussion Page.

....see also