%let Q1 = 0.2;
%let Q2 = 0.3;
%let Q3 = 0.4;
%let Q4 = 0.5;
a1 has a column named
Qtr which indicates its quarter this year. Original code is
if Qtr = 1 then QtrE = &Q1;
if Qtr = 2 then QtrE = &Q2;
if Qtr = 3 then QtrE = &Q3;
if Qtr = 4 then QtrE = &Q4;
calculated = base * QtrE;
I think the original one is very clumsy. If the effect is by month not by quarter, then I have to write more code just to do the simple calculation. So I wrote the following code. But it didn't work. It seems the macro variable
Qtr did't change row by row.
calculated = base * &&&Qtr;
Best How To :
You should read the documentation on how symput() works in relation to the macro compiler and the data step compiler. http://support.sas.com/documentation/cdl/en/mcrolref/68140/HTML/default/viewer.htm#p09y28i2d1kn8qn1p1icxchz37p3.htm
Short story is that your code doesn't work because the macro compiler resolves &&&Qtr and then passes that to the Data Step.
Macros write SAS code for you. SAS code is then compiled and run.
Think about it this way, that Data Step is compiled into a foreach loop.
foreach(record in a1):
record.calculated = record.base * <value of &qtr>;
But the value of &qtr is resolved BEFORE the code above is written.
The creation of a lookup table is probably the best way to go. Left join that on the table with your values. There are numerous ways to do a left join in SAS.