如何在SAS中的现有数据集中添加带分数的新变量?
proc standard data=orig out=age_t mean=50 std=10;
var age ;
run;
我想在原始数据集中创建一个新的变量age_t,每个观察的t分数
答案 0 :(得分:1)
Left Join
原始表格带有Proc Standard
输出。完整代码如下:
创建虚拟数据:
data orig;
input name $ age ;
datalines;
jackieChan 50
Tom 70
Lee 45
Tim .
Sarah 29
Rose 33
;
将标准输出保存到新表" stnd_age":
proc standard data=orig out=stnd_age mean=50 std=10;
var age ;
run;
使用stnd_age左加入Orig表:
proc sql;
create table want as
select orig.* , stnd_age.age as age_t
from orig left join stnd_age on orig.name=stnd_age.name;
quit;
结果:
name=Sarah age=29 age_t=39.873841923
name=Tim age=. age_t=.
name=Tom age=70 age_t=65.189237115
name=jackieCh age=50 age_t=52.840263851