Hello
I have a numeric value that represent time
for example 101600 is 10:16:00 (hour 10 ,mimutes 16,seconds 0)
How can I convert it into time variable please?
Use PUT() to create a string, CATX() to make it into a proper format for INPUT():
data _null_;
num = 101600;
length string $8;
string = put(num,z6.);
string = catx(":",substr(string,1,2),substr(string,3,2),substr(string,5,2));
time = input(string,time8.);
format time time8.;
put time=;
run;
Use PUT() to create a string, CATX() to make it into a proper format for INPUT():
data _null_;
num = 101600;
length string $8;
string = put(num,z6.);
string = catx(":",substr(string,1,2),substr(string,3,2),substr(string,5,2));
time = input(string,time8.);
format time time8.;
put time=;
run;
Or get the numeric parts of the value and use HMS function.
data junk; num = 101600; time = hms(int(num/10000),mod(int(num/100),100),mod(num,100)); format time time8.; run;
@Ronein wrote:
Hello
I have a numeric value that represent time
for example 101600 is 10:16:00 (hour 10 ,mimutes 16,seconds 0)
How can I convert it into time variable please?
If it's a time of day (i.e., at most 235959), you can also use the B8601TM. informat:
time=input(put(num,z6.),b8601tm.);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.