Milad
Milad

Reputation: 339

How to add a column containing mean value to a table in SAS

Assume this is my dataset:

data test;
   input  Age ;
   datalines;
34 
28 
27 
36 
32 
39 
12 
32 
;

How can I add a column to this dataset which contains the average value of the age column?

Upvotes: 1

Views: 820

Answers (2)

DomPazz
DomPazz

Reputation: 12465

Use PROC SQL;

proc sql;
create table test2 as
select age, 
       mean(age) as age_mean
from test;
quit;

Without a GROUP BY statement, SQL will merge the mean back with the original values.

Upvotes: 3

Shenglin Chen
Shenglin Chen

Reputation: 4554

It is easy to get it with proc sql.

proc sql;
   select *,mean(age) as Age_mean from test;
quit;

Upvotes: 1

Related Questions