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
How about:
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
How about:
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
Thanks Linlin, it works perfectly
then should you mark my answer as correct answer instead of yours?
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
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.