BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Siennayun
Calcite | Level 5
How can I get a result of the sum(c)/3



data a;

input c e;

datalines;

3 2

4 2

5 3;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11
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;

View solution in original post

8 REPLIES 8
Shmuel
Garnet | Level 18

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;
Siennayun
Calcite | Level 5
I understand that I can use
proc means a sum;
Variable;
To get the sum,
But how can I get the Sum(c)/3 ?
ghosh
Barite | Level 11
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;
Shmuel
Garnet | Level 18
proc means data=a;
 class;
 var a;
 output out=want mean=new_var;
run;
PaigeMiller
Diamond | Level 26

@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)?

--
Paige Miller
Ksharp
Super User
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;
andreas_lds
Jade | Level 19

@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?

ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 1038 views
  • 0 likes
  • 7 in conversation