BookmarkSubscribeRSS Feed
SachinRuk
Calcite | Level 5
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
8 REPLIES 8
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Ksharp
Super User
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
SachinRuk
Calcite | Level 5
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
Ksharp
Super User
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Did you read my reply and consider the appropriate INFORMAT approach to read your input file/cell?

Scott Barry
SBBWorks, Inc.
Ksharp
Super User
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
ArtC
Rhodochrosite | Level 12
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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
  • 8 replies
  • 1454 views
  • 0 likes
  • 4 in conversation