For reference, here is my macro code. The basic idea is that it generates a list of desired values (or coefficients) from one data set, then in the second data set multiplies all the matching variables by their coefficients and adds them together into a single variable. It doesn't quite work yet, but I think I could make it to work if I understood how I can force scan to see a variable name instead of a string. The underlined part is what I'm referencing in the previous post.
%macro freezer (data=, coefficients=, varcol=, valcol=, variables=, combined=, outdata=);
/* This is pretty much polingjw's code and puts a list of desired values separated by spaces into "expression" */
proc sql noprint;
select distinct &valcol into: expression separated by ' '
from &coefficients
where find("&variables", trim(&varcol)) > 0;
quit;
/* end polingjw's code */
/* set out data set to data set */
data &outdata; set &data;
&combined = 0;
i = 1;
run;
/* create new variable that multipies desired variables by their matching coefficients */
data &outdata; set &outdata;
do until(scan(expression, i) = ' ');
&combined = &combined + scan(expression, i) * scan("&variables", i); i+1;
output;
end;
drop i expression;
run;
%mend freezer;
... View more