BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
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. 

 

Ksharp
Super User

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;
BETO
Fluorite | Level 6
Hi thank you everyone e that is assisting me ...whst I have is a data set that looks like this
SITE. NUMBER. START TIME. END TIME
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
Ksharp
Super User

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;
BETO
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
Ksharp
Super User

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

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

sas-innovate-2024.png

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
  • 2178 views
  • 2 likes
  • 4 in conversation