turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Join 2 Data Sets (DataSet_1, DataSet2) and save th...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-12-2013 10:36 AM

Hi,

I have 2 data sets (DataSet1 , DataSet2):

- The Data Set "DataSet1" has 2 variables (1_A , 1_B) with 3 observations

1_A | 1_B |

2 | 2 |

3 | 1 |

5 | 19 |

- The Data Set "DataSet2" has 3 variables (2_A , 2_B , 2_C) with 2 observations

2_A | 2_B | 2_C |

2 | -5 | 9 |

21 | 13 | 8 |

I want to join these 2 Data Sets, and SAVE as a new Data Set named "DataSet3" as show below:

1_A | 1_B | 2_A | 2_B | 2_C |

2 | 2 | 2 | -5 | 9 |

3 | 1 | 21 | 13 | 8 |

5 | 19 | . | . | . |

How shoud I proceed?

Thanks!

Accepted Solutions

Solution

07-12-2013
01:52 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Wagner_Alvarenga

07-12-2013 01:52 PM

One-to-One merging from SAS documentation

One-to-one merging combines observations from two or more SAS data sets into a single observation in a new data set. To perform a one-to-one merge, use the MERGE statement without a BY statement. SAS combines the first observation from all data sets that are named in the MERGE statement into the first observation in the new data set, the second observation from all data sets into the second observation in the new data set, and so on. In a one-to-one merge, the number of observations in the new data set is equal to the number of observations in the largest data set named in the MERGE statement. See Example 1 for an example of a one-to-one merge. For more information, see Reading, Combining, and Modifying SAS Data Sets in SAS Language Reference: Concepts.

Syntax

data dataset3;

merge dataset1 dataset2;

run;

example:

data d1;

input var1;

datalines;

1

2

3

;

run;

data d2;

input var2;

datalines;

2

3

;

run;

data d3;

merge d1 d2;

run;

Vincent

All Replies

Solution

07-12-2013
01:52 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Wagner_Alvarenga

07-12-2013 01:52 PM

One-to-One merging from SAS documentation

One-to-one merging combines observations from two or more SAS data sets into a single observation in a new data set. To perform a one-to-one merge, use the MERGE statement without a BY statement. SAS combines the first observation from all data sets that are named in the MERGE statement into the first observation in the new data set, the second observation from all data sets into the second observation in the new data set, and so on. In a one-to-one merge, the number of observations in the new data set is equal to the number of observations in the largest data set named in the MERGE statement. See Example 1 for an example of a one-to-one merge. For more information, see Reading, Combining, and Modifying SAS Data Sets in SAS Language Reference: Concepts.

Syntax

data dataset3;

merge dataset1 dataset2;

run;

example:

data d1;

input var1;

datalines;

1

2

3

;

run;

data d2;

input var2;

datalines;

2

3

;

run;

data d3;

merge d1 d2;

run;

Vincent