Solved
New Contributor
Posts: 4

# Merging two datasets without a common by variable

The first dataset (one) represents people (pid) and where they live (cid). The second data set (two) has where they live (cid) and a set of possible product choices (pho). I need a dataset that has, for each person, all the choices they face.  Note: the choice set changes based on where they live.  The below illustrates my issue.  The actual data has 90,000 persons living in 180 different locations that on average will have 20 choices.  The output data file will have approx. 1,800,000 obs.

Data one; input pid cid;
datalines;
1 1
2 1
3 1
4 2
5 2
;
data two; input cid pho;
datalines;
1 1
1 2
1 3
1 4
2 1
2 4
2 5
;

/*
needed output
pid cid pho
1 1 1
1 1 2
1 1 3
1 1 4
2 1 1
2 1 2
2 1 3
2 1 4
3 1 1
3 1 2
3 1 3
3 1 4
4 2 1
4 2 4
4 2 5
5 2 1
5 2 4
5 2 5
*/

Accepted Solutions
Solution
‎07-31-2015 11:31 PM
Posts: 4,930

## Re: Merging two datasets without a common by variable

This is a standard task for SQL:

proc sql;

create table three as

select one.*, two.pho

from one natural join two;

quit;

PG

PG

All Replies
Solution
‎07-31-2015 11:31 PM
Posts: 4,930

## Re: Merging two datasets without a common by variable

This is a standard task for SQL:

proc sql;

create table three as

select one.*, two.pho

from one natural join two;

quit;

PG

PG
🔒 This topic is solved and locked.