This is pretty simple and I think will work: 1. Get a list of all the columns in your current table and save them into a macro: proc sql noprint;
select upcase(name) into :fields separated by ","
from dictionary.columns
where libname = "SASHELP" and memname = "CARS";
run; *test; %put fields= &fields; >>fields= MAKE,MODEL,TYPE,ORIGIN,DRIVETRAIN,MSRP,INVOICE,ENGINESIZE,CYLINDERS,HORSEPOWER,MPG_CITY,MPG_HIGHWAY,WEIGHT,WHEELBASE,LENGTH Pass in your libname and memname values as macros. 2. Add this IF check to each of your individual %err_xxx checks: %macro err_1004(var);
if upcase(vname(var)) in ("&fields") then do;
Error_id=1003;
if &var. not in ('Business','Employee') then output;
end;
%mend; This way, if your current var isn't in the table (i.e. the list of values in &fields), the check won't run. Does that make sense? %macro err_1004(var);
if upcase(vname(var)) in ("&fields") then do;
Error_id=1003;
if &var. not in ('Business','Employee') then output;
end;
%mend;
%macro data_validation;
proc sql noprint;
select upcase(name) into :fields separated by ","
from dictionary.columns
where libname = "SASHELP" and memname = "CARS";
run;
data want;
length Error_id 8 Error_record $200;
keep Error_id Error_record ;
set have ;
Error_record=cats(FLT_LAYR_NM,'|',FYP_NM,'|',_TEAM_NM);
%err_1004(new_field)
run;
%mend;
%data_validation; Note, this is very similar to @mkeintz's solution. mkeintz's may be more efficient if your data is large since you won't check the list of fields for each datastep pass.
... View more