zoukankan      html  css  js  c++  java
  • SAS--do loop until while

      

        data work.earning;       /*loop只发生在data步*/
            value=2000;
            do year=1 to 20;
            interest=value*0.075;
            value+interest;                       /*year=21*/
            end;
        run;
        proc print data=earning;
        run;
    
        /*升级版*/
        data work.earning(drop=counter);
            value=2000;
            do counter=1 to 20;
            interest=value*0.075;
            value+interest;
            year+1;                               /*year=20*/
            end;
        run;
        proc print data=earning;
        run;
    
    
    data work.earning;
            value=2000;
            do year=1 to 20;
            interest=value*0.075;
            value+interest;
            output;   /*显示每一次执行的结果*/     /*year=1-20*/
            end;
        run;
        proc print data=earning;
        run;
    
    
        /*nesting 嵌套*/
    
        data earning;
            rate=0.0625/4;
            do year= 1 to 20;
                amount+2000;
                do quarter=1 to 4;
                    amount+amount*rate;
                    end;
            end;
        run;
        proc print data=earning;
        run;    
    
    
        data work.totals(drop=i balance /*记得drop i*/
         interest);
       set sasuser.loans;
       TotalInterest=0;              /*可有可无*/
       do i= 1 to months;    /*用变量来做循环时,循环里用到的变量一直使用当前值*/
          Interest=amount*(rate/12);
          amount+interest-payment;
          totalinterest+interest;
       end;
    run;
    proc print data=totals;
    run;
    
    /*每年投2000,年利率0.1,总额达到5万停手*/
      data work.invest;
            do until(Capital>=50000);  /*until至少执行一次*/
               capital+2000;
               capital+capital*.10;
               Year+1;
               output;
            end;
         run;
    
         data retire;
             saving=8000;
            income=42000;
            do until(saving>1000000);
                income+income*0.04;
                saving+income*0.1;
                year+1;
            end;
        run;
    
         data retire;
             saving=8000;
            income=42000;
            do while(saving<1000000);
                income+income*0.04;
                saving+income*0.1;
                year+1;
            end;
        run;
    
          data work.invest(drop=i);
            do i=1 to 30 until(Capital>=50000); /*两个循环条件,形成类似 |或门|   */
               Year+1;
               capital+2000;
               capital+capital*.10;
            end;
         run;
    
              data work.subset;
            do sample=10 to 5000 by 10;
               set factory.widgets point=sample;
               output;
            end;
            stop;
         run;
    Valar morghulis
  • 相关阅读:
    测试心得---杂七杂八
    Redis 集群缓存测试要点--关于 线上 token 失效 BUG 的总结
    linux基础
    如何获取新系统的业务逻辑?
    python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon)
    python笔记8-多线程threading之封装式
    redis监控key失效
    使用PageHepler分页
    使用token和redis怎样判断账户是否失效和异地登录
    JSONObject
  • 原文地址:https://www.cnblogs.com/super-yb/p/11833402.html
Copyright © 2011-2022 走看看