BookmarkSubscribeRSS Feed
naomimaisel
Calcite | Level 5

Hello. I am new to SAS and apologize if this is elementary. I am using NHANES data and already have a dataset in place for a 3-year period. That said, I just found the same data I need for 3 more years. How do I add this data to my existing dataset?

 

Thank you!

4 REPLIES 4
Reeza
Super User

The operation is known as Appending, and it depends. 

 

If your data sets have the exact same data structure, including variable names/types then you can do an append. If not, you should ideally make them the same and then append. 

 

Append stacks data, adds more rows, same variables.

Merges bring the data side by side, adds more columns/variables.

 

For appending you can use PROC APPEND or SET in a Data step.

This is an example of an append, except I'm appending the same data twice.

 

data double_class;
set sashelp.class 
     sashelp.class;

run;
SASKiwi
PROC Star

A simple dataset concatenation where you stack all of the new data on top of the old data should do the trick:

 

data want;
  set existing new;
run;
Kurt_Bremser
Super User

PROC APPEND or a DATA step with several datasets in the SET statement will do nicely.

The difference between the two methods is: the DATA step will do a complete rewrite of the dataset, while APPEND will append physically to the existing dataset.

APPEND is less tolerant about changes in the data structure, though.

LinusH
Tourmaline | Level 20
A third option would be SQL INSERT INTO.
The downside is that you need to keep track of the column order.
The upside is that SQL is close to common knowledge. Performance is comparable with proc append.
Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1420 views
  • 0 likes
  • 5 in conversation