Thursday, September 12, 2013
Creating Validation using SAS format and Intelligent handling plus accumulating format validation error.
I created a small program to cross validate the incoming data with a Master data file.
Approach : I created SAS formats for various validation fields according to business rules applicable.
Then check the incoming data with the formats already created.
Then I accumulated the warning\error in a different file. This way I could accumlate all the error& warnings in one file.
1) Create a format by hardcoding , (I had created format using MS-access files too -- will cover it later on)
proc format library=prod;
value $TODA
'1001INTEGRATION_' = '7081'
'1001PROD' = '7081'
'1001SYSTEM_TEST' = '7081'
OTHER = '0'
;
run;
/*Store SAS format in to required lib*/
proc format
Fmtlib lib=work
cntlout=prod;
select $TODA;
run;
2) Performing validation
/* Validate all postings */
data work.AdjustmentX (drop=nr imperr impfield local_ammount_err accgroup)
work.errorlist_GL (keep=nr imperr impfield)
work.warnlist_GL (keep=nr imperr impfield)
work.cd12026_errorlist_adj (keep=nr imperr impfield)
;
set work.AdjustmentX end=slut;
if cd01001 > ' ' then do;
tst = put(cd01001,$accunit.); /* Performing validation */
if tst = 1 then do;
tst = put(compress(&cd01041!!cd01001),$ccac.);
if tst ^= 1 then do;
%FieldError(cd01001,Account unit not valid with company code &cd01041,errorlist_GL);
end;
end;
else do;
%FieldError(cd01001,Profit center invalid,errorlist_GL); /* Error macro */
end;
end;
else do;
if transaction_type = 'GL' then do;
%FieldWarning(cd01001,Tick-Off Ledger Id missing,Warnlist_GL); /* Warning Marco*/
end;
end;
run;
3) Accumulate Errors and warning via a general macro into a particular dataset.
Here i have called few general macros if there is a error or if i wana give a warning.
/* general macros*/
%macro FieldError(CD,errtxt,mem);
%if "&errtxt"="" %then %let errtxt=Wops;
%if "&CD"="" %then %let CD=WopsAgain;
imperr = "&errtxt";
impfield = &CD;
call symput('imperr',imperr !! impfield);
nr = _n_;
output &mem;
*put '---------------------' imperr= impfield= "&mem";
%mend;
%macro FieldWarning(CD,Warntxt,mem);
%if "&Warntxt"="" %then %let Warntxt=Wops;
%if "&CD"="" %then %let CD=WopsAgain;
impWarn = "&Warntxt";
impfield = &CD;
call symput('impWarn',impWarn !! impfield);
nr = _n_;
output &mem;
*put '---------------------' impWarn= impfield= "&mem";
%mend;
Note : /* Mention name of error log / warning log dataset as : &mem */
Let me know if anyone has any suggestion / doubts on this .
Happy to help , Chow !!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment