楼主: 小鳄鱼a
1449 29

请教个程序 [推广有奖]

21
jeozu 发表于 2015-10-11 11:26:36
小鳄鱼a 发表于 2015-10-3 10:29
153  proc datasets library=work nowarn noprint;
                                       -------
  ...
直接删除掉proc datasets这个procedure就可以了。在这里是用来删除中间过程生成的数据的。
直接删除到run;quit;就可以了。
主要是功能实现了就可以了。

22
小鳄鱼a 发表于 2015-10-11 21:35:56
jeozu 发表于 2015-9-20 19:48
好像不支持代码了~~,添加在附件。应该是你要的功能。
请看看这个数据     1,3,1995,1
1,2,1996,4
1,2,1997,1
1,3,1995,1
1,3,1995,2
1,3,1998,2
1,3,1998,3
1,3,1999,3
2,3,1995,1
2,3,1995,2
2,3,1995,3
2,3,1998,1
3,3,1995,2
3,3,1995,3
3,3,1998,2
3,3,1999,3
3,4,1996,1
3,4,1996,2
3,2,1997,1
;

stk=3  在1999 3   id 1 3 出现,此时x=2  ,下一期没有 所以y=0 结果应该是 z=(2-1)/(2-1)=1

23
小鳄鱼a 发表于 2015-10-11 21:37:39
jeozu 发表于 2015-10-11 11:26
直接删除掉proc datasets这个procedure就可以了。在这里是用来删除中间过程生成的数据的。
直接删除到ru ...
data ori;
infile datalines dlm=',';
input id stk        year1        qtr2;
qtr=yyq(year1,qtr2);
format qtr yyq9.;
datalines;
1,3,1995,1
1,2,1996,4
1,2,1997,1
1,3,1995,1
1,3,1995,2
1,3,1998,2
1,3,1998,3
1,3,1999,3
2,3,1995,1
2,3,1995,2
2,3,1995,3
2,3,1998,1
3,3,1995,2
3,3,1995,3
3,3,1998,2
3,3,1999,3
3,4,1996,1
3,4,1996,2
3,2,1997,1
;
run;

24
小鳄鱼a 发表于 2015-10-16 17:59:16
还是没有解决

25
小鳄鱼a 发表于 2015-10-31 14:49:32
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

26
johnpark1 发表于 2015-11-1 06:49:25
data test;
infile cards dlm='|';
input id stk year qtr;
qtrSeq = (year-1995)*4 + qtr;
cards;
1|2|1996|3
1|2|1996|4
1|2|1997|1
1|3|1995|1
1|3|1995|2
1|3|1998|2
1|3|1998|3
1|3|1999|3
2|3|1995|1
2|3|1995|2
2|3|1995|3
2|3|1998|1
3|3|1995|2
3|3|1995|3
3|3|1998|2
3|3|2000|1
3|4|1996|1
3|4|1996|2
3|2|1997|1
;
run;

/*Start finding stock entry points */;

proc sort data=test; by stk year qtr qtrSeq; run;
proc means data=test noprint;
        by stk year qtr qtrSeq;
        output out=Stk_entries(keep=stk year qtr qtrSeq) N=N;
run;
data stk_entries; set stk_entries;
        by stk;
        if first.stk then flag=1;
        else if qtrSeq - lag(qtrSeq) > 1 then flag = 1;
        if flag =1 then output;
run;
/*Finish finding Stock Entry points */;


/* Flag customer entry points: initial entry and reentry */;
proc sort data=test; by stk id qtrSeq;
data test2; set test; by stk id;
        if first.id then flag = 1;  /* a customer's initial entry of the stk */;
        stk_last = lag(stk);
        id_last = lag(id);
        qtrSeq = (year-1995)*4 + qtr;
        qtrSeq_last = lag(qtrSeq);
        qtrSeq_prev = qtrSeq-1;
        if stk_last = stk and id_last = id and qtrSeq_last < qtrSeq -1 then flag = 1;  /* a customer's reentry of the stk */
run;

/* Computing new total new entry by stock and quarter */
proc sort data=test2; by stk year qtr qtrSeq;
proc means data=test2(where=(flag=1)) noprint;
by stk year qtr qtrSeq qtrSeq_prev;
output out=stk_Summary N=N;
run;

/* Computing Ratios */;
data stk_Summary;
        merge stk_Summary(keep=stk year qtr qtrseq N) stk_Summary(keep=stk qtrSeq_prev N rename=(qtrSeq_prev=qtrSeq N=N_next));
        by stk qtrSeq;
        x = sum(N, 0); y = sum(N_next, 0);
        if x+y>1 then z = (x-1)/(x+y-1);
        if z > . then output;
run;

data stk_summary_final;
        merge stk_Summary(in=ina) stk_entries(keep=stk year qtr in=inb);
        by stk year qtr;
        if ina*inb;
run;


proc print data=stk_summary_final(obs=2); run;

/** Results */
[td]
Obs__stk__year__qtr__qtrSeq__N__N_next__x__y__z__
1__3__1995__1__1__2__1__2__1__0.5
2__3__1998__1__13__1__2__1__2__0.0__


已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
小鳄鱼a + 5 + 5 + 5 + 5 精彩帖子

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

27
johnpark1 发表于 2015-11-1 07:07:49
小鳄鱼a 发表于 2015-10-11 21:35
请看看这个数据     1,3,1995,1
1,2,1996,4
1,2,1997,1
Curious what's the context of this program. It feels like speed of analysts or institutional analysts covering a stock, but I am puzzled why you have -1 for both denominator and numerator.
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
小鳄鱼a + 5 + 5 + 5 + 5 精彩帖子

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

28
小鳄鱼a 发表于 2015-11-1 09:14:06
johnpark1 发表于 2015-11-1 07:07
Curious what's the context of this program. It feels like speed of analysts or institutional analy ...
it control the economic meanings of this  indicator  ,  it eliminate the obs that a fund buy a stock without coordination with other funds

29
johnpark1 发表于 2015-11-1 09:26:59
小鳄鱼a 发表于 2015-11-1 09:14
it control the economic meanings of this  indicator  ,  it eliminate the obs that a fund buy a sto ...
My code above should work.
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
小鳄鱼a + 5 + 5 + 5 + 5 精彩帖子

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

30
小鳄鱼a 发表于 2015-11-1 09:40:24
johnpark1 发表于 2015-11-1 09:26
My code above should work.
非常感谢    有个人在前面先回答了   不好意思啊   这次先给他了

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-23 02:51