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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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