BookmarkSubscribeRSS Feed
Xamius32
Calcite | Level 5

So I am trying to combine a bunch of tables into one based on certain conditions. I am not sure how I would write a macro or do loop for it so I dont have to repeat the union step for each table.

This is what I have so far, and would need to do for ~80 tables

create table test as select monthend, loan_no, balance, portfolio, DELQIND180 from lp.lp_200512

where DELQIND180 ne "0" and portfolio="CORE" or portfolio="NAT"

union

select monthend, loan_no, balance, portfolio,  DELQIND180 from lp.lp_200601

where DELQIND180 ne "0" and portfolio="CORE" or portfolio="NAT"

union

select monthend, loan_no, balance, portfolio,  DELQIND180 from lp.lp_200602

where DELQIND180 ne "0" and portfolio="CORE" or portfolio="NAT";

quit;

4 REPLIES 4
yeshwanth
Fluorite | Level 6

Hello,

Try this...

Data final;

set lp_200512 - lp_200600; // ( Specify the Range here )

run;


// This prog will append all the data sets from lp_200512 to lp_200600..

Xamius32
Calcite | Level 5

I forgot to mention, it is by month/year, so its 200512, 200601, 200602...200612, 200701, etc.

yeshwanth
Fluorite | Level 6

Okey,

Try this

Data final;

set lp_200512 -- lp_200712; // ( Specify "--" will append all the data sets which are between 200512 to 200712)

run;

Astounding
PROC Star

If you want to combine ALL the data set names that have the right naming pattern, you could use:

data want;

   set ip.ip_20: ;

   where ...;

run;

The WHERE statement would be applied to all the data sets.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1005 views
  • 0 likes
  • 3 in conversation