Help using Base SAS procedures

Table not appending properly

Accepted Solution Solved
Reply
Contributor spg
Contributor
Posts: 61
Accepted Solution

Table not appending properly

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;


Accepted Solutions
Solution
‎04-06-2015 03:16 PM
Super User
Posts: 10,500

Re: Table not appending properly

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


All Replies
Solution
‎04-06-2015 03:16 PM
Super User
Posts: 10,500

Re: Table not appending properly

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;

Contributor spg
Contributor
Posts: 61

Re: Table not appending properly

Thank you ballardw! That did the trick.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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