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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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