将t得分添加到sas中的现有数据集

时间:2018-04-04 03:33:49

标签: merge sas statistics rank standardized

如何在SAS中的现有数据集中添加带分数的新变量?

proc standard data=orig out=age_t mean=50 std=10; 
var age ;
run; 

我想在原始数据集中创建一个新的变量age_t,每个观察的t分数

1 个答案:

答案 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;

结果:

Left Join

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