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

Merging two datasets without a common by variable

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

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
Respected Advisor
Posts: 4,930

Re: Merging two datasets without a common by variable

Posted in reply to MichaelWku

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

View solution in original post


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

Re: Merging two datasets without a common by variable

Posted in reply to MichaelWku

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.

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

Discussion stats
  • 1 reply
  • 299 views
  • 0 likes
  • 2 in conversation