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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1307 views
  • 1 like
  • 2 in conversation