Here is the code I am trying to automate: Proc sql; create table Common_Policy as select *, case when POL_YYYY = 2005 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP05a, case when POL_YYYY = 2006 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP06a, case when POL_YYYY = 2007 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP07a, case when POL_YYYY = 2008 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP08a, case when POL_YYYY = 2009 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP09a, case when POL_YYYY = 2010 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP10a, case when POL_YYYY = 2011 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP11a, case when POL_YYYY = 2012 Then SUM_of_DIR_WP_AMNT Else 0 End as DWP12a, case when POL_YYYY = 2005 Then SUM_of_WRIT_EXPOS_AMNT Else 0 End as EXP05a, case when POL_YYYY = 2006 Then SUM_of_WRIT_EXPOS_AMNT Else 0 End as EXP06a, case when POL_YYYY = 2007 Then SUM_OF_WRIT_EXPOS_AMNT Else 0 End as EXP07a, case when POL_YYYY = 2008 Then SUM_OF_WRIT_EXPOS_AMNT Else 0 End as EXP08a, case when POL_YYYY = 2009 Then SUM_OF_WRIT_EXPOS_AMNT Else 0 End as EXP09a, case when POL_YYYY = 2010 Then SUM_OF_WRIT_EXPOS_AMNT Else 0 End as EXP10a, case when POL_YYYY = 2011 Then SUM_OF_WRIT_EXPOS_AMNT Else 0 End as EXP11a, case when POL_YYYY = 2012 Then SUM_OF_WRIT_EXPOS_AMNT Else 0 End as EXP12a from Drop_Zeros; quit; Here is what I have written: %macro CP(start_py=,end_py=,curr=); data Common_Policy; set Drop_Zeros; %let start = %eval(&start_py - 1); %let newC = %eval(&curr - 1); %do %while (&start <= &end_py); if POL_YYYY = &start then %let DWP&del0&newC&dela = SUM_of_DIR_WP_AMNT; else %let DWP&del0&newC&dela = 0; if POL_YYYY = &start then %let EXP&del0&newC&dela = SUM_OF_WRIT_EXPOS_AMNT; else %let EXP&del0&newC&dela = 0; start = %eval(&start + 1); newC = %eval(&newC + 1); %end; run; %mend CP; %CP (start_py=&start_policy_year, end_py=&end_policy_year, curr=¤t); Variables &end_policy_year, &start_policy_year , and ¤t are global variables which would be input by the user at the very top of the code. Here, they would be 2006, 2012, and 06, respectively. I keep running into errors with this code saying that the macro cannot be redefined. Any ideas on how I can complete this macro as is or a whole new way of doing it?
... View more