Hello Experts,
I would like to get the Year with Datepart function in proc sql, but my code doesn't work.
Could you help me, please :
proc sql;
create table TEST as
select count(distinct(ev.d_effet)) as nombre_versement_15ans from psaeu11.db_evenement ev,
psaeu11.dp_classe_evt classe
where ev.no_police = 'AFFGV'
and classe.b_ea =1 and classe.b_rachat = 1
and ev.is_classe_evt=classe.is_classe_evt and
year(datepart(y,ev.d_effet))>=year(datepart(y,today()))-15;
quit;
Thank you !
The DATEPART() function just converts number of seconds (DATETIME value) into number of days (DATE value). Basically it is just dividing by 24*60*60.
If you want the YEAR from a DATE value you can use the YEAR() function.
So if you want the YEAR from a DATETIME value you can just nest the two function calls.
select YEAR(DATEPART(datetime_var)) as year_var
...
The DATEPART() function has only one argument. You are using DATEPART() with two arguments, that won't work. DATEPART() also only works on data/time values, do your variables contain date/time values?
The DATEPART() function just converts number of seconds (DATETIME value) into number of days (DATE value). Basically it is just dividing by 24*60*60.
If you want the YEAR from a DATE value you can use the YEAR() function.
So if you want the YEAR from a DATETIME value you can just nest the two function calls.
select YEAR(DATEPART(datetime_var)) as year_var
...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.