BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Geo-
Quartz | Level 8

how to count time interval for each customer?

have:

idtime
10307MAR2015:09:13:02.00
10207DEC2015:10:42:19.00
10207DEC2015:10:43:39.00
10107MAY2015:09:13:30.00
10207DEC2015:10:43:51.00
10107MAY2015:09:13:41.00
10307MAR2015:09:13:05.00
10107MAY2015:09:13:55.00

 

want:

idtimeinterval
10107MAY15:09:13:30.
10107MAY15:09:13:4111
10107MAY15:09:13:5514
10207DEC15:10:42:19.
10207DEC15:10:43:3980
10207DEC15:10:43:5112
10307MAR15:09:13:02.
10307MAR15:09:13:053

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Yes having the seconds included makes it clear how the value is to be determined.

This problem has been solve by PG Stats at this link.  You might have to do a little work with the code so that the variables reference your case information.

https://communities.sas.com/t5/SAS-Programming/count-average-time-interval/m-p/487616#M127080

 

View solution in original post

4 REPLIES 4
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

How does interval get assigned?  your sample reflects that interval is char based on the sample being left justified.

Geo-
Quartz | Level 8
I have updated and add the seconds.Would it be more clear?thanks
mkeintz
PROC Star

You appear to want to do 2 things:

 

  1. Take unsorted data, and order it by ID/TIME.  Is that correct?

  2. There are multiple obs with ID101 and tied time values.  Are there other variables that would force a particular ordering of those tied records?  After all you have interval values of 11 and 14 for the 2nd and 3rd records.  I see no data that would produce those values.
  3. Calculate a new variable called interval, which is left missing for the first obs of each id, but has a positive value for all subsequent obs for each id.  As @VDD asked, what it the formula for generating the new variable interval?
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Yes having the seconds included makes it clear how the value is to be determined.

This problem has been solve by PG Stats at this link.  You might have to do a little work with the code so that the variables reference your case information.

https://communities.sas.com/t5/SAS-Programming/count-average-time-interval/m-p/487616#M127080

 

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