BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Super User

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. 


Super User

Here could give you a start :



option datestyle=mdy;
data have;
input id $ Number  (Starttime Endtime) (: anydtdtm.);
format Starttime Endtime datetime.;
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
data temp;
 set have;
 if lag(Endtime) lt Starttime or id ne lag(id) then g+1;
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;
Fluorite | Level 6
Hi thank you everyone e that is assisting me ...whst I have is a data set that looks like this
123. A3 06dec2015:8:24:00 .06dec2015:08:26;00

123. A3 06dec2015:8:26:00 .06dec2015:08:40:00

What I want is the min an max of those 2 entries nothing else something like this

123. A3 06dec2015:8:24:00 .06dec2015:08:40:00
The other 2 can be removed
What I'm getting is all 4 entries or just the min
123. A3 06dec2015:8:24:00 .06dec2015:08:26;00
Thank you again

BTW there are other dates in my data sometimes it brings those dates as my min an max for example
123. A3 03dec2015:8:25500 .06dec2015:08:26;00. Which means it's looking st who data I need it to look at each day spefic
Super User

You get what you want based this dataset .


proc sort data=have ; by SITE  END_TIME ;run;
data want;
 set have;
 by SITE  ;
 if first.SITE  ;
Fluorite | Level 6
Hi ksharp I added the data step ...where you state data want is it a table your refer or column? I refer to table it failed ? The set an if are highlighted in red log states. 180-322 statement is not valid or it used out of proper order
Super User

Sorry. I can't understand you. Show your data and code and the output you want .

Fluorite | Level 6
Ksharp I fig it out thanks for your help


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

What is Bayesian Analysis?

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.

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
  • 21 replies
  • 4 in conversation