BookmarkSubscribeRSS Feed
AmolGothe
Calcite | Level 5

I have a variable called post_time which is in the numeric format with values like 129, 203,252 etc I want to convert this variable into a time variable with values in format like follows:

129 to 13:29

203 to 14:03 etc.

need help for the code on this.

4 REPLIES 4
BrunoMueller
SAS Super FREQ

Hi

You can use the HMS function with the appropriate arguments. See sample below.

How can you know that the 1 in 129 is hour 13?

data have;
  infile cards;
 
input
    post_time :
8.
  ;
  date_s = hms(int(post_time / 100), mod(post_time, 100), 0);
  format date_s time8.;
cards;
129
203
252
;
AmolGothe
Calcite | Level 5

Thanks Bruno

I have a reference dataset (a csv file) and in that reference dataset they have used the post_time variable to calculate the time_variable that i am trying to calculate.

Regards

Amol Gothe

Kurt_Bremser
Super User

Still the question is, how are AM times represented? Seems like the one who created the file did not really engage her/his brain before starting to type. Or you missed some necessary information (maybe AM/PM is stored in another column of the csv?)

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am afraid it is too vague.  Why does 129 = 13:29 and not 01:29 which would seem more logical, how would 01:29 be represented?  Could it not also be 129 minutes past a certain time value?  Then its just time_point + 129. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 745 views
  • 0 likes
  • 4 in conversation