楼主: 雨中蝴蝶
1017 4

[原创博文] 数据循环的问题 [推广有奖]

  • 1关注
  • 1粉丝

大专生

80%

还不是VIP/贵宾

-

威望
0
论坛币
27 个
通用积分
0
学术水平
3 点
热心指数
5 点
信用等级
4 点
经验
616 点
帖子
42
精华
0
在线时间
31 小时
注册时间
2011-9-15
最后登录
2020-1-16

楼主
雨中蝴蝶 发表于 2012-3-11 20:32:29 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
现有数据简化如下:
要求:
     如果a是3,则b对应的值也是3,并且还要让b的这个3前面的观测值为2,在向前为1,后面的值为4,在向后为5,在在向后为6.
     如果3有重复,则新形成一列c,以此类推。请大侠给予指点!
a     b
4
1
2
3
6
3
3
4
5
7
具体要实现如下效果:
a     b        c       d
4              
1     1
2     2
3     3      1
6     4      2        1
3     5      3        2
3     6      4        3
4             5        4
5             6        5
7                       6
二维码

扫码加我 拉你入群

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

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

关键词:观测值

沙发
freerunning_sky 在职认证  发表于 2012-3-11 22:57:39
  1. data a;
  2.         input a;
  3.         cards;
  4.         4
  5.         1
  6.         2
  7.         3
  8.         6
  9.         3
  10.         3
  11.         4
  12.         5
  13.         7
  14.         ;
  15. run;

  16. data b;
  17.         set a;
  18.         array tmp(*) b1 c1 d1 e1 f1 g1;
  19.         retain b1 c1 d1 e1 f1 g1 j;
  20.         do i=1 to dim(tmp);
  21.                 if tmp(i)~=. then tmp(i)=tmp(i)+1;
  22.                 if tmp(i)>=7 then tmp(i)=.;
  23.                 if tmp(i)=. & a=3 then do;
  24.                         tmp(i)=3;
  25.                         leave;
  26.                 end;
  27.         end;
  28.         index=_n_;
  29.         drop i;
  30. run;

  31. proc sort data=b;by descending index;run;

  32. data c;
  33.         set b;
  34.         array tmp1(*) b1 c1 d1 e1 f1 g1;
  35.         array tmp2(*) b c d e f g;
  36.         retain b c d e f g;
  37.         do i=1 to dim(tmp1);
  38.                 if tmp1(i)~=. then tmp2(i)=tmp1(i)+1;
  39.                 tmp2(i)=tmp2(i)-1;
  40.                 if tmp2(i)<=0 then tmp2(i)=.;
  41.         end;
  42.         keep a b c d e f g index;
  43. run;

  44. proc sort data=c out=output(drop=index);by index;run;
  45.        
复制代码

藤椅
雨中蝴蝶 发表于 2012-3-12 16:22:05
方向好像有点相反,但正是我想要的谢谢楼上的大侠

板凳
jingju11 发表于 2012-3-13 02:11:57
  1. data _null_;
  2.    ...;run;
  3. data b; drop n i j;
  4.    set a end =Eof;
  5.    array a_[&na3];
  6.    array t[&obs] _temporary_; array tt[&na3] _temporary_;
  7.    t[_n_] =a;
  8.    if a =3 then do;
  9.          n ++1; tt[n] =_n_;
  10.    end;
  11.    if Eof then do i =1 to _n_;
  12.          a =t[i];
  13.          do j =1 to n;
  14.             if i >tt[j] -3 and i <=tt[j] +3 then a_[j] =i -tt[j] +3;
  15.                else a_[j] =.;
  16.          end;      
  17.         output;
  18.    end;
  19. run;
复制代码
one of other ways. just for reference. Jingju

报纸
sunset1986 发表于 2012-3-13 11:45:50
thx for sharing
An honest tale speeds best being plainly told.
Cheers!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 16:51