BookmarkSubscribeRSS Feed
TRUST
Calcite | Level 5
Can someone help. I have a data with dates entered in STRING format. I will like to change in into the TIME format. I can do that in SPSS but failed to do it in SAS. The Data is in the form hh:MM:SS. When I checked the data using proc contents, it shows that the Times are in STRING format. This is how the data looks like: I tried to multiply TIME by 1, it did not work.

Time
10:20:30
09:08:08
09:06:50
4 REPLIES 4
deleted_user
Not applicable
Hi,

You can try the format time8. to convert the string to time number format.
But keep in mind that the output here which you get as a number will be the number of seconds starting from 1 Jan 1960 00:00:00
data test;
input timevar $10.;
timenum=input(timevar,time8.);
cards;
10:20:30
09:08:08
09:06:50
;
run;
proc print;
run;
Please check the following output.
10:20:30 37230
09:08:08 32888
09:06:50 32810


Thanks,
Saurabh.
TRUST
Calcite | Level 5
sorry it did not work. Currently the data that I have is in STRING FORMAT, I will like to convert it to TIME format. Sorry it did not work.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With SAS, your variables are either CHARACTER or NUMERIC type with an optional output FORMAT -- this can be identified with a PROC CONTENTS output report. The code example provided should properly convert your CHARACTER variable data string to a SAS NUMERIC type variable, where you would then need to apply a SAS FORMAT statement in your code.

If unsuccessful, suggest you share what SAS log you have demonstrating where the code is not working.

Scott Barry
SBBWorks, Inc.
TRUST
Calcite | Level 5
Thank you very much. It is working. I do really appreciate.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 2644 views
  • 0 likes
  • 3 in conversation