COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to merge two SAS datasets without common variables?

• Follow

```Hi,
I have two datasets.
The first dataset looks like this:
company_name1    zipcode
aaa	         12345
bbb              23456
.....
The second dataset looks like this:
company_name2   sales
bcb             1000
bbc             2000
....
What is the fastest way for me to generate a dataset that has all the combinations of the observations, i.e.,
company_name1 zipcode company_name2 sales
aaa           12345   bcb           1000
aaa           12345   bbc           2000
bbb           23456  bcb            1000
bbb           23456  bbc            2000

Thank you very much!
```
 0
Reply zhumin80 (9) 3/2/2011 3:56:19 PM

```On Mar 2, 7:56=A0am, xzz <zhumi...@gmail.com> wrote:
> Hi,
> I have two datasets.
> The first dataset looks like this:
> company_name1 =A0 =A0zipcode
> aaa =A0 =A0 =A0 =A0 =A0 =A0 =A012345
> bbb =A0 =A0 =A0 =A0 =A0 =A0 =A023456
> ....
> The second dataset looks like this:
> company_name2 =A0 sales
> bcb =A0 =A0 =A0 =A0 =A0 =A0 1000
> bbc =A0 =A0 =A0 =A0 =A0 =A0 2000
> ...
> What is the fastest way for me to generate a dataset that has all the com=
binations of the observations, i.e.,
> company_name1 zipcode company_name2 sales
> aaa =A0 =A0 =A0 =A0 =A0 12345 =A0 bcb =A0 =A0 =A0 =A0 =A0 1000
> aaa =A0 =A0 =A0 =A0 =A0 12345 =A0 bbc =A0 =A0 =A0 =A0 =A0 2000
> bbb =A0 =A0 =A0 =A0 =A0 23456 =A0bcb =A0 =A0 =A0 =A0 =A0 =A01000
> bbb =A0 =A0 =A0 =A0 =A0 23456 =A0bbc =A0 =A0 =A0 =A0 =A0 =A02000
>
> Thank you very much!

Looks like you want a cross join.

Using PROC SQL

proc sql;
create table want as
select t1.*, t2.*
from have1 as t1
cross join have2 as t2;
quit;
```
 0
Reply Reeza 3/2/2011 5:32:31 PM

1 Replies
936 Views

(page loaded in 0.046 seconds)

Similiar Articles:

7/23/2012 9:54:52 PM