I've written the code for data validation for one dataset. I would like to develop further for multiple datasets using macro. Now the problem is that the rules which I want to write is not applicable for all the datasets. Because the variables for each dataset is not same.
Now I want to develop the below code to handle all the rules for multiple datasets. I want to feed the dataset name and variable names as keyword parameter macro.
data have;
infile cards dsd dlm='|' truncover;
input FLT_LAYR_NM :$10. FYP_NM :$30. _TEAM_NM :$30. ;
cards;
DIS|Consistencycheck|Business
DID|Rangecheck|Client
DID| |Client
DID|Rangecheck|Employee
;
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);
Error_id=1001;
if missing(FYP_NM) then output;
Error_id=1002;
if _TEAM_NM not in ('Business','Employee') then output;
run;
SAS code or something similar which I except:
But the challenge here is I want to skip the condition (or data validation) in case if the variable not exists in the calling macro.
%macro data_validation(table_name,variable1,variable2,variable3,variable4)
data have;
infile cards dsd dlm='|' truncover;
input FLT_LAYR_NM :$10. FYP_NM :$30. _TEAM_NM :$30. ;
cards;
DIS|Consistencycheck|Business
DID|Rangecheck|Client
DID| |Client
DID|Rangecheck|Employee
;
data want;
length Error_id 8 Error_record $200;
keep Error_id Error_record ;
set &table_name;
Error_record=cats(FLT_LAYR_NM,'|',FYP_NM,'|',_TEAM_NM);
/*data validation rule for variable 1*/
Error_id=1001;
if missing(&variable1) then output;
/*data validation rule for variable 2*/
Error_id=1002;
if &variable2 not in ('Business','Employee') then output;
run;
/*data validation rule for variable 3*/
Error_id=1003;
if &variable3 not in ('Bus','Train') then output;
run;
/*data validation rule for variable 4*/
Error_id=1004;
if &variable4 not in ('Hotel','Office') then output;
run;
%mend data_validation;
%data_validation(table_name,variable1,variable4)
... View more