代码之家  ›  专栏  ›  技术社区  ›  Kaushik Saha

SAS数据组织

  •  -5
  • Kaushik Saha  · 技术社区  · 8 年前

    Dataset Sample

    我有一组数据,就像附件中的图片,我只需要每年都有相同数字的观测值。

    如何在SAS proc sql函数中执行此操作?在STATA中这样做会更容易吗?如果是,我可以使用什么程序?

    2 回复  |  直到 8 年前
        1
  •  1
  •   DCR    8 年前

    您看起来像是stackoverflow的新用户。欢迎你的问题被否决至少有三个原因:

    1) It's not really clear what you want from your description of the problem and the data
       you're providing
    
    2) You haven't shown any attempts at what you've tried
    
    3) Providing your data as a picture is not great.  It's most helpful if you're going
       to provide data to provide it so it's easy for others to consume in their program.  
       After all, you're asking for our help make it easier for us to help you.  If You 
       included something like the following we just have to copy and paste to create your
       dataset to work with:
    
        DATA test;    
        INPUT ID YEAR EXEC SUM;
           DATALINES;
        1573 1997 50 1080
        1581 1997 51  300
        1598 1996 54   80
        1598 1998 54   80
        1598 1999 54   80
        1602 1996 55  112.6
        1602 1997 55  335.965
           ;
        RUN;
    

    下面的话可能会告诉你你想要什么,但这只是猜测,因为我不确定这是否真的是你想要的:

    proc sql no print;
         create table testout as
                select *,count(*) as cnt
          from test
                group by sum
                      having cnt > 1;
    quit;
    

        2
  •  0
  •   CYT    8 年前

    input ID YEAR EXEC SUM
        1573 1997 50 1080 //
        1581 1997 51  300 //
        1598 1996 54   80 //
        1598 1998 54   80 //
        1598 1999 54   80 //
        1602 1996 55  112.6 //
        1602 1997 55  335.965 //
        1575 1997 50 1080 //
        1575 1998 51 1080 //
        1595 1996 54   80 //
        1595 1998 54   30 //
        1595 1999 54   80 //
        1605 1996 55  112.6 //
        1605 1997 55  335.965 //
    end
    
    bysort ID SUM: gen drop=cond(_N==1, 0,_n)
    drop if drop==0
    

    结果显示(根据我的数据):

       
        ID      YEAR   EXEC  SUM    drop    
    
    1.  1575    1997    50  1080    1   
    2.  1575    1998    51  1080    2   
    3.  1595    1999    54  80      1   
    4.  1595    1996    54  80      2   
    5.  1598    1996    54  80      1   
    
    6.  1598    1998    54  80      2   
    7.  1598    1999    54  80      3