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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1053 views
  • 0 likes
  • 2 in conversation