zoukankan      html  css  js  c++  java
  • 【SAS Notes】If then statements

    【回顾内容】

    data mysas.ifthen;
    infile 'E:\ifthen.txt' dlm='09'x firstobs=2;
    input date gtone shen dong all;
    run;
    

    1.当数据来源于excel dlm的参数为'09'x in ASCII 09 is the hexadecimal equivalen of a tab character,and the notation '09'x means a hexadecimal 09

    2.firstboservation

    【if then do end】

    /*if then 练习 实现年度求和*/
    data mysas.ifthen1;
      infile 'e:\ifthen.txt' dlm='09'x firstobs=2;
      input date gtone shen dong all;
      sum=0;
      if date>=201001 and date<=201012 then 
        do sum=sum+all;
    	end;
     run;
     proc print data=mysas.ifthen1;
     run;
    

    print result

     Obs     date      gtone      shen       dong        all           sum

                 1    200901    498937    6742289    2494050     9735276           0
                 2    200902    478784    6765642    2406706     9651132           0
                 3    200903    479560    6827687    2391841     9699088           0
                 4    200904    477907    6743027    2297549     9518483           0
                 5    200905    486403    6907205    2261126     9654734           0
                 6    200906    486593    6803153    2182113     9471859           0
                 7    200907    492590    6901677    2117964     9512231           0
                 8    200908    495797    6965608    2084515     9545920           0
                 9    200909    495485    6873504    2033317     9402306           0
                10    200910    500339    7055739    1994235     9550313           0
                11    200911    492797    6857360    1942764     9292921           0
                12    200912    498678    6898360    1922876     9319914           0
                13    201001    500179    6918185    1868214     9286578     9286578
                14    201002    513237    7128654    1809876     9451767     9451767
                15    201003    504156    7521635    1892241     9918032     9918032
                16    201004    507437    7544403    1869134     9920974     9920974
                17    201005    511050    7765219    1854844    10131113    10131113
                18    201006    503222    7852088    1877326    10232636    10232636
                19    201007    507169    7999714    1924397    10431280    10431280
                20    201008    509278    8045505    1969896    10524679    10524679
                21    201009    515511    7928625    1986502    10430638    10430638
                22    201010    508082    7785980    2005948    10300010    10300010
                23    201011    506488    7529334    2003324    10039146    10039146
                24    201012    509890    7484314    2011298    10005502    10005502
                25    201101    513356    7434192    2001453     9949001           0
                26    201102    526176    7635112    2070135    10231423           0
                27    201103    524697    7690899    2202720    10418316           0

     【if then else if then】

    1、if then do end; "end" is fllow by "do". if there did not use "do" then "end" should be dissappered.

    /*if then else 简单筛选*/
    data mysas.ifthen2;
          infile 'e:\ifthen.txt' dlm='09'x firstobs=2;
    	  input date gtone shen dong all;
    	  if date>201001 then sum=1;
    	     else if date>200905 and date<=201001 then sum=2;
    		      else if date<200905 then sum=3;
    run;
    proc print data=mysas.ifthen2;
    run;
    

    【if delete】

    在data 中导入数据时if delete是一个很有意思的操作。

    /*if delete*/
    data mysas.ifthen3;
         infile 'e:\ifthen.txt' dlm='09'x firstobs=2;
    	 input date gtone shen dong all;
    	 if date>201005;
    run;
    proc print data=mysas.ifthen3;
    run;
    

    【对日期的处理】

    一般日期都为20120113这种形式,如何导入sas?

    yymmn6. union anydtdte9.

    /*对date的处理*/
    data mysas.ifthen4;
         infile 'e:\ifthen.txt' dlm='09'x firstobs=2;
         input date yymmn6. gtone shen dong all;
    run;
    proc print data=mysas.ifthen4;
         format date anydtdte9..
    run;
  • 相关阅读:
    前缀和
    不用加减乘除做加法
    数组中重复的数字
    滑动窗口的最大值
    矩阵中的路径
    Redis 和 Memcached 的区别 Tair
    机器人的运动范围
    汉诺塔问题
    洗牌算法
    斐波那契查找算法(黄金分割查找算法)
  • 原文地址:https://www.cnblogs.com/colipso/p/2874672.html
Copyright © 2011-2022 走看看