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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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