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

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.

 

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
  • 806 views
  • 0 likes
  • 3 in conversation