任何身体可以帮助我做这个循环吗?

时间:2017-12-22 08:47:16

标签: sas

任何人都可以帮我看看这个循环中有什么问题?我想用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 个答案:

答案 0 :(得分:0)

from bs4 import BeautifulSoup
import requests

link = "http://www.cnnvd.org.cn/web/vulnerability/querylist.tag"

req = requests.get(link)
web = req.text
soup = BeautifulSoup(web, "lxml")

cve_name = []
cve_link = []


for par_ in soup.find(class_='list_list').find_all('div', attrs={'class':'fl'}):
    print(len(par_))
    for link_ in par_.find_all('p'):
        for text_ in link_.find_all('a'):
            print (text_.string)
            print (text_['href'])
            print ("==========")
            #cve_name.append(text_.string)
            #cve_link.append(text_['href'])

永远不会迭代。您需要使用%Do outm=5%to2; 下降1.大量documentation

%BY -1

或者您可以自己计算降序索引。

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

%example1