Help using Base SAS procedures

date-time informats

Reply
Contributor
Posts: 47

date-time informats

Hi All,

I want to read into a dataset date times which look like the following: Note especially that 9:45...AM has one integer before the ":" and 10:02...PM has two.
26/01/2009 9:45:51 AM
26/01/2009 10:02:08 PM

Any suggestions?

Thanks,
Sachin
Super Contributor
Super Contributor
Posts: 3,174

Re: date-time informats

Posted in reply to SachinRuk
Have a look at the DATESTYLE= System option, first, for an appropriate setting to meet you data-input requirements.

Then consider ANYDTDTM INFORMAT which should handle the dd/mm/yyyy appropriately. Or alternatively, consider inputting the two date/time components individually with an INPUT statement, and then use the DHMS function to assign a SAS DATETIME variable.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

informats ANYDTDTM MDYAMPM site:sas.com

using dates and times site:sas.com
Super User
Posts: 10,028

Re: date-time informats

Posted in reply to SachinRuk
Hi.
I think SAS have some proper format can read it.
Hope Someone can point it out.I have another curve way after lookup documentation for a long time.

[pre]
data temp;
input date : ddmmyy10. time anydttme11.;
datetime=input(catx('/',put(date,date9.),put(time,timeampm11.)),datetime22.);
format datetime dateampm22.;
datalines;
26/01/2009 9:45:51 AM
26/01/2009 10:02:08 PM
;run;
proc print noobs;run;
[/pre]



Ksharp
Contributor
Posts: 47

Re: date-time informats

thing is im doing this from a csv file. And those date-times exist in ONE column. So any suggestions as to how to pull it in from a csv itself. OR if not pull the column in as text and do what you did there?

Sorry, Im just quite new to SAS

Sachin
Super User
Posts: 10,028

Re: date-time informats

Posted in reply to SachinRuk
OK.
That would not be too complicated.

[pre]
filename csv 'c:\test.csv';
data temp; ;
infile csv delimiter = ',' lrecl=32767 firstobs=1;
informat datetime $30.;
input datetime;
_datetime=input(catx('/',put( input(scan(datetime,1,' '),ddmmyy10.) ,date9.),put( input( catx(' ',scan(datetime,2,' '),scan(datetime,3,' ')) ,anydttme11. ) ,timeampm11.)),datetime22.);
format _datetime dateampm22. ;
keep _datetime;
run;
proc print noobs;run;
[/pre]



Ksharp
Super Contributor
Super Contributor
Posts: 3,174

Re: date-time informats

Did you read my reply and consider the appropriate INFORMAT approach to read your input file/cell?

Scott Barry
SBBWorks, Inc.
Super User
Posts: 10,028

Re: date-time informats

Ok.
I can not understand enough for your said.
Can you point out the proper formate to read this style of datetime ,
I do not find the informat after look up documentation for a long time.

Ksharp
Valued Guide
Posts: 634

Re: date-time informats

The ANYDTDTM informat will not handle the AM/PM. The MDYAMPM informat would do the trick, except it does not come in a DMY flavor. Assuming you have no control over the structure of the value, I think that you are back to parsing the input line.
Super Contributor
Super Contributor
Posts: 3,174

Re: date-time informats

Thanks for the correction, ArtC.

It appears that the DATESTYLE= system option is ignored for MDYAMPM and the AM|PM suffix string is ignored by the ANYDTDTM INFORMAT. Also, there is a SAS tech note about ANYDTDTM which is unresolved on some OS platforms.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 8 replies
  • 279 views
  • 0 likes
  • 4 in conversation