全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1628 2
2011-07-26
大家好!
我写了下面的代码,但是为什么虽然没有报错,但是仍然没有结果。

主要是统计isbuy这个序列(这个序列是由0和1组成的)中,连续的0和连续的1这种串有多少个。要求是按照股票代码来统计的。

proc sort data=sh;by code date time;run;

data runcount;
        set sh nobs=nobs end=last;
        by  code date;
        prev=( lag(isbuy) = 0 );
        curr=( isbuy = 0 );
if first.code=1 or first.date=1 then do;runs=0; numzero=0;end;
else do;

        if curr and prev then do;numzero+1; end;
        else if curr and ^prev then
           do;
           runs+1;
           numzero+1;
           end;
        else if ^curr and prev then runs+1;
        if last then
          do;
          numone=nobs-numzero;
          n=nobs;
          output;
          end;
end;
keep code date runs numpos numneg n;
run;

数据在附件中。

谢谢!
附件列表

sh.rar

大小:1.23 KB

 马上下载

本附件包括:

  • sh.sas7bdat

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-7-26 17:04:19
最后的numneg那里来的?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-7-26 17:40:43
是不是这样?


data runcount;
        set sh nobs=nobs end=last;
        by  code date;
               
        prev=( lag(isbuy) = 0 );
        curr=( isbuy = 0 );
if first.code=1 then do;runs=0; numzero=0;end;
else do;

        if curr and prev then do;numzero+1; end;
        else if curr and ^prev then
           do;
           runs+1;
           numzero+1;
           end;
        else if ^curr and prev then runs+1;
        if last.code then
          do;
          numone=nobs-numzero;
          n=nobs;
          output;
          end;
end;
keep code date runs numone numzero n;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群