Hi Cynthia,
Thank you for your quick answer 🙂
I know that it might seem stupid tu replace the data set do loop by a %DO loop but I have to create variables names depending on the start and end dates used for the loop, and some other parameters.
%let nameMonth1 = JAN;
%let nameMonth2 = FEB;
... etc ...
%let nameMonth11=NOV;
%let nameMonth12=DEC;
%Macro GenConso;
data work.test;
set work.inputData;
%do varYear = 2008 %to 2011;
%if year(dtps) LE &varYear and year(dtps) GE &varYear &then &do;
%do varMonth = month(dtps) %to 12 ;
ConsoPeak&varYear + cn&varMonth;
ConsoPeak&&nameMonth&varMonth..&varYear = cn&varMonth;
ConsoOffPeak&&nameMonth&varMonth..&varYear = cl&varMonth;
%end;
%end;
%end;
output;
run;
%Mend GenConso;
in the input dataset, we have 12 variables cn (cn1, cn2, ... cn12), 12 variables cl (cl1, cl2, ... cl12), and dtps.
i.e. if the value of year(dtps) is 2010 and month(dtps) = 11, it will create the following variables:
ConsoPeak2010
ConsoPeakNOV2010
ConsoPeakDEC2010
ConsoOffPeakNOV2010
ConsoOffPeakDEC2008
ConsoPeak2011
ConsoPeakNOV2011
ConsoPeakDEC2011
ConsoOffPeakNOV2011
ConsoOffPeakDEC2011
The possibility to replace data set do loops by %DO loops makes the code really shorter and easier to update (as there is a lot of conditions and select; when ... in the complete program).
Sorry if my explanations are not clear enough.
Florent
... View more