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
*/
This is a standard task for SQL:
proc sql;
create table three as
select one.*, two.pho
from one natural join two;
quit;
PG
This is a standard task for SQL:
proc sql;
create table three as
select one.*, two.pho
from one natural join two;
quit;
PG
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!
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.