Any one can help?
I want to convert a datetime to a year using proc sql in sas Eg.
for example, convert any time between '01Apr2001:00:00:00'dt and '31Mar2002:00:00:00'dt into 2002
between '01Apr2002:00:00:00'dt and '31Mar2003:00:00:00'dt into 2003
............
'
year=(year(datepart(date))+1)-(month(datepart(date))<=3);
*example for dates, not date time;
data have;
do i='01Jan2012'd to '31Dec2013'd;
year=(year(i)+1)-(month(i)<=3);
output;
end;
format i date9.;
run;
Assuming its Proc SQL and not SQL Pass-Through
Try year(datepart(variable)))
Thanks, not exactly for my question
See my answer in this thread:
https://communities.sas.com/thread/41166
An alternative would be to create a user defined format.
I wrote a proc format code , but it come out with error message
here is the log attached.
but I still dont know how to correct it.Can you help me please.
I got one answer for initial question
year(intnx('year.4',datepart(time),1))
Thanks
March 31 is always 275 days until the end of the calendar year (even during leap year), so this works:
fiscal_year=year(datepart(intnx('dtday', datetime_var,275)));
year=(year(datepart(date))+1)-(month(datepart(date))<=3);
*example for dates, not date time;
data have;
do i='01Jan2012'd to '31Dec2013'd;
year=(year(i)+1)-(month(i)<=3);
output;
end;
format i date9.;
run;
Thanks Reeza!
Awsome answer, it worked well.
Thanks Mifisher, your answer works well. sorry I was not allowed to choose two correct answer.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.