DATA Step, Macro, Functions and more

append datasets and new variables that exist in the added data

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 133
Accepted Solution

append datasets and new variables that exist in the added data

Hello, 

Is there a way to vertically append new data to an existing dataset but also bring over the new variables that don't exist in the base dataset? I thought 'force' would do it but it is not carrying over the new variables. Proc datasets with append doesn't do it either. What I want is a full join which includes all observations from both and all variables from both. 


proc append base=dataprep3 data=AppendEMR force ;
run;


Accepted Solutions
Solution
‎10-19-2016 02:00 PM
Super User
Posts: 17,840

Re: append datasets and new variables that exist in the added data

In SQL this is UNION ALL

 

data want;

set table1 table2:

run;

 

prox sql;

create table want2 as 

select * from table1

union all

select * from table2;

quit;

View solution in original post


All Replies
Solution
‎10-19-2016 02:00 PM
Super User
Posts: 17,840

Re: append datasets and new variables that exist in the added data

In SQL this is UNION ALL

 

data want;

set table1 table2:

run;

 

prox sql;

create table want2 as 

select * from table1

union all

select * from table2;

quit;

Frequent Contributor
Frequent Contributor
Posts: 133

Re: append datasets and new variables that exist in the added data

too simple! Thank you!

Super User
Posts: 10,500

Re: append datasets and new variables that exist in the added data

Note that if you have the same variable name but with different types you'll get an error.

If a same named variable has different lengths assigned you will get a warning message about possible truncation of data. Pay attention to these as you may actually lose critical data.

Also if other variable characteristics such as assigned label or format differs then you may want to verify that the desired one is in the results.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 223 views
  • 2 likes
  • 3 in conversation