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

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.

 

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
  • 5931 views
  • 0 likes
  • 2 in conversation