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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 627 views
  • 0 likes
  • 7 in conversation