Hello SAS users, I need help to modify the below macro. For the cbalance, it has to be &name - 1 (for example if &name is January and &datayear is 2012 then it has to say cbalance_December_2011). I am struggling to modify this. The code needs to be flexible to account for the year movement from December to January. Below is my code. Could someone help take a look? Many thanks!! %macro bal; %let edate = %sysfunc(inputn(&ending_year&ending_month,yymmn6.),date.); %let datayear=&beginning_year; data dataset.new; set dataset.new; %do j=0 %to 3; %let sdate = %sysfunc(inputn(&datayear&beginning_month,yymmn6.)); %do i=0 %to 11; %do h=-1 %to 10; %put sdate=&sdate; %let nextsdate=%sysfunc(intnx(month,&sdate,&i),date.); %let lastday=%sysfunc(day(%sysfunc(intnx(month,&sdate,&i,end)))); %let datamonth=%sysfunc(month(%sysfunc(inputn(&nextsdate,date.)))); %let datayear=%sysfunc(year(%sysfunc(inputn(&nextsdate,date.)))); %let name=%sysfunc(intnx(month,&sdate,&i),monname.); %let prevdate=%sysfunc(intnx(month,&sdate,&h),date.); %let prevmonth=%sysfunc(putn(%sysfunc(intnx(month,&sdate,&h),monname.))); %let prevyear=%sysfunc(year(%sysfunc(inputn(&prevdate,date.)))); %if &nextsdate=&edate %then %do; %let i=11; %let j=3; %let h=10; %end; Rt1_&name.&datayear = (balance1_&name.&datayear / cbalance_&prevmonth.&prevyear)*100; Rt2_&name.&datayear = (balance2_&name.&datayear / cbalance_&prevmonth.&prevyear)*100; %end; %end; %end; run; %mend; %bal
... View more