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!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.