I have variable with time with values like 515 which should be read like 5:15 To do this I used the following code-
data flights;
set cs.flights;
format sched_dep_time hhmm. dep_time hhmm. ;
run;
but i get result for 515 as 0.09 which I think is the time it is calculating from 12:00 am in seconds . I also use time. format but no use. how do i deal with this?
You will need to convert your number into a SAS Time value for this to work.
data test;
timeAsNum=515;
format timeAsSAS time5.;
timeAsSAS=int(timeAsNum/100)*3600+mod(timeAsNum,100)*60;
run;
Actually.... If you're just interested how your numeric variable prints but you don't need it to be a SAS Time value then a Picture format could serve the purpose as well.
proc format;
picture numWithColon
low-high = '00:00'
;
quit;
data test;
format timeAsNum numWithColon4. timeAsSAS time5.;
timeAsNum=515;
timeAsSAS=int(timeAsNum/100)*3600+mod(timeAsNum,100)*60;
run;
Try this:
data flights;
set cs.flights;
sched_dep_time_t = hms(int(sched_dep_time/100), mod(sched_dep_time, 100), 0);
dep_time_t = hms(int(dep_time/100), mod(dep_time, 100), 0);
format sched_dep_time_t dep_time_t hhmm. ;
drop sched_dep_time dep_time;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.