BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

Hi Everyone,

When I import a CSV file into SAS, the column datetime having format mm/dd/yyyy hh:mm:ss is imported and in SAS it has:

Length 8

Format DATETIME16.

Informat ANYDTDTM40.

 

I use the below code to extract year month date and SAS give errors.

 

data intra; set intra;
year=year(datetime);
month=month(datetime);

hour=hour(datetime);
minute=minute(datetime);
second=second(datetime);
run;

NOTE: Invalid argument to function YEAR(1973854021.9) at line 218 column 6.
NOTE: Invalid argument to function MONTH(1973854021.9) at line 219 column 7.
_0=A _1=117.871 _2=479962 datetime=19JUL22:12:47:02 year=. month=. hour=12 minute=47
second=1.8895449638 date=. _ERROR_=1 _N_=1

 

Can you please help me with that?

Thanks

HHC

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

YEAR(),MONTH() and DAY() functions operate on DATE values (number of days)

HOUR(),MINUTE() and SECOND() functions operate on either DATETIME or TIME values (number of seconds).

 

To convert a DATETIME value to DATE value use the DATEPART() function.

year(datepart(datetime))

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

YEAR(),MONTH() and DAY() functions operate on DATE values (number of days)

HOUR(),MINUTE() and SECOND() functions operate on either DATETIME or TIME values (number of seconds).

 

To convert a DATETIME value to DATE value use the DATEPART() function.

year(datepart(datetime))
hhchenfx
Rhodochrosite | Level 12

Thank you for your help, Tom.

HHC

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2574 views
  • 0 likes
  • 2 in conversation