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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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