楼主: 锦sè♀
11287 7

SAS新手请教如何删除不符合条件的观测值 [推广有奖]

  • 2关注
  • 0粉丝

本科生

59%

还不是VIP/贵宾

-

威望
0
论坛币
1288 个
通用积分
0.5407
学术水平
1 点
热心指数
2 点
信用等级
1 点
经验
2767 点
帖子
73
精华
0
在线时间
71 小时
注册时间
2013-6-2
最后登录
2022-5-17

楼主
锦sè♀ 在职认证  学生认证  发表于 2014-10-14 23:26:44 |只看作者 |坛友微信交流群|倒序 |AI写论文
5论坛币
QQ截图20141014232547.jpg 数据集balancesheet大概是这样的。第一个问题是我需要将不同代码的股票按照2001-2011年10年间每年12月31日的数据拆分成十个子数据集,程序应该如何写啊?求大神指教。

第二问题是我需要删除在2001-2011年数据不完整的股票,具体程序又是如何的呢?SAS新手,还请路过大神指点一番,解决问题可以论坛币答谢~!

QQ截图20141014232547.jpg (74.26 KB)

QQ截图20141014232547.jpg

最佳答案

lwien007 查看完整内容

第一个问题 data t1-t11; set balancesheet; if period = '2001-12-31' then output t1; if period = '2002-12-31' then output t2; if period = '2003-12-31' then output t3; if period = '2004-12-31' then output t4; if period = '2005-12-31' then output t5; if period = '2006-12-31' then output t6; if period = '2007-12-31' then output t7; if period = '2008-12-31' then output t8; if period ...
关键词:观测值 Balances balance lance Balan 如何 程序
沙发
lwien007 发表于 2014-10-14 23:26:45 |只看作者 |坛友微信交流群
第一个问题
data t1-t11;
        set balancesheet;
        if period = '2001-12-31' then output t1;
        if period = '2002-12-31' then output t2;
        if period = '2003-12-31' then output t3;
        if period = '2004-12-31' then output t4;
        if period = '2005-12-31' then output t5;
        if period = '2006-12-31' then output t6;
        if period = '2007-12-31' then output t7;
        if period = '2008-12-31' then output t8;
        if period = '2009-12-31' then output t9;
        if period = '2010-12-31' then output t10;
        if period = '2011-12-31' then output t11;
run;

第二个问题,你的period应该是字符型,首先转换成日期型新变量date
data tmp;
        set balancesheet;
        date = input(period,yymmdd10.);
        format date yymmdd10.;
        if year(date)>2000 and year(date)<2011 then do;
                if missing(asset) or missing(cash) then delete;
        end;
run;
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
diyyam + 5 + 1 + 1 精彩帖子

总评分: 论坛币 + 5  学术水平 + 1  热心指数 + 1   查看全部评分

使用道具

藤椅
锦sè♀ 在职认证  学生认证  发表于 2014-10-16 15:37:21 |只看作者 |坛友微信交流群
lwien007 发表于 2014-10-15 10:31
第一个问题
data t1-t11;
        set balancesheet;
大神你好~!第二个问题是为了删除在2001-1-1至2011-12-31期间没有连续公布财务报表的公司,也就是说我应该去判断每个CODE变量是否都对应着有2001-2011年底的数据,若不全则删除所有该code对应的观测诶,应该如何写啊?接触sas时间不过一周,所以问题傻了点,还请大神赐教啊

使用道具

板凳
lwien007 发表于 2014-10-17 10:50:29 |只看作者 |坛友微信交流群
  1. proc sort data=balancesheet out=tmp2;
  2.         by code period;
  3. run;
  4. data tmp3;
  5.         retain i;
  6.         set tmp2;
  7.         by code period;
  8.         if first.code then do;
  9.                 i=0;
  10.         end;
  11.         if first.period then do;
  12.                 if period in('2001-12-31','2002-12-31','2003-12-31','2004-12-31','2005-12-31','2006-12-31','2007-12-31','2008-12-31','2009-12-31','2010-12-31','2011-12-31') then i=i+1;
  13.                 else i=i;
  14.         end;
  15. run;
  16. proc sort data=tmp3 out=tmp4;
  17.         by code descending i;
  18. run;
  19. data tmp5(drop=i j);
  20.         retain j;
  21.         set tmp4;
  22.         by code descending i;
  23.         if first.code then if i=11 then j=1;
  24.         else j=0;
  25.         if j=0 then delete;
  26. run;
  27.        
复制代码

使用道具

报纸
锦sè♀ 在职认证  学生认证  发表于 2014-10-17 17:17:48 |只看作者 |坛友微信交流群
lwien007 发表于 2014-10-17 10:50
第一个按年份分隔数据集的代码不能生成11个数据表诶,我已经将日期改成了字符型,可是还是报错,只能生成t1和t11数据步,而且里面没有数据呢。。。

使用道具

地板
lwien007 发表于 2014-10-23 12:15:24 |只看作者 |坛友微信交流群
锦sè♀ 发表于 2014-10-17 17:17
第一个按年份分隔数据集的代码不能生成11个数据表诶,我已经将日期改成了字符型,可是还是报错,只能生成 ...
第一个程序肯定可以生成数据集,你的错误log中提示什么

使用道具

7
锦sè♀ 在职认证  学生认证  发表于 2014-10-23 18:43:37 |只看作者 |坛友微信交流群
lwien007 发表于 2014-10-23 12:15
第一个程序肯定可以生成数据集,你的错误log中提示什么
显示无法识别'2001-1-1',后来改成‘Jan12001’d就可以了,谢谢你!没有你的提醒不知猴年马月才能搞出来呢~

使用道具

8
水晶之恋002 发表于 2016-3-5 11:53:17 |只看作者 |坛友微信交流群
lwien007 发表于 2014-10-17 10:50
你好,根据你的代码我按每半年分组,结果输入有问题。如图。请问这是什么意思呢?

2A_[FH8O77%HN4SE{2M56H8.png (4.46 KB)

2A_[FH8O77%HN4SE{2M56H8.png

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 22:56