Hi:
Scott asks a good question. You show this:
[pre]
%MACRO _macro12;
%LOCAL numerator;
DATA data_03;
SET data_02;
DROP _name_ _label_;
%DO numerator = 1 %TO &_numerator.;
price_br&numerator. = _&numerator.;
[/pre]
Your %LOCAL refers to NUMERATOR as a local macro variable (without any underscores in the name.) This means that the correct reference is &NUMERATOR. And yet, in your code, you show 2 completely different macro variable references: &_NUMERATOR and _&NUMERATOR -- neither of which will be the same as &NUMERATOR. So right off the bat, you have a problem...you have 3 possible macro variables, one of them local and in your code you have this:
%DO numerator = 1 %TO &_numerator.; which seems to me should be:
%DO numerator = 1 %TO &_number.; or
%DO numerator = 1 %TO 33;
And THEN your %LET statement refers to _NUMBER -- a 4th possible macro variable, whose limit is set to 33. And it seems to me that you really want the DO loop to go from 1 to 33, (which is &_NUMBER) and not from 1 to &_NUMERATOR or _&NUMERATOR???? Is that correct???
I understand that you don't like the _2, _3, _4, etc naming convention that you get from PROC TRANSPOSE -- however, that can EASILY be solved by using the PROC TRANSPOSE PREFIX= option which will put the same prefix in front of each TRANSPOSED variable. So, instead of getting _2, _3, etc, you could have PREFIX=PB or PREFIX=PRICE_BR and you would get PB1, PB2, PB3, PB4 or PRICE_BR1, PRICE_BR2, PRICE_BR3, PRICE_BR4 as the names of your variables after the transpose.
As for the issue of how to turn the missing values (.) for transposed prices into 0 that is a fairly simple task for a simple DATA step ARRAY with a simple DO loop - no macro coding required.
I'm not convinced that you really need a SAS Macro solution here. I don't see anything that you could not also accomplish and accomplish easier with a simple DATA step DO loop.
This paper gives a good introduction to simple ARRAY processing with SAS (without using SAS macros)
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf
cynthia
ps...consider either of these PROC TRANSPOSE steps as an alternative to what you are currently using the code below...note that they create DATA_02A and DATA_02B, so you can compare the 2 output datasets created:
[pre]
PROC TRANSPOSE DATA = data_01 OUT = data_02A(drop=_NAME_)
prefix=pb;
BY id week;
ID brand;
VAR price_brand;
RUN;
PROC TRANSPOSE DATA = data_01 OUT = data_02B(drop=_NAME_)
prefix=price_br;
BY id week;
ID brand;
VAR price_brand;
RUN;
[/pre]