Hi,
I've been trying to run a do loop for a proc sql statement using the below code
%macro create_tables(start,end);
%do i = &start. %to &end.;
proc sql;
create table a_bal as select
a.*,
b.a_balance%sysevalf(&i.)
from accounts a
left join cashflows b
on a.account_no = b.account_no;
quit;
%end;
%mend;
%create_tables(39,134);
But the table output only contains the first column and the last iteration of the loop i.e. a_balance134
Any idea how to get this table to have all the a_balance fields from 39-134?
Thanks
You always create the same table:
create table a_bal as select
so you overwrite the result in every iteration of the macro do loop.
You seem to have a data design problem (wide dataset structure), which is solved best by using proc transpose:
proc transpose data=cashflows out=cashflows_long;
by account_no;
var a_balance39-a_balance134;
run;
Then join over account_no.
You always create the same table:
create table a_bal as select
so you overwrite the result in every iteration of the macro do loop.
You seem to have a data design problem (wide dataset structure), which is solved best by using proc transpose:
proc transpose data=cashflows out=cashflows_long;
by account_no;
var a_balance39-a_balance134;
run;
Then join over account_no.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: