码迷,mamicode.com
首页 > 其他好文 > 详细

SAS--array

时间:2019-11-12 00:37:59      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:相同   class   ESS   color   hrd   The   orange   变量   monthly   

  

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;

 

SAS--array

标签:相同   class   ESS   color   hrd   The   orange   变量   monthly   

原文地址:https://www.cnblogs.com/super-yb/p/11839196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!