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! 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1396 views
  • 1 like
  • 2 in conversation