## Mean of all observation in a separate column

Solved
Super Contributor
Posts: 409

# Mean of all observation in a separate column

Hi, is there a way I can calculate the mean for a column and display it consistently throughout each observation.. here's what I mean

HAVE:

Var1     Var2

DE          3

LM          .

SE          5

WANT:

Var1     Var2     MEAN

DE          3              4

LM          .               4

SE          5              4

Thanks

Accepted Solutions
Solution
‎06-15-2012 11:31 AM
Super Contributor
Posts: 1,636

## Re: Mean of all observation in a separate column

data have;

infile cards missover;

input Var1 :\$     Var2;

cards;

DE          3

LM          .

SE          5

;

proc sql;

create table want as

select *,mean(var2) as mean

from have;

quit;

proc print;run;

Linlin

All Replies
Solution
‎06-15-2012 11:31 AM
Super Contributor
Posts: 1,636

## Re: Mean of all observation in a separate column

data have;

infile cards missover;

input Var1 :\$     Var2;

cards;

DE          3

LM          .

SE          5

;

proc sql;

create table want as

select *,mean(var2) as mean

from have;

quit;

proc print;run;

Linlin

Super Contributor
Posts: 409

## Re: Mean of all observation in a separate column

Thanks Linlin, it works perfectly

Super Contributor
Posts: 1,636

## Re: Mean of all observation in a separate column

Super Contributor
Posts: 409

## Re: Mean of all observation in a separate column

I'm not so savy in proc sql, but how could I create anew field in the same procedure that calculates the difference between Mean and Var2 ?  Thanks

Super Contributor
Posts: 1,636

## Re: Mean of all observation in a separate column

Yes,sure.

data have;

infile cards missover;

input Var1 :\$     Var2;

cards;

DE          3

LM          .

SE          5

;

proc sql;

create table want as

select *,mean(var2) as mean,calculated mean-var2 as diff

from have;

quit;

proc print;run;

Linlin

🔒 This topic is solved and locked.