Help using Base SAS procedures

Changing STRING format INTO TIME format

Reply
New Contributor
Posts: 3

Changing STRING format INTO TIME format

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:MMSmiley FrustratedS. 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
N/A
Posts: 0

Re: Changing STRING format INTO TIME format

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.
New Contributor
Posts: 3

Re: Changing STRING format INTO TIME format

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Changing STRING format INTO TIME format

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.
New Contributor
Posts: 3

Re: Changing STRING format INTO TIME format

Thank you very much. It is working. I do really appreciate.
Ask a Question
Discussion stats
  • 4 replies
  • 217 views
  • 0 likes
  • 3 in conversation