BookmarkSubscribeRSS Feed
ddavies
Calcite | Level 5

I would like to combine the client_count where actual_date_b is within 90 minutes?

 

actual_dateactual_date_bclient_cnt
4/13/202013APR2020:16:30:0010
4/14/202014APR2020:16:25:009
4/16/202016APR2020:15:00:0012
4/16/202016APR2020:16:20:001
4/13/202013APR2020:12:00:002
4/15/202015APR2020:12:00:001

 

The final table would only show actual_date and client_count.

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@ddavies wrote:

I would like to combine the client_count where actual_date_b is within 90 minutes?

 


Within 90 minutes of what?

--
Paige Miller
ddavies
Calcite | Level 5

When actual_date_b is within 90 minutes of itself, so in the table, the 3rd and 4th record would end up combined

ballardw
Super User

@ddavies wrote:

When actual_date_b is within 90 minutes of itself, so in the table, the 3rd and 4th record would end up combined


Since any value should be within "90 minutes of itself" need to provide a better rule.

Maybe in terms of "within 90 minutes of the previous (or any previous)" value.

PaigeMiller
Diamond | Level 26
data have2;
     set have;
     prev_actual_date_b = lag(actual_date_b);
     if (actual_date_b - prev_actual_date_b)>90*60 then count+1;
run;
proc summary data=have2 nway;
    class count;
    var client_cnt;
    id date;
    output out=want sum=;
run;

you don't say what want if you get three records like this

 

16APR2020:15:00:00

16APR2020:16:20:00

16APR2020:17:20:00



--
Paige Miller
Ksharp
Super User

This could give you a start .

 

data have;
infile cards expandtabs truncover;
input actual_date : mmddyy10.	actual_date_b : datetime32.	client_cnt;
format actual_date  mmddyy10.	actual_date_b  datetime32.;
cards;
4/13/2020	13APR2020:16:30:00	10
4/14/2020	14APR2020:16:25:00	9
4/16/2020	16APR2020:15:00:00	12
4/16/2020	16APR2020:16:20:00	1
4/13/2020	13APR2020:12:00:00	2
4/15/2020	15APR2020:12:00:00	1
;
run;

proc sql;
create table want as
select a.actual_date_b as group,b.*
from have as a,have as b
 where b.actual_date_b between a.actual_date_b and a.actual_date_b+'01:30:00't
  group by a.actual_date_b
   having count(*)>1;
quit;

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!

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
  • 5 replies
  • 492 views
  • 0 likes
  • 4 in conversation