全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1559 9
2012-11-13
悬赏 15 个论坛币 已解决
QQ截图20121113162433.png
如图所示,数据由因变量Y与自变量x1-x200构成整个数据集,储存在在work.indices中;
现在我想将x1与x2-x200做归一化,x2与x3-x200做归一化,....依此类推直到x199与x200做归一化,公式为:

n1=(x1-x2)/(x1+x2),n2=(x1-x3)/(x1+x3),n3=(x1-x4)/(x1+x4),n4=(x1-x5)/(x1+x5),.........n201=(x2-x3)/(x2+x3),.......
nK=(x199-x200)/(x199+x200).(K为常数)
将所有数据在所得到的新变量还是按照Y、n1、n2、n3....nk储存起来在新的数据集work.new中。




最佳答案

pobel 查看完整内容

是不是这样?
二维码

扫码加我 拉你入群

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

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

全部回复
2012-11-13 16:47:41
是不是这样?
复制代码
二维码

扫码加我 拉你入群

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

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

2012-11-13 17:58:43
data ex;
input x1-x5;
cards;
1 2 3 4 5
6 7 8 9 10
;
run;

data ex1;
set ex;
array   m(5)  x1-x5;
array n(10);
sum=0;
do i=1 to dim(m)-1;
    if i ne 1 then  sum+(dim(m)-i+1);
    do j=i to dim(m)-1;
        if (m(i)+m(j+1))=0 then
    n(sum+j-i+1)=.;
        else
        n(sum+j-i+1)=(m(i)-m(j+1))/(m(i)+m(j+1));
end;
end;
run;
二维码

扫码加我 拉你入群

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

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

2012-11-13 18:24:13
pobel 发表于 2012-11-13 17:29
是不是这样?
65   data test;
66       y=1000;
67           array x[200] x1-x200;
68           do _n_=1 to 200;
69              x(_n_)=_n_;
70           end;
71   run;

NOTE: The data set WORK.TEST has 1 observations and 201 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


72
73   data test1;
74       set test;
75           array x(200);
76           array nn(19900) ;
77           do i=1 to 199;
78             do j=i+1 to 200;
79            num+1;
80                    nn(num)=(x(i)-x(j))/(x(i)+x(j));
81             end;
82           end;
83           keep y nn:;
                    --
                    241
ERROR 241-185: The array nn is not allowed in a DROP/KEEP/RENAME context.

84   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST1 may be incomplete.  When this step was stopped there were 0
         observations and 19901 variables.
WARNING: Data set WORK.TEST1 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.04 seconds

数据未能读入进去。。如上所示: there were 0
         observations and 19901 variables.
二维码

扫码加我 拉你入群

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

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

2012-11-13 19:47:03
黄建荣 发表于 2012-11-13 18:24
65   data test;
66       y=1000;
67           array x[200] x1-x200;
40   data test;
41       y=1000;
42           array x[200] x1-x200;
43           do _n_=1 to 200;
44              x(_n_)=_n_;
45           end;
46   run;

NOTE: The data set WORK.TEST has 1 observations and 201 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds


47
48   data test1;
49       set test;
50           array x(200);
51           array nn(19900) ;
52           do i=1 to 199;
53             do j=i+1 to 200;
54                   num+1;
55                    nn(num)=(x(i)-x(j))/(x(i)+x(j));
56             end;
57           end;
58           keep y nn:;
59   run;

NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST1 has 1 observations and 19901 variables.
NOTE: DATA statement used (Total process time):
      real time           0.09 seconds
      cpu time            0.07 seconds
二维码

扫码加我 拉你入群

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

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

2012-11-13 21:05:49
pobel 发表于 2012-11-13 19:47
40   data test;
41       y=1000;
42           array x[200] x1-x200;
您好,谢谢您的耐心帮助,但是我的程序还是老是在nn上面出错,我用SAS9.0 ,是不是我支持nn:的用法?如下:

219          keep y nn:;
                    --
                    241
ERROR 241-185: The array nn is not allowed in a DROP/KEEP/RENAME context.

220  run;
怎么办啊?本人对循环是不太懂。。谢谢您的回复
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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