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
proc sort data=have;
by cst_id date;
run;
now do the calculations using lag.
@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).
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: