Exceptions

In many instances a node has data and variable requirements. If those restrictions are not met, then Enterprise Miner needs to be notified so that the client can display an appropriate message. This is accomplished by assigning a value to the macro variable &EMEXCEPTIONSTRING. For example, suppose you write code that does the following:
  • uses PROC MEANS to compute descriptive statistics of interval variables.
  • If class targets are present, then they are used as grouping variables.
  • saves the output statistics to the STATS output data set.
In the code below, an exception is generated if no interval variables are present.
%em_getname(key=STATS, type=DATA);
%macro means;
	%if %EM_INTERVAL_INPUT %EM_INTERVAL_TARGET eq %then %do;
		%let EMEXCEPTIONSTRING = ERROR;
		%put &em_codebar;
		%put Error: Must use at least one
			interval input or target.;
		%put &em_codebar;
		%goto doendm;
	%end;
	proc means data=&EM_IMPORT_DATA;
		%if %EM_BINARY_TARGET %EM_NOMINAL_TARGET
			%EM_ORDINAL_TARGET ne %then %do;
			class %EM_BINARY_TARGET
				%EM_NOMINAL_TARGET
				%EM_ORDINAL_TARGET;
		%end;
		var %EM_INTERVAL_INPUT
			%EM_INTERVAL_TARGET;
		output out=&EM_USER_STATS;
	run;
	%doendm:
%mend means;
%means;
You can literally populate &EMEXCEPTIONSTRING with any non-null string. All that really matters is that it is no longer null after the exception is encountered. The result is the same regardless of the string you use; you see a generic error message:
Run Status Error window
In the example above, if the input data source contained no interval input or target variables the following message would also appear in the SAS log:
*------------------------------------------------------------*
Error: Must use at least one interval input or target.
*------------------------------------------------------------*