SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
D_Z_
Obsidian | Level 7

I have looked all over the place for this and haven't been able to find anything to lead me in the right direction.

 

I have a dataset that is in SAS Time format HH:MM:SS (24 hours time format)... what i need to do is convert the time to seconds.

 

So for example, 0:12:28 would be converted to 748.  I know its possible.. i just can't find a way to do it.

 

Can anyone help with a datastep or a calculated field in a select statement that can do this.  The name of the field is TTL_AHT

 

Any help would be awesome!

 

DZ

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you have a TIME variable it is already in seconds.  Just remove the format if you want it to print as a raw number of seconds instead of being formatted to look like a time value.

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Run and have fun-->

 

data w;
k='0:12:28't;
k1='0:12:28';
k2=input(k1,time.);/* i think you want this*/
run;
Tom
Super User Tom
Super User

If you have a TIME variable it is already in seconds.  Just remove the format if you want it to print as a raw number of seconds instead of being formatted to look like a time value.

D_Z_
Obsidian | Level 7

Thanks Tom!  After I read... i realized that i was trying to complicate it way too much... i knew that deep down inside.  Thank you so much!

 

DZ

Reeza
Super User

SAS stores times as seconds natively. A format is used to control the display, so removing the format will create the raw seconds value.

 

data demo;
x='11:45't;
y=x;

format x time6.;
format y; *no format, not needed but how you would remove a format;

run;


proc print data=demo;run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 7103 views
  • 0 likes
  • 4 in conversation