BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

I need to concatenate the datasets "one and two" to  get last date from data two. 

 

In data two there are more  subjects than data one. I need to have in my output only subjects that are in dataone. Please help . Thank you

 

data one;
input id date date9.
datalines;
1 05OCT2015
2 06OCT2015
3 07OCT2015
;
data two;
input id date date9.;
datalines;
1 05DEC2015
2 06DEC2015
3 07DEC2015 
4 08DEC2015
;

code:

 

data three;

set one two;

run;

 

output needed;

id date

1 05OCT2015
2 06OCT2015
3 07OCT2015

1 05DEC2015
2 06DEC2015
3 07DEC2015

6 REPLIES 6
PaigeMiller
Diamond | Level 26

UNTESTED CODE

data want;
    merge one(in=in1 rename=(date=date1)) two(in=in2 rename=(date=date2));
    by id;
    if in1 and in2;
run;
--
Paige Miller
knveraraju91
Barite | Level 11

Thank you for the support.

But I need to concatenate the datasets, not merging. Thank you

PaigeMiller
Diamond | Level 26

But I need to concatenate the datasets, not merging. Thank you



 

In that case @novinosrin has provided the solution.

--
Paige Miller
novinosrin
Tourmaline | Level 20

A silly solution, forgive me but fun:

 

data one;
input id date :date9.;
format date date9.;
datalines;
1 05OCT2015
2 06OCT2015
3 07OCT2015
;
data two;
input id date :date9.;
format date date9.;
datalines;
1 05DEC2015
2 06DEC2015
3 07DEC2015
4 08DEC2015
;
data temp;
merge one(in=a) two(in=b);
by id;
if a and b;
run;
data want;
set one temp;
run;

data_null__
Jade | Level 19
data three;
   set one(in=in1) two(in=in2);
   by id;
   if first.id and in2 then delete;
   format date date9.;
   run;

Capture.PNG

Ksharp
Super User
Assuming there are not duplicated ID in both tables.



data one;
input id date :date9.;
format date date9.;
datalines;
1 05OCT2015
2 06OCT2015
3 07OCT2015
;
data two;
input id date :date9.;
format date date9.;
datalines;
1 05DEC2015
2 06DEC2015
3 07DEC2015
4 08DEC2015
;
data want;
 set one two;
 by id;
 if first.id and last.id then delete;
run;


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

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
  • 6 replies
  • 1977 views
  • 4 likes
  • 5 in conversation