zoukankan      html  css  js  c++  java
  • SAS--array

      

    array sales{4} q1-q4;
    array sales{2:6} q2-q6;
    array sales{*} _numeric_;
    array sales{*} _character_;
    array sales{*} _all_;
    array fruit{*} apples pears grapes bananas oranges;
    /*array只存在data步,array名不能与已有变量名相同*/
    /*将已有变量定义到一个array*/
    data sasuser.added;
        set sasuser.funddrive;
        array contrib{4} qtr1-qtr4;   
        do i= 1 to dim(contrib);
            contrib{i}=contrib{i}+contrib{i}*.25;
        end;
    run;
    
    /*根据array创建变量*/
    
    array array-name{dim};  /*assume dim=3 then create array-name1 array-name2 array-name3*/
    array test{5} $ 20;       /*创建长度为20的5个character型变量*/
    
    
    
    /*二维的array,往往使用nesting loop*/
    
    data sasuser.summary(drop=i j total);
       set sasuser.survey;
       array section{3} eating exercise stress;
       array resp{3,6} item1-item18;
       do i=1 to 3;
          Total=0;
          do j=1 to 6;
             total+(resp{i,j});
          end;
          section{i}=total/6;
       end;
    run;
    
    
    /*旋转表格*/
    data sasuser.summary2(drop=item1-item18);
       set sasuser.survey;
       array amount{18} item1-item18;
           do item = 1 to 18;
        a= amount(item);
        output;
        end;
    run;
           
    
         data work.report(drop=i);
            set master.temps;
            array wkday{7} mon tue wed thr fri sat sun;
            do i=1 to 7;
               wkday{i}=5*(wkday{i}-32)/9;
            end;
         run;
    
         data hrd.convert(drop=i);
            set hrd.fitclass;
            array wt{6} weight1-weight6;
            do i=1 to dim(wt);
               wt{i}=wt{i}*2.2046;
            end;
         run;
    
         data hrd.diff(drop=i);
            set hrd.convert;
            array wt{6} weight1-weight6;
            array WgtDiff{5};
            do i=1 to 5;
               wgtdiff{i}=wt{i+1}-wt{i};
            end;
         run;
    
         data finance.report(drop=i);
            set finance.qsales;
            array sale{4} sales1-sales4;
            array goal{4} _temporary_ (9000 9300 9600 9900);  /*创建临时变量,不用drop*/
            array Achieved{4};
            do i=1 to 4;
               achieved{i}=100*sale{i}/goal{i};
            end;
         run;
    
         data finance.quarters(drop=i j);
            set finance.monthly;
            array m{4,3} month1-month12;
            array Qtr{4};
            do i=1 to 4;
              qtr{i}=0;
               do j=1 to 3;
                  qtr{i}+m{i,j};
               end;
            end;
         run;
    Valar morghulis
  • 相关阅读:
    python之简单爬虫
    python之正则表达式
    python之面向对象
    python之模块与包
    python之循环嵌套与算法
    linux shell实现从函数返回数组
    linux脚本实现数组值相加
    linux中使用函数输出
    linux shelll中显示的意义
    lsof命令
  • 原文地址:https://www.cnblogs.com/super-yb/p/11839196.html
Copyright © 2011-2022 走看看