%let begTrans = %sysfunc( intnx( dtyear, /* unit of time interval */ %sysfunc(datetime()), /* function to get current datetime */ -1 , /* number of intervals, negative goes to the past */ beginning /* alignment of interval date. "Same" is for same day of month/same time , "beginning" as start, end as ending*/ ) ); %put &=begTrans;
why is just using the same, when I have written beginning ? I want it to keep 01Jan until we get to a new year then it will do the change
Hi @Kiteulf,
Whilst it is typically better to work with SAS dates, they are not very human readable. Have you tried formatting (e.g., datetime20.) the value by using a second argument to %sysfunc() as below?
%let begTrans =
%sysfunc(
intnx(
dtyear, /* unit of time interval */
%sysfunc(datetime()), /* function to get current datetime */
-1 , /* number of intervals, negative goes to the past */
beginning /* alignment of interval date. "Same" is for same day of month/same time , "beginning" as start, end as ending*/
)
,datetime20.
);
%put &=begTrans;
This gives the following in the log:
BEGTRANS=01JAN2021:00:00:00
Kind regards,
Amir.
I'm not sure I see anything working incorrectly here.
%let begTrans =
%sysfunc(
intnx(dtyear,%sysfunc(datetime()),-1,beginning)
);
%put &=begTrans %sysfunc(putn(&begtrans,datetime16.));
Results in:
BEGTRANS=1925078400 01JAN21:00:00:00
which is correct.
Next year, when the date is 08FEB2023, I get
%let nextyear=%sysevalf('08FEB2023:00:00:00'dt);
%let begTrans =
%sysfunc(
intnx(dtyear,&nextyear,-1,beginning)
);
%put &=begTrans %sysfunc(putn(&begtrans,datetime16.));
the result is
BEGTRANS=1956614400 01JAN22:00:00:00
which is also correct.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.