【问题标题】:SAS Data organizationSAS 数据组织
【发布时间】:2017-01-17 11:02:41
【问题描述】:

Dataset Sample

我有像附图一样的数据集,我只想要每年都有相同 numsecur 的观察结果。

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

【问题讨论】:

  • 抱歉 - 我没有看到图片...你能不能使用代码块来代替?
  • 所以对于您的示例,您只需要 1998 年和 1999 年?
  • 是的,在这个例子中,我想要 1996,1998,1999 年 ID 为 001598 的观察结果
  • 点击标题会看到表格
  • 您能否提供一个具体示例,说明您希望最终数据集是什么样的?很难理解你在问什么。

标签: statistics sas stata analysis


【解决方案1】:

假设我正确理解了您的问题,您希望仅在公司每年都有相同的 numsecur 时才保留来自同一公司/个人的观察结果。所以,这是我尝试使用 STATA 的方法:

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 下降 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

【讨论】:

  • 我很乐意提供帮助!
【解决方案2】:

您看起来像 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;

您是在问:显示使用相同 SUM 的所有行还是其他?

【讨论】:

  • 感谢您的回答,我的问题应该更清楚。我其实想要你说的。至于我的尝试,我创建了一个滞后变量,然后在滞后和 numsecur 之间创建了一个差异变量;然后我删除了非零的观察值。
  • 如果我的答案对您有用,请单击复选标记以接受答案并单击向上的三角形。
猜你喜欢
  • 2013-12-14
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 2018-03-16
  • 2012-07-17
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多