Help using Base SAS procedures

Reading Date/Time Fields Into SAS

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

Reading Date/Time Fields Into SAS

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!


Accepted Solutions
Solution
‎07-14-2015 06:57 AM
Contributor
Posts: 44

Re: Reading Date/Time Fields Into SAS

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


All Replies
Solution
‎07-14-2015 06:57 AM
Contributor
Posts: 44

Re: Reading Date/Time Fields Into SAS

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;

Contributor
Posts: 59

Re: Reading Date/Time Fields Into SAS

Posted in reply to AskoLötjönen

Thanks, Asko. That works!

Contributor
Posts: 50

Re: Reading Date/Time Fields Into SAS

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,

Contributor
Posts: 59

Re: Reading Date/Time Fields Into SAS

Posted in reply to BrunoSilva

Thanks, Bruno!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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