## Sum Statement

Solved
Occasional Contributor
Posts: 5

# Sum Statement

Hi Everyone,

I am confused between what we call the statement below in the 2 programs?

Are both the statements called  SUM statements?

I got confused when I came across a question where it was asked if SUM statement can be used in DATA step. I was wondering which sum statement they were referring to?

First Program-

Data s1;

set Ori.sales;

Total+Salary;  /* What do you call this highlighted statement */

run;

Second Program-

Proc print data=ori.sales;

sum Salary;  /* What do you call this highlighted statement */

run;

Accepted Solutions
Solution
‎06-12-2015 05:41 PM
Super User
Posts: 8,089

## Re: Sum Statement

Both are sum statements, but mean different things and are used in different places.

You can get context from the way they asked the question.

For example if they show a statement like

SUM SALARY;

and asked if it was valid in a Data step then the answer is NO.  But if they just asked "can a sum statement be used in a data step" or "what is the syntax for a sum statement in a data step" then it is obvious they are talking about a statement of the form:

VARNAME + expression ;

All Replies
Posts: 3,000

## Re: Sum Statement

According to the SAS Help and Documentation, both are properly referred to as "Sum Statements"

--
Paige Miller
Super User
Posts: 23,700

## Re: Sum Statement

Occasional Contributor
Posts: 5

## Re: Sum Statement

It was me actually who posted there at Stackoverflow :-)

Super User
Posts: 13,523

## Re: Sum Statement

```Data s1;
set Ori.sales;
Total+Salary;  /* What do you call this highlighted statement */
run;

```

Don't know if there is a formal term but I would think of the variable Total as an accumulator holding running totals though this construct is also used as a simple counter.

```Proc print data=ori.sales;
sum Salary;  /* What do you call this highlighted statement */
run;

```

Sum here would be a SUMMARY as it will print at the end of the print job to display a total for the named variable(s).

SUM has different but related meanings depending on where used. It is a Statistic that may be requested in a number of procedures such as Proc Means and Tabulate. In a data set the specific Function sum is to handle addition with added behaviors of not having to type lots of + signs and can use lists of similarly named variables as well as summing variables with values and ignoring missing values.

Short example program;

Data _null_;

file print;

x1 = 1; x2=3; x3=. ; x4=10;

add = x1 + x2 + x3 + x4;

sum1 = sum(x1,x2,x3,x4);

sum2 = sum( of x: );

run;

Posts: 3,000

## Re: Sum Statement

So what is the real underlying question here?

Is the question about the names of the statements?

Is the question about where each statement can be used?

Is the question about where summing can be performed?

Is the question supposed to see if a user knows the difference between different ways to sum in SAS?

Is this a homework question designed to trick new SAS users?

--
Paige Miller
Solution
‎06-12-2015 05:41 PM
Super User
Posts: 8,089

## Re: Sum Statement

Both are sum statements, but mean different things and are used in different places.

You can get context from the way they asked the question.

For example if they show a statement like

SUM SALARY;

and asked if it was valid in a Data step then the answer is NO.  But if they just asked "can a sum statement be used in a data step" or "what is the syntax for a sum statement in a data step" then it is obvious they are talking about a statement of the form:

VARNAME + expression ;

🔒 This topic is solved and locked.