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
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))
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))
Thank you for your help, Tom.
HHC
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!
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.
Ready to level-up your skills? Choose your own adventure.