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

Hi,

 

I have a dataset with 288 variables whose name is col2 to col289. I want to replace all values with zeros and the code I used is as below.

data want;
  set have;
  array n{*} Col2-Col289;
  do i=1 to dim(n);        
    if n{i}=1 then n{i}=0;
  end;
run;

After I used this program, all values are replaced with zeros but there is one more variable called i. All the values in this column are 288. Can anyone tell me why this variable exists and how can I avoid it? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Your code is fine. is your index variable in the do loop. You can safely drop it like this

 

data want(drop=i);
  set have;
  array n{*} Col2-Col289;
  do i=1 to dim(n);        
    if n{i}=1 then n{i}=0;
  end;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Your code is fine. is your index variable in the do loop. You can safely drop it like this

 

data want(drop=i);
  set have;
  array n{*} Col2-Col289;
  do i=1 to dim(n);        
    if n{i}=1 then n{i}=0;
  end;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 3 replies
  • 772 views
  • 1 like
  • 2 in conversation