Hello SAS communities,
I want to merge a data set of individuals shopping at stores and store information. I have data set of individuals shop at which store and another dataset with store information. The two data sets are not of same size. How can I merge the information of store into the individual shopping data?
Example of my data:
Individual data like this:
id store
1 1
1 2
2 1
3 3
4 2
....
Store data like this:
store location convenience inventory
1 1 7 5
2 4 8 6
3 3 8 5
....
I want a data like this:
id store location convenience inventory
1 1 1 7 5
1 2 4 8 6
2 1 1 7 5
3 3 3 8 5
4 2 4 8 6
....
Thanks!
A tested one-->
data indiv;
input id store ;
cards;
1 1
1 2
2 1
3 3
4 2
;
data store;
input store location convenience inventory ;
cards;
1 1 7 5
2 4 8 6
3 3 8 5
;
proc sql;
create table want as
select a.*,location , convenience , inventory
from indiv a inner join store b
on a.store=b.store
order by a.id, store;
quit;
untested
data want;
merge indiv store;
by store;
run;
sort both the datasets by store before the merge
A tested one-->
data indiv;
input id store ;
cards;
1 1
1 2
2 1
3 3
4 2
;
data store;
input store location convenience inventory ;
cards;
1 1 7 5
2 4 8 6
3 3 8 5
;
proc sql;
create table want as
select a.*,location , convenience , inventory
from indiv a inner join store b
on a.store=b.store
order by a.id, store;
quit;
Again, thank you @novinosrin !
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.