I have tried many times to convert date into sas time value but do not get the result. I am sharing my syntax please
In your INPUT you need to give TIME5. informat.
data test1;
format final time5.;
set test;
char = put(date, z4.);
hour = substr(char,1,2);
min = substr(char,3,2);
con = trim(hour)||':'||trim(min);
final = input(con,time5.);
run;
thanks a ton....SuryaKiran
Do you have any other syntax to solve this problem...
this method looks lengthy
You can avoid creating unnecessary new variables and can create only one by combining all the function.
data test1;
format time time5.;
set test;
Time=input(CATX(":",substr(put(date, z4.),1,2),substr(put(date, z4.),3,2)),TIME5.);
run;
I don't think this is a lengthy process. If your data is not formatted properly then you need to go for all these extra.
Why not keep FINAL as a sas numeric time value (i.e. the number of seconds after midnight)? You can apply a format to display it as desired. And because it's a sas time-value you can do all sorts of time-interval calculations, if needed.
data test2;
set test;
final= 3600*floor(date/100)+ 60*mod(date,100);
format final time5.0;
run;
Why do you call a time value "date"? That will set you down the wrong path to begin with.
data want; set have; time = input(put(date,z4.),hhmmss4.); format time time5.; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.