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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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