BookmarkSubscribeRSS Feed
Symun23
Calcite | Level 5

Hello,

 

So I have two tables, one of them is a historical table (Table 1) that I am storing all data in, the other is a table that updates with new data and deletes old data that is no longer needed (Table 2).

 

I am wanting to take the new data from Table 2 and add it on to Table 1, what is the easiest way to do this? I will be able to identify the new data as there is a field that identifies new data going in, so the data goes in in batches and I have the name of the new batches going in.

 

Is Proc Append the best thing in this situation?

4 REPLIES 4
Kurt_Bremser
Super User

proc append cannot delete data from the base dataset, it only adds new data to the (physical) end of the base dataset.

Please supply some example data (see my footnotes) to illustrate how you would want to handle the delete's.

Symun23
Calcite | Level 5
Thats fine, I am not wanting to delete anything, just want to add the new data from Table 2 and add it on to the end of Table 1
Kurt_Bremser
Super User

@Symun23 wrote:
Thats fine, I am not wanting to delete anything, just want to add the new data from Table 2 and add it on to the end of Table 1

Then use proc append. Keep in mind that you need exclusive access to the base dataset while appending (no process may have the dataset opened).

SuryaKiran
Meteorite | Level 14

Hi,

 

PROC APPEND might not work for you, because when you have extra variable in data=table2 that are not in base=table1 FORCE option concatenates and drops the extra variables. Missing values will be assigned to variables that are in base=table1 but not in data=table2. I suggest you using proc sql set operator OUTER UNION CORR or Data step SET statement. 

 

When you are using PROC APPEND with FORCE keep in mind that dropping/truncating might occur.

 

Check PROC APPEND vs OUTER UNION vs SET statement results here:

 

data allvars;
  set sashelp.class (obs=5);
run;

data onevar (keep= name_ age);
  set sashelp.class (obs=5 rename=(name=name_));
run;
 
proc append base=onevar data=allvars force ;
run;

proc print data=onevar;
run;

proc sql;
create table allvars_ as
select * from allvars
outer union corr
select * from onevar;
quit;

data allvars;
set allvars onevar;
run;

 

Thanks,
Suryakiran

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 4 replies
  • 2680 views
  • 0 likes
  • 3 in conversation