Hi All
Please help, I have two datasets:
Name Acc Code
Shop1 A0001 Stationery
Shop2 A0002 Clothes
Shop3 A0003 Groceries
Date Acc Phone_Number
01MAY2012 A0001 00112000009
01MAY2012 A0001 00112000010
01MAY2012 A0001 00112000011
01MAY2012 A0002 00112000555
01MAY2012 A0002 00112000666
01MAY2012 A0003 00112005678
I want to merge the two datasets to achieve the below dataset:
Date : Acc: Phone_Number: Name: Code:
01MAY2012 A0001 00112000009 Shop1 Stationery
01MAY2012 A0001 00112000010 Shop1 Stationery
01MAY2012 A0001 00112000011 Shop1 Stationery
01MAY2012 A0002 00112000555 Shop2 Clothes
01MAY2012 A0002 00112000666 Shop2 Clothes
01MAY2012 A0003 00112005678 Shop3 Groceries
Thanks 🙂
Hi,
Try this..Hope it helps..
data one;
input Name $ Acc $ Code $ 20.;
cards;
Shop1 A0001 Stationery
Shop2 A0002 Clothes
Shop3 A0003 Groceries
;
run;
data two;
input Date Acc $ Phone_Number;
informat Date date9.;
format Date date9.;
cards;
01MAY2012 A0001 00112000009
01MAY2012 A0001 00112000010
01MAY2012 A0001 00112000011
01MAY2012 A0002 00112000555
01MAY2012 A0002 00112000666
01MAY2012 A0003 00112005678
;
run;
data want;
merge one(in=a) two(in=b);
by acc;
if a;
run;
Thanks,
Shiva
Hi,
Try this..Hope it helps..
data one;
input Name $ Acc $ Code $ 20.;
cards;
Shop1 A0001 Stationery
Shop2 A0002 Clothes
Shop3 A0003 Groceries
;
run;
data two;
input Date Acc $ Phone_Number;
informat Date date9.;
format Date date9.;
cards;
01MAY2012 A0001 00112000009
01MAY2012 A0001 00112000010
01MAY2012 A0001 00112000011
01MAY2012 A0002 00112000555
01MAY2012 A0002 00112000666
01MAY2012 A0003 00112005678
;
run;
data want;
merge one(in=a) two(in=b);
by acc;
if a;
run;
Thanks,
Shiva
Thank you Shivas, worked great!!
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!
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.