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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1181 views
  • 0 likes
  • 3 in conversation