0
votes

I am confused between what we call the statement below in the 2 programs in SAS ? 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;
4
What language is this? - Spencer Wieczorek

4 Answers

3
votes

It does appear both are called SUM statement. One is a Data set SUM statement and the second is a Proc Print Sum statement. However, they do operate differently.

Reference to the SAS 9.2 Documentation: Data step SUM statement http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000289454.htm

Proc Print SUM Statement http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000064121.htm

Short version: The Data step SUM includes an implicit retain on the variable Total and calculates a running total.

The Proc Print SUM statement adds a total sum to the dataset as the final row but does not include a running total.

1
votes

If I am understanding your question clearly...

The SUM "function" (used in a data step) will handle missing values, using total= var1 + var2 in a data step will not (handle missing values). Examples below...

data sales;
input a b c d;
cards;
1 2 3 .
4 5 . 8
. 4 6 .
4 5 1 2
;
run;

The SUM function below will produce your "Total" column even if you have missing values -

data new;
set sales;
Total=sum(a,c);
run;

The data step below using the (+) sign will produce your "Total" value as "missing" if there are missing values in the variables you are adding -

data new2;
set sales;
Total = a + c;
run;
0
votes

You could call first program to calculate cumulative sum, what each record get total is sum of salary of current record and all sums of salary of before records,at last record, total is sum of salary of all records. In second program, you only get sum of salary of all records.

-1
votes

I would like to strengthen @Reeze answer by giving attention to sum statement and sumfunction.

When you come across pseudo code/ SAS programming exam for DATA STEP, you would find the two terms appear frequently.

Sum function refers to the use of sum(variable(s)) in any statements.

Sumstatement refers to the use of the auto-retained form of summing variables : a + b

They are similar in the way that they both could handle missing value well.