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.
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.
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.