BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

I have 

data A;

input id    caldt  ret;

datalines;

1     01-2019 9

1     02-2019  10

2     03-2018   2

2      04-2018  4;

 

data B;

input id    caldt  tna;

dataline;

1     01-2020 12

1     02-2021  11

2     03-2019   3

2      04-2019  2;

 

want

id    tna   ret

1      12   9

1       11   10

2       3   2

2       2   4

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's the simplest program that might work:

 

data want;
   set A;
   set B;
   keep id tna ret;
run;

If you were to actually describe your intentions, a better program might be possible.  This program just matches observation by observation:  first from A with first from B, second from A with second from B, third from A with third from B, etc.  Perhaps that is what you want, but if not you will have to do more of the work.

View solution in original post

4 REPLIES 4
Reeza
Super User

What have you tried? SQL or Data step?

 

If you're not familiar with merges at all, the documentation has a full set of examples here (with code and data examples):

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=n1tgk0uanvisvon1r26lc036k0w7.htm&docsetVe...

 

You want to look at one to one merging or match merging section.

 


@sasphd wrote:

I have 

data A;

input id    caldt  ret;

datalines;

1     01-2019 9

1     02-2019  10

2     03-2018   2

2      04-2018  4;

 

data B;

input id    caldt  tna;

dataline;

1     01-2020 12

1     02-2021  11

2     03-2019   3

2      04-2019  2;

 

want

id    tna   ret

1      12   9

1       11   10

2       3   2

2       2   4


 

 

sasphd
Lapis Lazuli | Level 10

sql

Reeza
Super User
Can you post the code you tried?
Astounding
PROC Star

Here's the simplest program that might work:

 

data want;
   set A;
   set B;
   keep id tna ret;
run;

If you were to actually describe your intentions, a better program might be possible.  This program just matches observation by observation:  first from A with first from B, second from A with second from B, third from A with third from B, etc.  Perhaps that is what you want, but if not you will have to do more of the work.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 770 views
  • 0 likes
  • 3 in conversation