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
UNTESTED CODE
data want;
merge one(in=in1 rename=(date=date1)) two(in=in2 rename=(date=date2));
by id;
if in1 and in2;
run;
Thank you for the support.
But I need to concatenate the datasets, not merging. Thank you
But I need to concatenate the datasets, not merging. Thank you
In that case @novinosrin has provided the solution.
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 three;
set one(in=in1) two(in=in2);
by id;
if first.id and in2 then delete;
format date date9.;
run;
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;
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.
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.