SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Combine datasets

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Combine datasets

Hello,

 

I want to combine two datasets (file attached). In general, the objective is to copy a specific string of texts in one dataset for all observations in another dataset.

 

Thank you very much!

 

Thierry

 


Accepted Solutions
Solution
‎01-27-2017 06:59 AM
Super User
Posts: 5,093

Re: Combine datasets

In general, a solution would be:

 

proc sql;

create table a3 as select * from a1, a2;

quit;

 

There are other simple ways, if you know that your data set a2 always contains a single observation.  For example:

 

data a3;

if _n_=1 then set a2;

set a1;

run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,413

Re: Combine datasets

Post test data, in the form of a datastep in the body of the post.  I am not opening some dodgy internet xl file.  If you need to combine datasets then this is called merging (SAS) or joining (SQL).  In each instance you identify common identifiers in both datasets, then merge one to the other based on collection of observations you want at the end, this graphic shows the types of SQL joins (merge has similar):

Capture.PNG

Contributor
Posts: 33

Re: Combine datasets

I need a code because I have thousands opairs of datasets which I need to combine one with its partner. Thank you very much!

 

Thierry

Super User
Super User
Posts: 7,413

Re: Combine datasets

Then you need to hire a contractor, this is a question and answer board - you asked how to join data from one dataset to another you do that by joins or by merges as described in that graphic which also provides code on how to do such a thing.  Once you have one working then you can look at creating a macro - depends on how samey your data is.  

Solution
‎01-27-2017 06:59 AM
Super User
Posts: 5,093

Re: Combine datasets

In general, a solution would be:

 

proc sql;

create table a3 as select * from a1, a2;

quit;

 

There are other simple ways, if you know that your data set a2 always contains a single observation.  For example:

 

data a3;

if _n_=1 then set a2;

set a1;

run;

Contributor
Posts: 33

Re: Combine datasets

Dear @Astounding Thank you very much for your code. It is simple but it is all I need. The code is very helpful for me. Thanks.

 

Thierry

Super User
Posts: 6,963

Re: Combine datasets

The proper way to supply example data is a data step with datalines included. While Excel files can easily carry malware and are therefore blocked by most company firewalls, SAS code is just text and considered harmless.

It is also a matter of basic courtesy, as it enables your potential helpers to recreate your data with a simple copy/paste and run.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 33

Re: Combine datasets

Thank you very much, in the future I will take into account this matter.
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 725 views
  • 5 likes
  • 4 in conversation