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

im trying to find out column level mean function.

 

data m;
input name$ var1 var2 var3;
cards;
a 10 0 5
b 1 2 0
c 9 5 8
;run;

 

proc means data=m nway noprint;
var var1 var2;
output out=rmean;
run;

 

proc sql;
create table m3 as
select mean(var2) as mean
from m;
quit;

 

now proc means and proc sql both are giving column wise mean value

but i was trying to use this but why this is not working in data set approach:---

 

data m2;
set m;
c1=mean(var2);
run;

 

this is not working plz help me

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

in a data step you would have to go back to basics:

 

data m2;
set sashelp.class end=done;
s + weight;
n + (not missing(weight));
if done then do;
    mean = s/n;
    output;
    end;
keep n mean;
run;
PG

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

The MEAN function in a DATA step does means across columns within each row, not across rows. Your example then of having one variable inside your MEAN function is pointless as it will just return the value of that column. It is only useful for more than one column.

PGStats
Opal | Level 21

in a data step you would have to go back to basics:

 

data m2;
set sashelp.class end=done;
s + weight;
n + (not missing(weight));
if done then do;
    mean = s/n;
    output;
    end;
keep n mean;
run;
PG

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1687 views
  • 0 likes
  • 3 in conversation