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
Opal | Level 21

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
Opal | Level 21

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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