BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CP2
Pyrite | Level 9 CP2
Pyrite | Level 9

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Reeza
Super User

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;

CP2
Pyrite | Level 9 CP2
Pyrite | Level 9

too simple! Thank you!

ballardw
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1696 views
  • 2 likes
  • 3 in conversation