BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
podarum
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

View solution in original post

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

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

podarum
Quartz | Level 8

Thanks Linlin, it works perfectly

Linlin
Lapis Lazuli | Level 10

then should you mark my answer as correct answer instead of yours?Smiley Wink

podarum
Quartz | Level 8

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

Linlin
Lapis Lazuli | Level 10

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

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 7780 views
  • 0 likes
  • 2 in conversation