create table HH_Assets_&j as
select nnn, cddd, sum(aaaa) as value_&j,sum(bbb) as qty_&j,
from XYZ.part&j inner join Elig_secs on
and aaa > 0 and cdd='A'
group by nnn,cdd,
order by nnn,cdd;
proc sort data = HH_Assets_&j; by nnn cdd; quit;
you will see that the start and stop values for %DO must resolve to be:
"...specify integers or macro expressions that generate integers to control the number of times the portion of the macro between the iterative %DO and %END statements is processed."
Therefore, the string 0905 as an INTEGER number is 905.
You can prove this to yourself by turning on the macro debugging options:
options symbolgen mprint mlogic;
I'm betting you will see that &START and &STOP still have the leading 0, but that &J (since it must resolve to an integer number) will be either 905 or 906.
That means you will have to control how &J gets used in building your filenames and variable names. Probably you will need to create another macro variable one that you would use just in the names.
For what it is worth:
This brings up a second reason this code bugs me. Is "0905" May 2009 or September 5? If the latter what happens to the code on Sept 30? Stepping through a string as if it is an integer just seems full of potential problems to me.
Just a tad curious what you will do when crossing a year boundary, where one string is not in the same year as the other?
Suggest you still take in the two macro variables but drive the %DO / %END process using SAS DATE values represented as macro variables, and then truncate the output format of your low "yymm" and high "yymm" data strings as needed.
This would mean using %SYSFUNC and PUTN / INPUTN to convert the yymm to yymm01, using INPUTN and then use PUTN, if needed, to generate a truncated DATE variable string. You will need to consider using the INTNX function for your processing, possibly.