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;


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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