I’m trying to create a table by
However, when I use this code below, it keeps replacing the newest variable instead of adding them . .. So instead of a table with 100+ variables, I end up with a table with just a couple. Where am I going wrong?
%macro test;
%do i=1 %to 110;
data got&i;
set have (keep=date var&i);
run;
proc expand data= got&i out=want&i;
convert var&i = new_var&i /transformout=(movave 4);
run;
proc sql;
create table final as
select a.*, b. new_var&i
from semifinal a
left join want&i b on a.date=b.date;
quit;
%end;
%mend;
%testmacro;
I don't know what is in you table Semifinal but you keep replacing the table Final with the contents of Semifinal and one variable.
I expect that you only have the 110th variable in last version of Final. If I understand what you may be attempting you need to do something after each "create table final" to make it the table semifinal. Maybe:
proc sql;
create table final as
select a.*, b. new_var&i
from semifinal a
left join want&i b on a.date=b.date;
Create table semifinal as
select * from final;
quit;
I don't know what is in you table Semifinal but you keep replacing the table Final with the contents of Semifinal and one variable.
I expect that you only have the 110th variable in last version of Final. If I understand what you may be attempting you need to do something after each "create table final" to make it the table semifinal. Maybe:
proc sql;
create table final as
select a.*, b. new_var&i
from semifinal a
left join want&i b on a.date=b.date;
Create table semifinal as
select * from final;
quit;
Thank you ballardw! That did the trick.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.