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
...
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.