代码之家  ›  专栏  ›  技术社区  ›  Rhea

将数组的值作为维度赋给SAS中的另一个数组

  •  0
  • Rhea  · 技术社区  · 6 年前

    我一直在编写一个复杂的代码,最后陷入了困境,我需要将一个数组的值作为维度参数赋给代码中的另一个数组。我的代码中的快照: 例如:

    array temp_match_fl(3) temp_match_fl1 - temp_match_fl3;     
        ARRAY buracc_repay(3) buracc_repay1 - buracc_repay3;
        ARRAY ocs_repay(3) ocs_repay1 - ocs_repay3;
        jj = 0;
        do until (jj>=3);
        jj=jj+1;
    
        If length(strip(match_flag(jj))) = 1 then do;
            temp_match_fl(jj) = match_flag(jj);
        end;
    
        Else If length(strip(match_flag(jj))) > 1 then do; 
            j1 = 0; 
            min_diff = 99999999;    
            do until (j1>=length(strip(match_class(jj))));
               j1=j1+1;
               retain min_diff;
                n=substr(strip(match_flag(jj)),j1,1);
                If (min_diff > abs(buracc_repay(jj)-ocs_repay(n))) then do;
                    min_diff = abs(buracc_repay(jj)-ocs_repay(n));
                    temp_match_fl(jj) = n;              
                end;
            end;
        end;
        kk=temp_match_fl(jj);
    /*  buracc_repay(jj) = ocs_repay(kk);*/
        buracc_repay(jj) = ocs_repay(temp_match_fl(jj));    
     end;
    run;
    

    现在,我需要能够将存储在temp\u match\u fl(jj)数组中的值作为维度参数赋给另一个数组,我如何实现这一点??最后两种说法都不管用:

    buracc\u return(jj)=ocs\u return(kk); buracc_return(jj)=ocs_return(temp_match_fl(jj)); 谢谢!

    1 回复  |  直到 6 年前
        1
  •  1
  •   Quentin    6 年前

    实际上,你写的最后两个陈述确实有用。您是否收到错误或意外结果?你能举一个简单的例子来说明这个问题吗?

    请注意,要使其工作,关键是 temp_match_fl(jj) 是1、2或3,因为OCS\u数组有三个元素。从您展示的代码来看,不清楚这是否总是正确的。不显示匹配标志数组。

    data want ;
      array temp_match_fl(3) temp_match_fl1 - temp_match_fl3 (1 2 3) ;     
      array buracc_repay(3) buracc_repay1 - buracc_repay3 (10 20 30) ;
      array ocs_repay(3) ocs_repay1 - ocs_repay3  (100 200 300) ;
    
      jj=1 ;
      kk=2 ;
    
      *buracc_repay(jj) = ocs_repay(kk);  *this works ;
    
      put temp_match_fl(jj)= ; *debug to confirm value is 1 2 or 3 ;
    
      buracc_repay(jj) = ocs_repay(temp_match_fl(jj)); *this also works;
    
      put (buracc_repay:)(=) temp_match_fl1=; *check output ;
    run ;