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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.