How do I add a new variable with a score in an existing dataset in SAS?
proc standard data=orig out=age_t mean=50 std=10;
var age ;
run;
I want to create a new variable age_t in the original dataset with the t score for every observation
Left Join
your original table with the Proc Standard
output. Full code below:
Creating Dummy Data:
data orig;
input name $ age ;
datalines;
jackieChan 50
Tom 70
Lee 45
Tim .
Sarah 29
Rose 33
;
Saving Standard output to new table "stnd_age":
proc standard data=orig out=stnd_age mean=50 std=10;
var age ;
run;
Left Joining Orig table with stnd_age:
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;
Result:
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