Join 2 Data Sets (DataSet_1, DataSet2) and save the result as DataSet3

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Join 2 Data Sets (DataSet_1, DataSet2) and save the result as DataSet3

Hi,

I have 2 data sets (DataSet1 , DataSet2):

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

1_A1_B
22
31
519

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

2_A2_B2_C
2-59
21138

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

1_A1_B2_A2_B2_C
222-59
3121138
519...

How shoud I proceed?

Thanks!


Accepted Solutions
Solution
‎07-12-2013 01:52 PM
Super Contributor
Posts: 339

Re: Join 2 Data Sets (DataSet_1, DataSet2) and save the result as DataSet3

Posted in reply to Wagner_Alvarenga

One-to-One merging from SAS documentation

One-to-One Merging

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

View solution in original post


All Replies
Solution
‎07-12-2013 01:52 PM
Super Contributor
Posts: 339

Re: Join 2 Data Sets (DataSet_1, DataSet2) and save the result as DataSet3

Posted in reply to Wagner_Alvarenga

One-to-One merging from SAS documentation

One-to-One Merging

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

🔒 This topic is solved and locked.

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

Discussion stats
  • 1 reply
  • 328 views
  • 1 like
  • 2 in conversation