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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 824 views
  • 0 likes
  • 4 in conversation