BookmarkSubscribeRSS Feed
Kiteulf
Quartz | Level 8
%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

2 REPLIES 2
Amir
PROC Star

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1097 views
  • 2 likes
  • 3 in conversation