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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.