Learning SAS? Welcome to the exclusive online community for all SAS learners.

Sum Statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

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
Super User
Posts: 6,502

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 ;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,621

Re: Sum Statement

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

Super User
Posts: 17,868

Re: Sum Statement

Occasional Contributor
Posts: 5

Re: Sum Statement

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

Super User
Posts: 10,516

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: );

     put add= sum1= sum2=;

run;

Trusted Advisor
Posts: 1,621

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?

Solution
‎06-12-2015 05:41 PM
Super User
Super User
Posts: 6,502

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 475 views
  • 0 likes
  • 5 in conversation