BookmarkSubscribeRSS Feed
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Hey Fellow SAS_Forum_Campers,

Is this a SAS forum or a Perl forum?

After converting a character-string to a SAS DATETIME variable (seconds since 1/1/1960), you can use the SAS DATETIME format or you can extract the time-portion using the SAS CALL function TIMEPART. See below.

Scott Barry
SBBWorks, Inc.



22 data _null_;
23 dt = input('1/31/2009',mmddyy10.);
24 dttm = dhms(dt,9,9,9.222);
25 tm = timepart(dttm);
26 put dt= date9. dttm= datetime7. dttm=datetime9. tm= time12.3;
27 run;

dt=31JAN2009 dttm=31JAN09 dttm=31JAN2009 tm=9:09:09.222
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 second

Suggested Google advanced search arguments, this topic / post:

using sas dates site:sas.com

datetime date introduction site:sas.com
Pdogra
Calcite | Level 5
Thanks Sbb.

Well I could also do a substr to carry out the tasks but I am trying to utilise the power of regular expressions and that's very reason why SAS has included that.

Thanks,

PD
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Okay, so after you have corrected the format, then what? How will you know that the date, for example, 02/29/2010, is or is not valid? Then, what will you do with the string, if sorting "by chronological date" is needed? This is my point.

Scott Barry
SBBWorks, Inc.


13 data _null_;
14 dt = input('02/29/2010',mmddyy10.);
15 put dt= date.;
16 run;

NOTE: Invalid argument to function INPUT at line 14 column 6.
dt=.
dt=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of
the operations have been set to missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 14:6
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Pdogra
Calcite | Level 5
My apologies. Don't mean to make this complex. How about if you have datetime. (I am using SAS 9.1.3)


data have;
input have_date $18.;
format date date9.;
date=input(have_date,datetime16.);
cards;
7/1/2010:12:57
06/5/2009:10:57
04/05/2010:9:48
5/06/2010:6:48
;

or

data have;
input have_date $18.;
format date date9.;
date=input(have_date,datetime16.);
cards;
7/1/2010 12:57
06/5/2009 10:57
04/05/2010 9:48
5/06/2010 6:48
;

Datetime is not being read properly
Result (from first prog)


Obs have_date date

1 7/1/2010:12:57 .
2 06/5/2009:10:57 .
3 04/05/2010:9:48 .
4 5/06/2010:6:48 .


According to SAS : The datetime values must be in the following form: ddmmmyy or ddmmmyyyy, followed by a blank or special character, followed by hh:mm:ss.ss (the time). In the date


Message was edited by: Pdogra Message was edited by: Pdogra

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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