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

Dear All,

 

I have to find the difference between the two times in character format. Can some one help me on these...

 

09:15 17:40----Have to find difference between these two.Ideally i would like to conver numeric sas format and then do the subtraction.

09:40 16:50----Have to find difference between these two

 

Thanks in advance.

Rakesh

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data test;
format time1 time2 diff time8.;
time1 = input('09:15',time5.);
time2 = input('17:40',time5.);
diff = time2 - time1;
output;
time1 = input('09:40',time5.);
time2 = input('16:50',time5.);
diff = time2 - time1;
output;
run;

proc print data=test noobs;
run;

Result:

  time1       time2        diff

9:15:00    17:40:00     8:25:00
9:40:00    16:50:00     7:10:00

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User
data test;
format time1 time2 diff time8.;
time1 = input('09:15',time5.);
time2 = input('17:40',time5.);
diff = time2 - time1;
output;
time1 = input('09:40',time5.);
time2 = input('16:50',time5.);
diff = time2 - time1;
output;
run;

proc print data=test noobs;
run;

Result:

  time1       time2        diff

9:15:00    17:40:00     8:25:00
9:40:00    16:50:00     7:10:00
rakeshvvv
Quartz | Level 8

Thank you Sir..

art297
Opal | Level 21

Are the pairs in one or separate strings?

 

Art, CEO, AnalystFinder.com

 

Shmuel
Garnet | Level 18

convert char time as var="09:15" using time_1 = input(var,time5.);

 

to calculate the difference just do: diff = intck('minute',time_1,time_2);

 

 

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
  • 2382 views
  • 1 like
  • 4 in conversation