BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
goms
Fluorite | Level 6

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,
alertgroup,
alertkey,
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;

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

So what data type is src_lastmodified?

Data never sleeps
Oligolas
Barite | Level 11

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 -

goms
Fluorite | Level 6

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


sas-missing value.JPG

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
  • 4 replies
  • 11494 views
  • 2 likes
  • 3 in conversation