Hi,
I do not understand why SAS has a result different for same dates. Only format is different, date or datetime.
Why happen this? I need the format datetime21.3
%let tdate = %sysfunc(today(),date9.);
%put &tdate.;
%let dois_anos_fmt = %sysfunc(intnx(year, %sysfunc(today()), -2, same), date9.);
%put &dois_anos_fmt.;result:
36 GOPTIONS ACCESSIBLE;
37 %let tdate = %sysfunc(today(),date9.);
38 %put &tdate.;
07MAY2018
39
40 %let dois_anos_fmt = %sysfunc(intnx(year, %sysfunc(today()), -2, same), date9.);
41 %put &dois_anos_fmt.;
07MAY2016
%let data_requerida = %sysfunc(today(),datetime21.3);
%put &data_requerida.;
%let data_dois_anos_menos = %sysfunc(intnx(year, %sysfunc(today()), -2, same), datetime21.3);
%put &data_dois_anos_menos.;result:
55 %let data_requerida = %sysfunc(today(),datetime21.3);
56 %put &data_requerida.;
01JAN60:05:55:11.000
57
58 %let data_dois_anos_menos = %sysfunc(intnx(year, %sysfunc(today()), -2, same), datetime21.3);
59 %put &data_dois_anos_menos.;
01JAN60:05:43:01.000
Regards,
Aleixo
Try this corrected code of your second version
%let data_requerida = %sysfunc(datetime(), datetime21.3);
%put &data_requerida.;
%let data_dois_anos_menos = %sysfunc(intnx(dtyear, %sysfunc(datetime()), -2, same), datetime21.3);
%put &data_dois_anos_menos.;
your code
%let data_requerida = %sysfunc(today(),datetime21.3);
%put &data_requerida.;Today() returns a date value and not a datetime value that you are trying to format using a datetime format
Dates and times are different. You can't substitute one for the other. It just doesn't work. It's like saying, "I baked a cake and I used ketchup instead of sugar. But it didn't come out right. Why?" They're just plain different.
To understand what SAS is expecting, you can start here:
https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002200738.htm
Try this corrected code of your second version
%let data_requerida = %sysfunc(datetime(), datetime21.3);
%put &data_requerida.;
%let data_dois_anos_menos = %sysfunc(intnx(dtyear, %sysfunc(datetime()), -2, same), datetime21.3);
%put &data_dois_anos_menos.;
Thank you all.
Yes the right function is datetime()
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.