请选择 进入手机版 | 继续访问电脑版
楼主: zhouzhoudada
5040 8

[求助] 如何用SAS对数据集做标准化处理 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

高中生

7%

还不是VIP/贵宾

-

威望
0
论坛币
5 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
50 点
帖子
1
精华
0
在线时间
44 小时
注册时间
2019-7-4
最后登录
2021-8-9

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请问我如何把图中的每一列数据减去这一列的平均值,然后再除以这一列标准差的算术平方根,比如图中MEDN001这一列,每个观测值我需要经过以下转变:(观测值-该列平均值)/该列标准差算术平方根,得到的转变后的结果然后输出到新的数据集,列名不变。请各位大神指教!


二维码

扫码加我 拉你入群

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

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

关键词:SAS 数据标准化 代谢组

微信图片_20190704095444.png
glmswufe 发表于 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;
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
admin_kefu + 30 + 3 + 3 + 3 热心帮助其他会员

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

使用道具

glmswufe 发表于 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;

使用道具

glmswufe 发表于 2019-7-13 22:07:59 |显示全部楼层 |坛友微信交流群

使用道具

glmswufe 发表于 2019-7-13 22:08:05 |显示全部楼层 |坛友微信交流群
人大经济论坛问题回复.txt (1.13 KB)

使用道具

glmswufe 发表于 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;

使用道具

glmswufe 发表于 2019-7-13 22:09:25 |显示全部楼层 |坛友微信交流群
/*产生测试数据:假设数据变量名,没有规律可以先重命名,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;
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
admin_kefu + 30 + 3 + 3 + 3 热心帮助其他会员

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

使用道具

glmswufe 发表于 2019-7-13 22:55:36 |显示全部楼层 |坛友微信交流群

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;

使用道具

AimeeZhuo 发表于 2021-7-15 12:01:38 |显示全部楼层 |坛友微信交流群
如果只是做Z-score的话可以直接用proc standard data=xxxx mean=0 std=1试试

使用道具

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

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 15:01