Hi:
As Scott recommended, you need to read up on how ARRAYs work in SAS and about ARRAY referencing. And, perhaps understand a bit more about how the Macro facility works. This is a good introduction on using ARRAYs:
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf
And this is a good introdution to the SAS Macro facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
You are not actually getting an error message on a MACRO variable, you are getting a NOTE on an unitialized DATA step variable. The message you listed:
[pre]
note: Variable expos0 is uninitialized
note: Variable expos1 is uninitialized
note: Variable expos2 is uninitialized
[/pre]
is put into the log because the macro variable references in your macro program resolved to the wrong DATA step variables.
Remember that the invocation of %SUMCOV is ONLY, ONLY, ONLY going to generate one single assignment statement for TEXPOS -- the macro program is not doing anything else except building this ONE statement every time you invoke the %SUMCOV macro program. Then, that statement, in the context of a DATA step program will be sent to the SAS compiler and then the statement (without ANY macro references) will go forward to be executed.
So, think about the code you want to generate -- did you start with working code? The macro facility is going to generate ONE single statement for you:
TEXPOS=sum(of resolved reference1 - resolved reference2 );
This is the array statement you showed:
[pre]
array expos(0:32) x0 - x32;
[/pre]
Which one of these statements (with resolved references) do you want/need to generate for THIS single invocation of %SUMCOV:
%sumcov(n1=0,n2=2);
[pre]
texpos=sum(of expos0- expos2);
OR
texpos=sum(of x0-x2);
[/pre]
Since your ARRAY is referencing variables X0-X32 -- there ARE not any EXPOS0-EXPOSn variables in your dataset to be used with the SUM function -- which is the cause of the "Variable xxx is not initialized" note. So, you need to explain a bit more about the processing you hope to accomplish with your macro program. If possible, post ALL of the code and explain what you need to do with your SUM statement. And also explain whether you need to generate multiple values for TEXPOS or whether you just need to generate 1 value for TEXPOS.
If you are referencing a variable as an ARRAY member, such as the one shown above in a DO loop, then you might have code like this to reference your variables in an array -- such as when you want to create a total from all the array members:
[pre]
array expos(0:32) x0 - x32;
do i = 0 to 32;
total = sum(total , expos(i));
end;
[/pre]
Note the use of the ARRAY reference to
expos(i) where I is the index for the array name EXPOS. So, when i = 0, then EXPOS(I) is actually referencing the variable X0. Remember that SAS ARRAYs are not physical data constructs -- they provide a simple way to reference multiple variables as though they were members of an array. This means that the variables do NOT necessarily need to be numbered variables. These are all valid ways to declare ARRAYs for referencing:
[pre]
array tvshow $ tv1 tv2 tv3 tv4;
array henson $ sesame fraggle muppet otter;
array allnum _numeric_;
array allchar $ _character_;
array slprf sales discount commission profit;
array numvar var1 var5 var15 var20;
array nv var:;
array other var1-var20;
[/pre]
You also questioned the correct placement for the ARRAY statement itself -- whether it should go into the macro program or into the DATA step. Given what we know so far, the ARRAY statement should not be placed INSIDE of the %MACRO/%MEND definition. That's because your ARRAY statement -- a DATA step statement -- is a compile time statement and only needs to be put into the DATA step program 1 time.
Consider the following program. It uses SASHELP.CLASS and declares 2 arrays -- one for all the character variables (NAME and SEX) and another for all the numeric variables (AGE, HEIGHT and WEIGHT). The only purpose of the program is to show that the array reference is really only pointing to variable in the Program Data Vector. It also illustrates 2 different ways to use the SUM function -- one using array references (to calculate the TOT variable and the other way uses the variable names. So when I=3, ALLNUM(I) is pointing to the variable WEIGHT and when I=2, ALLNUM(I) is pointing to the variable HEIGHT, etc.
cynthia
[pre]
5710 data makearr;
5711 set sashelp.class(obs=2);
5712 array allnum _numeric_;
5713 array allchar $ _character_;
5714 putlog '***** ***** ***** ' _n_= name= sex= age= height= weight=;
5715 putlog '*** entering DO loop for ALLCHAR Array ***';
5716 do i = 1 to dim(allchar);
5717 putlog i= allchar(i)=;
5718 end;
5719 putlog '*** entering DO loop for ALLNUM Array ***';
5720 do i = 1 to dim(allnum);
5721 tot = sum(tot,allnum(i));
5722 putlog i= allnum(i)= tot=;
5723 end;
5724 tot2 = sum (age, height, weight);
5725 tot3 = sum (of allnum(*));
5726 putlog '*** outside DO loop for ALLNUM ' tot2= tot3=;
5727 putlog ' ';
5728 run;
***** ***** ***** _N_=1 Name=Alfred Sex=M Age=14 Height=69 Weight=112.5
*** entering DO loop for ALLCHAR Array ***
i=1 Name=Alfred
i=2 Sex=M
*** entering DO loop for ALLNUM Array ***
i=1 Age=14 tot=14
i=2 Height=69 tot=83
i=3 Weight=112.5 tot=195.5
*** outside DO loop for ALLNUM tot2=195.5 tot3=195.5
***** ***** ***** _N_=2 Name=Alice Sex=F Age=13 Height=56.5 Weight=84
*** entering DO loop for ALLCHAR Array ***
i=1 Name=Alice
i=2 Sex=F
*** entering DO loop for ALLNUM Array ***
i=1 Age=13 tot=13
i=2 Height=56.5 tot=69.5
i=3 Weight=84 tot=153.5
*** outside DO loop for ALLNUM tot2=153.5 tot3=153.5
NOTE: There were 2 observations read from the data set SASHELP.CLASS.
[/pre]