DATA Step, Macro, Functions and more

Help with merge

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Help with merge


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 :-)


Accepted Solutions
Solution
‎06-25-2012 04:04 AM
Super Contributor
Posts: 349

Re: Help with merge

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

View solution in original post


All Replies
Solution
‎06-25-2012 04:04 AM
Super Contributor
Posts: 349

Re: Help with merge

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

Contributor
Posts: 36

Re: Help with merge

Thank you Shivas, worked great!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 168 views
  • 0 likes
  • 2 in conversation