DO LOOP Creates a new variable that is the index I am using

#1
Hi,

Sorry if this is a basic question but I have not been able to find a solution/answer.

I am using a do loop with an array to process some fields:

data new2;
set new2;
array Page_ {6} Page_1 - Page_6;
do i = 1 to 6;
page_ = page_ + 1;
end;

This has the effect of modifying already existing fields; Page1 - Page6 by reducing their values by 1, but also adds an additional field with the name 'i'.

Has anyone experienced this and is there an explanation/solution?

thank you for your response
 
#2
This is straightforward and known SAS behaviour. The code, as given, works correctly, assuming that dataset “new2” has (numerical) variables called “Page_1”, “Page_2”, “Page_3”, “Page_4”, “Page_5” and “Page_6”.

If you only want to get rid of the newly created variable “i” (which will show a value of 6 for each record), just add a “drop i;” command to your data step, as follows:
data new2;
drop i;
set new2;