Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending Tables in SAS 1

Status
Not open for further replies.

JM3482

Technical User
Nov 7, 2003
17
US
I need to take three tables that I am creating in a SAS program and append them to one table. I am creating three separate tables from one main table. How do I put the three tables together?
 
There are two ways to append data in SAS. The first is directly in the data step with the SET statements. The second way is through the use of the PROC APPEND statement.

Make sure that the variables are the same (same names and same types) in all the datasets.
ex1.

data your_new_ds;
set ds1
ds2
ds3;
run;

ex2
proc append base=your_new_ds data=ds1;
run;
proc append base=your_new_ds data=ds1;
run;
proc append base=your_new_ds data=ds1;
run;

I hope that this helps you.
Klaz
 
Oops! One change, in the second and third PROC APPEND the statement should read as follows: data=ds2 & data=ds3.

I hope that you can use this.
Klaz
 
FYI the Proc Append also works QUITE well with inserting into ODBC databases (SQL or otherwise)... so it is an alternative to using Proc SQL... the only thing that I use if the FORCE option so that I do not have to worry about having all of the variables in the SAS dataset.

So I end up with

libname MySQL odbc dsn=sqlserver datasrc="PlantReportData" BCP=YES;

...

proc append data=work.NewStuff base=MySQL.MaterialUsage force;

just an FYI
 
thanks, I will give that a try also.
 
Here's a tip. Proc Append is particularly useful when appending a small dataset to a large dataset. If you use the example above using the SET statement, every row from each of the datasets is read and processed. With Proc Append, only rows from the second (data=) dataset are read. So if you have one large dataset (such as a historic file) to which you are appending a smaller dataset (current weeks data for example) then Proc Append is a more efficient way of coding it. Otherwise there really isn't much difference between the 2 methods.
Another alternative method is to use the UPDATE statement instead of SET and this will update records on the master dataset with the records from the transaction dataset with matching BY values. Probably not what you need in this case though.
Enjoy.
 
Thanks, I think I will try the update statement. Sounds interesting.
 
Remember to read the doco on Update before using it, you need to use a By statement and there are other considerations too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top