So I'm trying to create new columns, mon_&cur_buy and times_&cur_buy that hold values that are set to the values money and times, respectively, from the work.t table.
The criteria for assigning the new variables their values is if the name of the &cur_buy macro variable matches the current row's value for BuyName in the work.t table.
The &buyers macro variable referenced is simply a list of names separated by commas.
The error that I'm getting saying that the new variables, mon_&cur_buy and times_&cur_buy are invalid.
The names are resolved correctly but are never written to the new dataset, decvars.
%let names = %quote(&buyers);
%let count = %sysfunc(countw(&buyers));
data decvars;
set work.t;
i=1;
do while (i <= &count);
%let cur_buy = %qscan(&names,&i,%str(,));
length mon_&cur_buy 8;
length times_&cur_buy 8;
if BuyName = "&cur_buy" then do;
mon_&cur_buy = money; /*still getting that statement is invalid here*/
times_&cur_buy = times;
end;
i=i+1;
end;
run;
Ultimately, I'm trying to create separate columns for purchases from each buyer for regression analysis that only contain values of purchases from a certain buyer. If you have any advice about how to automate this kind of process using a macro variable, please let me know.