BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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
;
3 REPLIES 3
novinosrin
Tourmaline | Level 20

 


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

user24feb
Barite | Level 11

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;
ballardw
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1301 views
  • 2 likes
  • 4 in conversation