Data description: Dataset called pop has the char variable ID, and the numeric date variable DT_INDEX. It also has 12 numeric date variables called pre_date01 to pre_date12, which correspond to the date 1,2,...12 months prior to DT_INDEX. What I am trying to do: Use a macro to loop through the pre_date variables 01 to 12. For every pre_date variable, I want to set a macro variable (called &mo) to the month value associated with the pre_date variables. So for example, if pre_date01 is 20180620, then I want &mo to be 06 for that iteration of the loop. The line giving me trouble: %let mo = %sysfunc(month(pre_date&mo_before)); The error message: ERROR: Argument 1 to function MONTH referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number. The chunk of relevant code is below and I have bolded the problem line. %macro test; data pop; set pop; %do i = 01 %to 12; /* &mo_before is the amount of months before DT_INDEX */ %let mo_before = %sysfunc(putn(&i, z2.)); /* &mo is the actual month associated with the date 1,2,3,...12 months before DT_INDEX */ %let mo = %sysfunc(month(pre_date&mo_before)); /* Rest of the code removed from sas support forum post */ %end; run; %mend; %test;
... View more