BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MichaelWku
Calcite | Level 5

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
*/

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

1 REPLY 1
PGStats
Opal | Level 21

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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