/*
The strategy pattern allows algorithm variation based on the parameters. In this pattern, one macro implements the
algorithm, and the selection comes to the implementation macro through the macro parameters
*/
data work.taxExample;
length grossAmount totalTax 8;
grossAmount = 34000;
run;
%macro calculateTaxes(dataset,county);
%macro taxStrategy(county);
%macro DeKalb;
totalTax = grossAmount * 0.06;
%mend deKalb;
%macro Fulton;
totalTax = grossAmount * 0.075;
%mend Fulton;
%macro Gwinnett;
totalTax = grossAmount * 0.06;
%mend Gwinnett;
%if &county. = DeKalb or
&county. = Fulton or
&county. = Gwinnett %then
%&county.;
%mend taxStrategy;
data &dataset.;
set &dataset.;
%taxStrategy(&county.);
run;
proc print data=&dataset.;
run;
%mend calculateTaxes;
%calculateTaxes(dataset=work.taxExample, county=Fulton);
No comments:
Post a Comment