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;