Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
Data Manipulation [18-18]


(+) Expression
 
Combining the use of the Retain statement and the SUM function allows you to compute the summation across observations.

The (+) Expression presents a shortcut that allows you to achieve the same results.
Picture

Again, the REVENUE data set contains the weekly revenue for 10 weeks. 

Another way to compute the revenue summation is to use the (+) expression.

Example

Data Revenue2;
Set Revenue;
Total + Revenue;
Run;
Picture

The code above achieves the same result without having to use the Retain statement and the Sum function!

Let's take a look at the code one more time:
​
Total + Revenue;

The code above does the following:
  1. It creates the variable Total with no initial value (missing)
  2. The variable Total has a built-in retain capability. Its value is retained from one observation to the next
  3. The (+ Revenue) syntax adds the revenue to the variable Total on each observation.

As a result, the summation of revenue is computed.
​
Picture

This method presents a short cut in calculating the cumulative summation.

Exercise

Copy and run the INVENTORY data set from the yellow box below:

​The INVENTORY data set contains the inventory of a bookshelf from a furniture store.

Compute the total inventory across all of the stores using the (+) expression.
Next

Need some help? 


HINT:
No Retain statement or Sum function is needed when using the (+) expression.


SOLUTION:

Data Inventory2;
Set Inventory;
Total+Qty;
Run;


Fill out my online form.

Already a member? Go to member's area.