BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi ,
iam trying to read the data for time stamp which is in below format
yyyy-mm-dd-hh.mm.ss.hshshs,please tell me which format can i use to read the data ,one more thing (field is numeric).
7 REPLIES 7
Patrick
Opal | Level 21
You have to use a INformat to read data. Formats are used to write data.
ANYDTDTMw. is a very convenient informat to read datetime values as it digests a number of different datetime STRINGS and converts them to a number representing a SAS datetime.
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a001239776.htm

What do you mean by "field is numeric"? Where do you try to read the data from? Could it be that this is more a data conversion problem (i.e. from ORACLE to SAS)?

If the field you want to read is already in SAS and contains a datetime value then it's only about:
newvar=datetimevar;
...and you might want to use a format to WRITE the values of this new var, i.e"
format newvar datetime21.;
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a001263753.htm

HTH
Patrick

Message was edited by: Patrick
deleted_user
Not applicable
thanx for your reply,
actually i am reading the data from text file to sas dataset ,then i need to convert that into datetime format
In first dataset after file reader field is Character,after converting field is numeric
value i ma getting from file is 2008-09-06-03.30.45.101010
GertNissen
Barite | Level 11
Perhaps this small sample can give you some hints
[pre]
data test;
datetime_txt = '2008-09-06-03.30.45.101010';

date_num = input(substr(datetime_txt,1,10), yymmdd10.);
time_num = input(substr(datetime_txt,12), time15.);

datetime_sas = date_num * 86400 + time_num;

put date_num date. time_num time. datetime_sas datetime22.;
run;
[/pre]
You have many ways to import and format your datetime, date and time values. Your 'problem' is that you got the year first in your datetime text, where's SAS normally got it last.
If you can find a SAS date function or informat/format then use it, and not the substr I use in the small sample above (its quick and dirty - like my 'dirty' datetime transformation).
Patrick
Opal | Level 21
data want;
infile datalines;
input MyDateTimeVar ANYDTDTM.;
put 'As a number: ' MyDateTimeVar= ' Formatted: ' MyDateTimeVar= datetime21.;
datalines;
2008-09-06-03.30.45.101010
;

HTH
Patrick
GertNissen
Barite | Level 11
Hi Patrick

Your right - ANYDTDTM. is a much better solution - I have learned something new, I didt knew that informat - tx.
deleted_user
Not applicable
Thanx patrick
deleted_user
Not applicable
ThanX GeniZ
i will try to user this now.........

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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