BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
d6k5d3
Pyrite | Level 9

I have the following code to run an array:

 

data HUF_Speech;
set HUF_Speech;

array  SP{66} SP1-SP66;
do i=1 to 66;
if SP{i}=. then SP{i}=0;
end;
run;

Initially there were 83 columns, but surprisingly, after running the code above, a column 'i' is added which has '67' as a value in all rows! How can this be possible?

 

Much thanks.

 

Regards.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

No magic here. Variable i is created as the control variable of the do loop. You can add the statement

 

drop i;

 

anywhere within the datastep to prevent variable i from being kept in the results.

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

No magic here. Variable i is created as the control variable of the do loop. You can add the statement

 

drop i;

 

anywhere within the datastep to prevent variable i from being kept in the results.

PG
d6k5d3
Pyrite | Level 9
Does this always happen with arrays?
PGStats
Opal | Level 21

It is not created by the array. It happens with all do loop control variables.

 

for example

 

data test;
do i = 1 to 4;
    output;
    end;
run;

creates a dataset with a single variable: i.

PG
d6k5d3
Pyrite | Level 9
Thank you! 🙂