BookmarkSubscribeRSS Feed
ccnky123
Calcite | Level 5

The original table is like:

cst_iddate
A012015/5/6 9:13:59
A022015/5/7 10:09:8
A012015/5/7 15:12:02
A022015/5/9 15:09:45
A012015/5/12 23:07:33 
A02 2015/5/13 14:03:16

and finally get:(the real table for column date may be disorder)

cst_iddatedate1interval
A012015/5/6 9:13:59 06may2015 9:13:59 .
A012015/5/7 15:12:02 07may2015 15:12:02 107863
A012015/5/12 23:07:33  12may2015 23:07:33 460531
A022015/5/7 10:09:01 07may2015  10:09:01 .
A022015/5/9 15:09:23 09may2015 15:09:23 190837
A02 2015/5/13 14:03:16 13may2015 14:03:16 341611

 

Data step will be preferable! thank you for your attention 

2 REPLIES 2
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

proc sort data=have;

by cst_id date;

run;

now do the calculations using lag.

 

Kurt_Bremser
Super User

@ccnky123 wrote:

The original table is like:

cst_id date
A01 2015/5/6 9:13:59
A02 2015/5/7 10:09:8
A01 2015/5/7 15:12:02
A02 2015/5/9 15:09:45
A01 2015/5/12 23:07:33 
A02  2015/5/13 14:03:16

and finally get:(the real table for column date may be disorder)

cst_id date date1 interval
A01 2015/5/6 9:13:59  06may2015 9:13:59  .
A01 2015/5/7 15:12:02  07may2015 15:12:02  107863
A01 2015/5/12 23:07:33   12may2015 23:07:33  460531
A02 2015/5/7 10:09:01  07may2015  10:09:01  .
A02 2015/5/9 15:09:23  09may2015 15:09:23  190837
A02  2015/5/13 14:03:16  13may2015 14:03:16  341611

 

Data step will be preferable! thank you for your attention 


Use the scan() fubction to dissect yor "date" string. input() the first "word" with yymmdd10., and the second with time8.

Then build the datetime value with dhms(date,0,0,time).

After that, use lag() as advised.

For code, provide your example data in usable form (data step with datalines).

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 648 views
  • 0 likes
  • 3 in conversation