title: Recoding multi dimensional array variables in SAS
body: <p>I'm trying to recode a SAS array variable based on other variables condition. I am getting array subscript out of range error </p>
  
  <pre><code>      datasets Chk1 and Chk2 have the following data
  
        Chk1
         id Var1 Var2
         1   Y    N
         2   N    Y
         3   Y    Y
        Chk2
        id Var3 Var4
         1   N    Y
         2   Y    N
         3   Y    Y
  
        My desired output is
        Chk3
        id  Var1 Var2 Var3 Var4 a1 a2 a3 b1 b2 b3
         1    Y   N    N    Y    1           1 
         2    N   Y    Y    N       1     1
         3    Y   Y    Y    Y          1        1
  
  
        Here is the data merge with recoding variables
  </code></pre>
  
  <p>I need your help in tweaking do loop with incremental value. </p>
  
  <pre><code>      data Chk3;
         merge Chk1(in=a) Chk2(in=b);
         by id;
         if a and b;
         array wv(*) var1 var2;
         array wv2(*) var3 var4;
         array wv3(*) a1 a2 a3 b1 b2 b3;
         do i=1 to dim(wv3) by 3;
          if wv(i)='Y' and wv2(i)='N' then wv3(i)=1;
          if wv(i)='N' and wv2(i)='Y' then wv3(i+1)=1;
          if wv(i)=wv2(i) then wv3(i+2)=1;
         end;
         run;
  </code></pre>