How to check whether a SAS dataset exist or not and throw an error in the log ?

/* if the data set exists, then conditionally execute the step(s). %sysfunc checks the availability of the data in the library location. It means it checks historical sas data. It generates the system error if the not is data available at the defined library  */

%let dsname=&dataval.MKT_DATA;  /**** declaring data set name with library*****/
%macro warning1(name);
%if %sysfunc(exist(&name)) %then %do;


Proc printto log="&logfile.\WarningLog..txt" new;     /*** printing log in the text file at specifile location &logfile****/
run;
%Put WARNING :- &name does not exists;

Proc printto  ;
Run;
%end;

%else
%do;
Proc printto log="&logfile.\WarningLog.txt" ;
run;
%put &name exists;

Proc printto  ;
Run;
%end;
%mend ;
%warning1(&dsname);



/**** Pros:  If any sas process is dependent on the existence of the data then we can use this macro***/
/**** Cons:  *Even if the SAS data set is available with zero observation it will not generate any system error hence not useful in that case**/

Comments

Popular posts from this blog

Solution for ERROR: Some character data was lost during transcoding in the dataset

2018 plan for getting expertise in Machine Learning and Deep Learning