DATA Step, Macro, Functions and more

convert time to sas time

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

convert time to sas time

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


Accepted Solutions
Solution
‎02-23-2017 11:01 AM
Super User
Posts: 7,832

Re: convert time to sas time

Posted in reply to rakeshvvv
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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎02-23-2017 11:01 AM
Super User
Posts: 7,832

Re: convert time to sas time

Posted in reply to rakeshvvv
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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 145

Re: convert time to sas time

Posted in reply to KurtBremser

Thank you Sir..

PROC Star
Posts: 7,485

Re: convert time to sas time

Posted in reply to rakeshvvv

Are the pairs in one or separate strings?

 

Art, CEO, AnalystFinder.com

 

Trusted Advisor
Posts: 1,575

Re: convert time to sas time

Posted in reply to rakeshvvv

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);

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 195 views
  • 1 like
  • 4 in conversation