Don't call functions to recalculate on every observations values that are constants.
Don't call functions you don't need.
So you would change something like this:
%do i=3 %to 12 %by 3;
if datepart(date)>=intnx('month', "&x_date"d,%eval(-&i+1), 'B')
and datepart(data_danych)<=intnx('month', "&x_date"d,0,'E') then do;
to:
%do i=3 %to 12 %by 3;
%let lower=%sysfunc(intnx(dtmonth,"&x_date:00:00"dt,-&i+1,b));
%let upper=%sysfunc(intnx(dtmonth,"&x_date:00:00"dt,0,e));
if date >= &lower and date_danych <= &upper then do;
So calculate the constants that are based on macro variables since they are know before the data step is even compiled.
Also calculate the constants as datetime values instead of date values so that you no longer need to call the DATEPART() function multiple times on each observation.
... View more