Dear,
In my data, each subject has startdate(sdate) enddate(edate) of dose of a drug taken. For the derivation an variable I need an output dataset with first.sdate of each subject and last.edate of each subject. Thank you
output need;
id sdate edate
1 05OCT2015 30OCT2015
2 05OCT2015 29OCT2015
3 06OCT2015 25OCT2015
data one;
input id sdate edate date9.
datalines;
1 05OCT2015 06OCT2015
1 06OCT2015 17OCT2015
1 17OCT2015 30OCT2015
2 05OCT2015 10OCT2015
2 11OCT2015 20OCT2015
2 20OCT2015 25OCT2015
2 26OCT2015 29OCT2015
3 06OCT2015 17OCT2015
3 17OCT2015 25OCT2015
;
data one;
input id sdate : date9. edate :date9.;
format sdate edate date9.;
datalines;
1 05OCT2015 06OCT2015
1 06OCT2015 17OCT2015
1 17OCT2015 30OCT2015
2 05OCT2015 10OCT2015
2 11OCT2015 20OCT2015
2 20OCT2015 25OCT2015
2 26OCT2015 29OCT2015
3 06OCT2015 17OCT2015
3 17OCT2015 25OCT2015
;
data want;
set one;
by id;
retain _sdate;
if first.id then _sdate=sdate;
else if last.id then sdate=_sdate;
if last.id;
drop _sdate;
run;
Regards,
Naveen Srinivasan
Try:
Proc SQL;
Create Table Want As
Select id,
Min(sdate) as sdate Format=Date9.,
Max(edate) as edate Format=Date9.
From one
Group By id;
Quit;
If there are no other variables involved:
proc summary data=have nway;
class id;
var sdate edate;
ouput out=want(drop= _:) min(sdate)= max(edate)=;
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.