I am using %SYMEXIST to check if a macro variable exists and then continue or skip based on the result. It sounds so simple but SAS is throwing errors for all the approaches I have tried so far.
&num_tables is a macro created from a dataset based on certain conditions.
proc sql noprint;
select distinct data_name into :num_tables separated by ' '
from TP_data
where trim(upcase(Data_Name)) in
(select distinct(trim(upcase(Data_Name))) from Check_table
where COALESCE(Num_Attri_DR,0)-COALESCE(Num_Attri_Data,0) = 0
and Name_Missing_Column eq ' ' and Var_Name eq ' ');
quit;
If this macro var is not resolved or not created (no rows selected from the dataset), I would like to skip. When I used,
%if %symexist(num_tables) %then %do;
SAS gives an error with the message "MACRO variable name X must start with a letter or underscore". So I tried removing leading spaces using all of the following approaches:
%let num_tables = &num_tables; /* approach 1 */
%let num_tables = %sysfunc(trim(&num_tables)) /* approach 2 */
%let num_tables = %trim(&num_tables) /* approach 3 */
But none of these worked. I still get the error "MACRO variable name X must start with a letter or underscore"