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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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