BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xtc283x
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
AskoLötjönen
Quartz | Level 8

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;

View solution in original post

4 REPLIES 4
AskoLötjönen
Quartz | Level 8

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;

xtc283x
Quartz | Level 8

Thanks, Asko. That works!

BrunoSilva
Quartz | Level 8

Hello,

This litle script will help you to find any informat in the future Smiley Happy

%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,

xtc283x
Quartz | Level 8

Thanks, Bruno!

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 813 views
  • 0 likes
  • 3 in conversation