data want;
set a end=eof;
retain cc;
if _n_=1 then
cc=c;
else
cc+c;
if eof then
sum_c=cc/_N_;
Run;
Why do you divide the sum into 3 ?
Do you want to compute the mean value of C ?
If positive - use proc means:
proc means data=a;
class;
var a;
run;
data want;
set a end=eof;
retain cc;
if _n_=1 then
cc=c;
else
cc+c;
if eof then
sum_c=cc/_N_;
Run;
proc means data=a;
class;
var a;
output out=want mean=new_var;
run;
@Siennayun wrote:
I understand that I can use
proc means a sum;
Variable;
To get the sum,
But how can I get the Sum(c)/3 ?
Always divide the sum by 3? Or divide by 3 because there are three observations (and so you would always divide by the number of non missing values)?
data a; input c e; datalines; 3 2 4 2 5 3 ; Run; proc sql; select sum(c)/count(c) as x from a; quit;
@Siennayun wrote:
How can I get a result of the sum(c)/3
data a;
input c e;
datalines;
3 2
4 2
5 3;
Run;
please post what you expect as result. What should happen to variable e?
Please show exactly how you want the output data set to appear.
And do something about all of the extra blank rows in your code. Easiest to copy code from your SAS editor and paste into a code box on the forum that is opened with the </> or "running man" icon. Anything else is likely to have the forum windows reformat text removing spaces and inserting html tags that make for ugly code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.