I have a pipe delimited file that contains several date/time fields with information like this: '2/8/2015 0:00:00' What is the datetime function that would read these fields in and allow me to use the daypart() or timepart() functions to break them out separately?
Thanks!
Anydtdtm informat is quite clever :
data have;
attrib dtm format=datetime21. informat=anydtdtm21.;
input dtm ;
cards;
2/8/2015 0:00:00
;
run;
data want;
set have;
attrib datep format=date9.;
attrib timep format=time8.;
datep=datepart(dtm);
timep=timepart(dtm);
run;
Anydtdtm informat is quite clever :
data have;
attrib dtm format=datetime21. informat=anydtdtm21.;
input dtm ;
cards;
2/8/2015 0:00:00
;
run;
data want;
set have;
attrib datep format=date9.;
attrib timep format=time8.;
datep=datepart(dtm);
timep=timepart(dtm);
run;
Thanks, Asko. That works!
Hello,
This litle script will help you to find any informat in the future
%let STR_TO_FIND=%str(2/8/2015 0:00:00); data find_informat; length source $ 100; format result datetime.; set sashelp.vformat; where fmttype eq "I"; source_str="&STR_TO_FIND."; result=inputn(source_str,fmtname); if result ne .; keep source_str result fmtname; run; |
Best regards,
Thanks, Bruno!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.