2017-12-22 29 views
-3

아무도 내가 루프를 잘못 이해하는 데 도움이 될 수 있습니까? 2,3,4 및 5로 outm을 생성하려고합니다. 처리 할 do 루프를 만들어야하지만 실패했습니다.어떤 몸이라도이 루프를 도와 줄 수 있습니까?

data Dmatrix5; 
input x1 x2 x3 x4 x5; 
cards; 
0 . . . . 
2 0 . . . 
15 0 . . 
4 3 5 0 . 
5 8 7 6 0 
; 
run;%macro loop 
%Do outm=5%to2; 
%let inm=5; 
%let outm=%eval(&inm-1); 
data Dmatrix&outm; 
retain minv small large; 
array cor{&inm,&inm} _temporary_; 
do i=1 to &inm; 
    set Dmatrix&inm; 
    array a[&inm] x1--x&inm; 
    array op[&outm]; 
    do j=1 to &inm; 
    cor[i,j]=a[j]; 
    end; 
end;` 

do i=1 to &inm; 
    if i>1 then do; 
     do j=1 to i-1; 
      m=cor{i,j}; 
      if i=2 & j=1 then do; 
       minv=m; 
       small=i; 
       large=j; 
       delrc=j; 
      end; 
      else do; 
       if minv > m then do; 
        minv=m; 
        delrc=i; 
        if i>j then do; 
         small=j; 
         large=i; 
        end; 
       else do; 
         small=i; 
         large=j; 
        end; 
       end;  
      end; 
     end; 
    end; 
end; 

array out{&inm}; 
do i=1 to &inm; 
    do j=1 to i; 
     if large=i and small=j then out[j]=99999; 
     else if large=j and small=i then out[j]=99999; 
     else if j=i then out[j]=0; 
     else do; 
      if small=i then do; 
       if small>j and large >j then do; 
        if cor[small,j]<cor[large,j] then out[j]=cor[small,j]; 
        else out[j]=cor[large,j]; 
       end; 
       else if small>j and large<j then do; 
        if cor[small,j]<cor[j,large] then out[j]=cor[small,j]; 
        else out[j]=cor[j,large]; 
       end;  
      end; 
      else if small=j then do; 
       if small<i and large<i then do; 
        if cor[i,small]<=cor[i,large] then out[j]=cor[i,small]; 
        else out[j]=cor[i,large]; 
       end; 
       else if small<i and large>i then do; 
        if cor[i,small]<=cor[large,i] then out[j]=cor[i,small]; 
        else out[j]=cor[large,i]; 
       end; 
      end; 
      else if large=j or large =i then 
       out[j]=99999; 
      else out[j]=cor[i,j];    
     end; 
    end; 
    n=1; 
    do k=1 to &inm; 
     if k^=delrc then do; 
      op[n]=out[k]; 
      n=n+1; 
     end; 
    end; 
    if delrc^=i then output; 
    end; 
    keep op1-op&outm; 
run; 

data Dmatrix&outm; 
set Dmatrix&outm; 
x1=op1; 
x2=op2; 
keep x1-x2; 
run; 

%end; 
%Mend loop; 

%loop; 
+1

"다음은이 질문 게시 요구 사항을 충족하는 것입니다."나는 횡설수설 게시 요구 사항에 대해 몰랐으며 일반적으로 다른 질문에는 표시되지 않습니다. – jps

+0

@jps 새로운 사용자의 경우 일정량의 비 코드가 필요합니다. 좋은 이유로. 횡설수설을 추가하는 것은 당연히 그것을 고쳐주지 않습니다. -1 . – Joe

+0

@Joe는 OP에 대해 더 자세한 정보를 제공해야합니다. "문제를 처리하기 위해 do 루프를 만들어야하지만 실패했습니다."는 문제에 대한 설명이 아닙니다. – jps

답변

0
%Do outm=5%to2; 

는 반복하지 않습니다. documentation을 1로 내려가려면 %BY -1을 사용해야합니다.

%macro example1; 
    %local index; 
    %do index = 5 %to 2 %by -1; 
    %put &=index; 
    %end; 
%mend; 

%example1 

또는 내림차순 색인을 직접 계산할 수 있습니다.

%macro example2; 
    %local iteration index; 
    %do iteration = 1 %to 4; 
    %let index = %eval(6-&iteration); 
    %put &=index; 
    %end; 
%mend; 

%example2