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

I have imported a data set from excel and I want to calculate the difference between two columns, StdTime and FinTime.  The format in SAS data set looks like this:

StdTime     FinTime

5:30.45      5:33.02

4:20.10      4:15.14

6:03.55      6:05.21

where the text above read as m:ss.millisec and the time should be less tha 10mins.

I want to add a column to my existing data set for the time difference between these two columns for each row but it seems the time format is not readable by SAS.  Please kindly help and thank you for your attention.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You can read them this way:

 

data test;
input (t1 t2) ($);
StdTime = input(cats("0:",t1),anydttme11.);
FinTime = input(cats("0:",t2),anydttme11.);
difTime = FinTime - StdTime;
format StdTime FinTime difTime time12.2;
drop t1 t2;
datalines;
5:30.45      5:33.02
4:20.10      4:15.14
6:03.55      6:05.21
;
proc print; run;

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

You can read them this way:

 

data test;
input (t1 t2) ($);
StdTime = input(cats("0:",t1),anydttme11.);
FinTime = input(cats("0:",t2),anydttme11.);
difTime = FinTime - StdTime;
format StdTime FinTime difTime time12.2;
drop t1 t2;
datalines;
5:30.45      5:33.02
4:20.10      4:15.14
6:03.55      6:05.21
;
proc print; run;

PG
acma
Calcite | Level 5
I changed your code a little bit to fit as a data set column and works flawlessly. Thanks for your solution.

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
  • 2 replies
  • 845 views
  • 1 like
  • 2 in conversation