BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Havi
Obsidian | Level 7


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 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
shivas
Pyrite | Level 9

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

2 REPLIES 2
shivas
Pyrite | Level 9

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

Havi
Obsidian | Level 7

Thank you Shivas, worked great!!

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 Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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