全部版块 我的主页
论坛 站务区 十一区 新手入门区
5730 8
2019-07-04
请问我如何把图中的每一列数据减去这一列的平均值,然后再除以这一列标准差的算术平方根,比如图中MEDN001这一列,每个观测值我需要经过以下转变:(观测值-该列平均值)/该列标准差算术平方根,得到的转变后的结果然后输出到新的数据集,列名不变。请各位大神指教!


附件列表
微信图片_20190704095444.png

原图尺寸 86.64 KB

微信图片_20190704095444.png

二维码

扫码加我 拉你入群

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

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

全部回复
2019-7-13 22:05:32
/*产生测试数据:假设数据变量名,没有规律可以先重命名,33是数据变量的个数*/
data test;
retain sample;
array medn(33);
do i=1 to 14;
   if i<10 then
      sample='ysp30'||compress(i);
   else
      sample='ysp3'||compress(i);
   do j=1 to 33;
      medn(j)=ranuni(0);
   end;
   output;
end;
drop i j;
run;
/*求每个变量的均值和标准差*/
proc means data=test mean std;
output out=testmeans;
run;
data testmean;
set testmeans;
if _stat_="MEAN";
RUN;
data teststd;
set testmeans;
if _stat_="STD";
RUN;
/*将标准差和均值合并到源数据中*/
data testall;
set testmean teststd test;
run;
/*计算每个(变量的值-均值)/标准差*/
data result;
set testall;
array mednmean(33) ;
array mednstd(33);
array medn(33);
retain mednmean mednstd;
if _n_=1 then
   do i=1 to 33;
      mednmean(i)=medn(i);
   end;
else if _n_=2 then
   do i=1 to 33;
      mednstd(i)=medn(i);
   end;
else
   do i=1 to 33;
      medn(i)=(medn(i)-mednmean(i))/mednstd(i);
   end;
run;
/*删除多余变量和观测值*/
data result;
retain sample;
set result;
keep sample medn1-medn33;
if _stat_="MEAN" then delete;
if _stat_="STD" then delete;
run;
二维码

扫码加我 拉你入群

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

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

2019-7-13 22:05:49
/*产生测试数据:假设数据变量名,没有规律可以先重命名,33是数据变量的个数*/
data test;
retain sample;
array medn(33);
do i=1 to 14;
   if i<10 then
      sample='ysp30'||compress(i);
   else
      sample='ysp3'||compress(i);
   do j=1 to 33;
      medn(j)=ranuni(0);
   end;
   output;
end;
drop i j;
run;
/*求每个变量的均值和标准差*/
proc means data=test mean std;
output out=testmeans;
run;
data testmean;
set testmeans;
if _stat_="MEAN";
RUN;
data teststd;
set testmeans;
if _stat_="STD";
RUN;
/*将标准差和均值合并到源数据中*/
data testall;
set testmean teststd test;
run;
/*计算每个(变量的值-均值)/标准差*/
data result;
set testall;
array mednmean(33) ;
array mednstd(33);
array medn(33);
retain mednmean mednstd;
if _n_=1 then
   do i=1 to 33;
      mednmean(i)=medn(i);
   end;
else if _n_=2 then
   do i=1 to 33;
      mednstd(i)=medn(i);
   end;
else
   do i=1 to 33;
      medn(i)=(medn(i)-mednmean(i))/mednstd(i);
   end;
run;
/*删除多余变量和观测值*/
data result;
retain sample;
set result;
keep sample medn1-medn33;
if _stat_="MEAN" then delete;
if _stat_="STD" then delete;
run;
二维码

扫码加我 拉你入群

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

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

2019-7-13 22:07:59
二维码

扫码加我 拉你入群

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

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

2019-7-13 22:08:05
二维码

扫码加我 拉你入群

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

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

2019-7-13 22:08:21
/*产生测试数据:假设数据变量名,没有规律可以先重命名,33是数据变量的个数*/
data test;
retain sample;
array medn(33);
do i=1 to 14;
   if i<10 then
      sample='ysp30'||compress(i);
   else
      sample='ysp3'||compress(i);
   do j=1 to 33;
      medn(j)=ranuni(0);
   end;
   output;
end;
drop i j;
run;
/*求每个变量的均值和标准差*/
proc means data=test mean std;
output out=testmeans;
run;
data testmean;
set testmeans;
if _stat_="MEAN";
RUN;
data teststd;
set testmeans;
if _stat_="STD";
RUN;
/*将标准差和均值合并到源数据中*/
data testall;
set testmean teststd test;
run;
/*计算每个(变量的值-均值)/标准差*/
data result;
set testall;
array mednmean(33) ;
array mednstd(33);
array medn(33);
retain mednmean mednstd;
if _n_=1 then
   do i=1 to 33;
      mednmean(i)=medn(i);
   end;
else if _n_=2 then
   do i=1 to 33;
      mednstd(i)=medn(i);
   end;
else
   do i=1 to 33;
      medn(i)=(medn(i)-mednmean(i))/mednstd(i);
   end;
run;
/*删除多余变量和观测值*/
data result;
retain sample;
set result;
keep sample medn1-medn33;
if _stat_="MEAN" then delete;
if _stat_="STD" then delete;
run;
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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