Dear All, I am trying to create a do loop where n will create a new column (withdrawal_&n) as well as act as a multiplier. While the code runs ok, each generated column is overwritten by the next e.g. withdrawals_4 overwrites withdrawal_3. IS there a way around this in proc sql? I appreciate that I can do the same in data step if I refer to the same table, but my preference is to do it within proc sql. I'm just learning the ropes to sas so any help would be greatly appreciated. %macro sqlloop; proc sql; %do n = 2 %to 4; %let field = Withdrawals_&n; create table test as select *, SUM(case WHEN time_on_books in (11,12,13) THEN BAL_THISMTH END) as Withdrawals_1, SUM(case WHEN time_on_books = (12*(&n-1))+11 or time_on_books = (12*(&n-1))+12 or time_on_books = (12*(&n-1))+13 THEN BAL_THISMTH END) as &field, FROM IS_tb1; %end; quit; %mend; %sqlloop
... View more