The macro looks fine to me, but without having the data it's hard to know what's happening in your CALL EXECUTE step. I didn't test that it works with the SPDE engine.
I would a %PUT statement to your macro, to have it write to the log the value for the parameters &ds, &var, and also the returned value. It's possible you'll be surprised by those values. Something like:
%macro varexist
/*----------------------------------------------------------------------
Check for the existence of a specified variable.
----------------------------------------------------------------------*/
(ds /* Data set name */
,var /* Variable name */
,debug=0
);
/*----------------------------------------------------------------------
Usage Notes:
%if %varexist(&data,NAME)
%then %put input data set contains variable NAME;
The macro calls resolves to 0 when either the data set does not exist
or the variable is not in the specified data set.
----------------------------------------------------------------------*/
%local dsid rc return;
/*----------------------------------------------------------------------
Use SYSFUNC to execute OPEN, VARNUM, and CLOSE functions.
-----------------------------------------------------------------------*/
%let dsid = %sysfunc(open(&ds));
%if (&dsid) %then %do;
%if %sysfunc(varnum(&dsid,&var)) %then %let return=1;
%else %let return=0 ;
%let rc = %sysfunc(close(&dsid));
%end;
%else %let return=0;
%if &debug=1 %then %do ;
%put macro call %nrstr(%%)VAREXIST(&ds,&var) returns: &return ;
%end ;
&return
%mend varexist;
%put >>%varexist(sashelp.class,name,debug=1)<< ;
%put >>%varexist(sashelp.class,nope,debug=1)<< ;
... View more