BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
spg
Obsidian | Level 7 spg
Obsidian | Level 7

I’m trying to create a table by

  • First, running proc expand on a variable (100+) and
  • Second, append these newly created variables on to one single table.

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

2 REPLIES 2
ballardw
Super User

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;

spg
Obsidian | Level 7 spg
Obsidian | Level 7

Thank you ballardw! That did the trick.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1306 views
  • 0 likes
  • 2 in conversation