BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Engel
Calcite | Level 5

Dear SAS experts

I need your help with my data:

Here the detailed information:

My table is structured as follows:

I have 5 columns

1. Column serialNumber

2 Column: Name

3Rd column: First (time)

4Th column: Last (time)

5Th column: cycles (sec)

The 3rd and 4th columns contain always the same time, the duration column always contains 1 (sec)

Now I would like to summarize the time, if the difference in time is less than 10 seconds between two rows.

The column "name" may change, and the summary should take place only within the respective name (I hope this is understandable)

Example:

Can help me?

How can I handle it with SAS??

I would appreciate your help!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Try this (untested):

data tmp;
set have; by serialNumber name notsorted;
grp + (first.name or dif(last)<10);
run;

proc sql;
create table want as
select serialNumber, name, min(first) as first, max(last) as last, max(last)-min(first)+1 as cycle
from tmp
group by serialNumber, name, grp;

drop table tmp;
quit;

PG

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Try this (untested):

data tmp;
set have; by serialNumber name notsorted;
grp + (first.name or dif(last)<10);
run;

proc sql;
create table want as
select serialNumber, name, min(first) as first, max(last) as last, max(last)-min(first)+1 as cycle
from tmp
group by serialNumber, name, grp;

drop table tmp;
quit;

PG

PG
Engel
Calcite | Level 5

Dear PG Thanks a lot! I've just changed the "lower than" to a "greater than" sign, and it works fine! Best regards from Germany EH

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1069 views
  • 0 likes
  • 2 in conversation