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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1916 views
  • 2 likes
  • 4 in conversation