楼主: 小鳄鱼a
1468 6

请问个有条件做标记的问题 [推广有奖]

  • 6关注
  • 10粉丝

已卖:280份资源

学科带头人

3%

还不是VIP/贵宾

-

威望
0
论坛币
125 个
通用积分
0.0040
学术水平
40 点
热心指数
45 点
信用等级
43 点
经验
32801 点
帖子
1185
精华
0
在线时间
1539 小时
注册时间
2009-7-16
最后登录
2018-10-5

楼主
小鳄鱼a 发表于 2014-12-26 09:21:30 |AI写论文
20论坛币
请看附件

book1.rar
下载链接: https://bbs.pinggu.org/a-1701362.html

6.81 KB

需要: 5 个论坛币  [购买]

本附件包括:

  • book1.xlsx

最佳答案

jl60156 查看完整内容

proc import datafile='\book1.xlsx' dbms=xlsx out=test replace; range="Sheet1$A19:D46"; getnames=yes; run; %macro test(n=,m=); %let k=%eval(&n+1); data test1; merge test %do i=2 %to &k; test(keep=tcode rename=(tcode=tcode&i) firstobs=&i) %end;; run; data test1(keep=fcode date tcode yn _yn); set test1; retain _cnt _yn; if sum(tcode=tcode2>. %do j=3 %to &k; ,tco ...

沙发
jl60156(未真实交易用户) 发表于 2014-12-26 09:21:31
proc import datafile='\book1.xlsx'
                dbms=xlsx
                out=test replace;
                range="Sheet1$A19:D46";
        getnames=yes;
run;

%macro test(n=,m=);
%let k=%eval(&n+1);
data test1;
        merge test %do i=2 %to &k; test(keep=tcode rename=(tcode=tcode&i) firstobs=&i) %end;;
run;

data test1(keep=fcode        date         tcode        yn _yn);
        set test1;
        retain _cnt _yn;
        if sum(tcode=tcode2>. %do j=3 %to &k; ,tcode=tcode&j>. %end;)>=&m and not missing(tcode&k) then do;
                _yn=1;
                _cnt=1;       
        end;       
        else if _cnt>&n then do;
        _cnt=1;
        _yn=0;
        end;       
        else _cnt+1;
run;
%mend;
%test(n=3, m=2);
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
admin_kefu + 30 根据规定进行奖励
Tigflanker + 5 + 3 + 3 + 3 热心帮助其他会员

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

藤椅
sushe1527(未真实交易用户) 发表于 2014-12-26 10:08:29
意思是连续4个数,出现任意3个就标记1? 那。。箭头那符合吗?

QQ截图20141226100255.jpg (133.39 KB)

QQ截图20141226100255.jpg

板凳
小鳄鱼a(未真实交易用户) 发表于 2014-12-26 10:13:25
sushe1527 发表于 2014-12-26 10:08
意思是连续4个数,出现任意3个就标记1? 那。。箭头那符合吗?
是,前提是从当期往前看三期,实际上如果这样的,第12个的200406刚开始应该不赋值或者赋值为0,但是当看200412的时候,由于条件满足,又重新被赋值为1

报纸
sushe1527(未真实交易用户) 发表于 2014-12-26 10:31:57
小鳄鱼a 发表于 2014-12-26 10:13
是,前提是从当期往前看三期,实际上如果这样的,第12个的200406刚开始应该不赋值或者赋值为0,但是当看2 ...
我知道你的意思,我是说两个红色箭头都符合条件?最终产生连续6个1的结果?任何连续3个数字加个空行,都会产生4选3的结果。妥妥的 这样的都符合条件?




2010
2010
2010






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

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

地板
小鳄鱼a(未真实交易用户) 发表于 2014-12-26 10:41:02
sushe1527 发表于 2014-12-26 10:31
我知道你的意思,我是说两个红色箭头都符合条件?最终产生连续6个1的结果?任何连续3个数字加个空行,产生 ...
哦   我明白您的意思了   不好意思   是我疏忽了     加个限定条件吧   当期t持有的情况下,t-3期也是要持有的这个样只要t-1 t-2中任意一期持有条件都满足

7
mingfeng07(未真实交易用户) 学生认证  发表于 2014-12-26 11:31:08
  1. data b;
  2. set test;
  3. id=_n_;
  4. run;
  5. proc sql;
  6. create table c as select b.*,b1.id as id1,b1.tcode as new_tcode,b.id-b1.id as value from b,b as b1 where 0<=b.id-b1.id<=3 order by b.id;
  7. quit;       
  8. proc sort data=c out=c1;by id id1;run;
  9. data c2;
  10. set c1;
  11. by id id1;
  12. if first.id then do;
  13. if not missing(new_tcode) then sum=2;
  14. else sum=0;
  15. end;
  16. if not first.id and not last.id then do;
  17. if not missing(new_tcode) then sum+1;
  18. end;
  19. if last.id then do;
  20. if not missing(new_tcode) then sum+2;
  21. end;
  22. run;
  23. proc sql;
  24. create table c3 as select *,max(sum) as yn,case when calculated yn>=5 then 1 else 0 end as yn1 from c2 group by id;
  25. create table c4 as select distinct id1,max(yn1) as yn from c3 group by id1;
  26. create table c5 as select id,tcode,yn from b,c4 where id1=id order by id;
  27. quit;
复制代码

已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
小鳄鱼a + 5 + 3 + 3 + 3 精彩帖子
Tigflanker + 5 + 3 + 3 + 3 热心帮助其他会员

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

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-17 12:26