Your GROUP BY tells SAS at what levels to calculate. From your code snippet it looks like you've included Number in your GROUP BY when the numbers are different across the observations. SAS is correctly calculating what you've requested. Remove Numbers from the GROUP BY and Select statement. If you want to include it in the SELECT you'll need some sort of rule, ie max/min of which one to take. If it's first or last then then you'll need to go back to data step logic.
Here could give you a start :
option datestyle=mdy;
data have;
input id $ Number (Starttime Endtime) (: anydtdtm.);
format Starttime Endtime datetime.;
cards;
1a. 23 01/01/16:11:01:00 01/01/16:11:05:11
1a. 24 01/01/16:11:02:00 01/01/16:11:06:16
1a. 25 01/01/16:12:00:00 01/01/16:12:07:00
;
run;
data temp;
set have;
if lag(Endtime) lt Starttime or id ne lag(id) then g+1;
run;
data want;
set temp;
by g;
retain start num;
if first.g then do;start=Starttime;num=number;end;
if last.g then do;end=Endtime;output;end;
format start end datetime.;
drop Starttime Endtime number;
run;
You get what you want based this dataset .
CODE NOT TESTED
proc sort data=have ; by SITE END_TIME ;run;
data want;
set have;
by SITE ;
if first.SITE ;
run;
Sorry. I can't understand you. Show your data and code and the output you want .
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 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: