1) Pay attention, MDY function creates a numeric sas date variable containing
the number of days past since January 1st, 1960 up to given date.
You can shorten 1st step to:
data _null_; datex = input("07102016",ddmmyy10.) ;
/* or datex = '07OCT2016'd; */ call symputx("from_date",strip(datex),'G'); run;
2) As from_date is a number you can make your code more simple:
instead:
%macro ren_vars;
data _null_;
length NRx $10000 renx $25 datex $10;
datex = compress("&from_date");
from_date = input(datex,10.);
you better use:
%macro ren_vars;
data _null_;
length NRx $10000 renx $25 datex $10;
from_date = &from_date;
3) As to splitting 7 days when changing month:
instead
do vnum=24 to 151;
datex = put(from_date,mmddyy10.);
renx = cat("Var",vnum,' = ',"NRx_",datex);
renx=tranwrd(renx,"/","_");
NRx = trim(NRx) ||' '|| renx;
if day(from_date) > 7 then from_date = from_date - 7;
else from_date = intnx('month',from_date,-1,'e');
end;
you need:
do vnum=24 to 151;
datex = put(from_date,mmddyy10.);
renx = cat("Var",vnum,' = ',"NRx_",datex);
renx=tranwrd(renx,"/","_");
NRx = trim(NRx) ||' '|| renx;
if day(from_date) > 7 then from_date = from_date - 7;
else do;
diff = day(from_date);
from_date = intnx('month',from_date,-1,'e');
datex = put(from_date,mmddyy10.);
renx = cat("Var",vnum,' = ',"NRx_",datex);
renx=tranwrd(renx,"/","_");
NRx = trim(NRx) ||' '|| renx;
if vnum = 151 then leave;
vnum = vnum +1;
from_date = from_date - 7 + diff;
end;
end;
DROP diff;
... View more