Function DATEPART requires a numeric expression as argument 1.

Solved
Occasional Contributor
Posts: 11

Function DATEPART requires a numeric expression as argument 1.

Hi,

Below query gives an error  Function DATEPART requires a numeric expression as argument 1.

proc sql;

create table sample as
select

identifier,
serial,
node,
nodealias,
manager,
agent,
summary,
location,
class,
poll,
type,
tally,
severity,
owneruid,
ownergid,
acknowledged,
put (datepart(src_lastmodified),yymmdd10.)||" "||put(timepart(src_lastmodified),time9.1) as src_lastmodified
from test.sample1;
quit;

Accepted Solutions
Solution
‎06-27-2016 10:12 AM
Regular Contributor
Posts: 164

Re: Function DATEPART requires a numeric expression as argument 1.

You need to convert the character dates to numeric for using datepart and timepart function as in this example:

``````data sample1;
src_lastmodified=put(datetime(),is8601dt.);
run;

proc sql;
select
put(datepart(input(src_lastmodified,is8601dt.)),yymmdd10.)
||" "
||put(timepart(input(src_lastmodified,is8601dt.)),time9.1) as src_lastmodified
from sample1;
quit;``````
________________________

- Cheers -

All Replies
Super User
Posts: 5,890

Re: Function DATEPART requires a numeric expression as argument 1.

So what data type is src_lastmodified?

Data never sleeps
Occasional Contributor
Posts: 11

Re: Function DATEPART requires a numeric expression as argument 1.

Char type

Solution
‎06-27-2016 10:12 AM
Regular Contributor
Posts: 164

Re: Function DATEPART requires a numeric expression as argument 1.

You need to convert the character dates to numeric for using datepart and timepart function as in this example:

``````data sample1;
src_lastmodified=put(datetime(),is8601dt.);
run;

proc sql;
select
put(datepart(input(src_lastmodified,is8601dt.)),yymmdd10.)
||" "
||put(timepart(input(src_lastmodified,is8601dt.)),time9.1) as src_lastmodified
from sample1;
quit;``````
________________________

- Cheers -

Occasional Contributor
Posts: 11

Re: Function DATEPART requires a numeric expression as argument 1.

[ Edited ]

Hi ,

Thanks for your reply. While executing the below query it returns missing value (.)

proc sql;
select
put(datepart(input(src_lastmodified,is8601dt.)),yymmdd10.)
||" "
||put(timepart(input(src_lastmodified,is8601dt.)),time9.1) as src_lastmodified
from test.sample1;
quit;

Date format needs to changed from

20160531 00:04:37 to 2016-05-31 00:04:37

🔒 This topic is solved and locked.