Statistical Analysis System : Summarizing Data

Only available on StudyMode
  • Topic: Assignment, Missing values, MCAR
  • Pages : 14 (1690 words )
  • Download(s) : 79
  • Published : November 15, 2012
Open Document
Text Preview
Chapter 3 Summarizing Data
0.1 0.2 Introduction...........................................................................Error! Bookmark not defined. A Section Title .......................................................................Error! Bookmark not defined. Demonstration: ............................... Error! Bookmark not defined. Exercises ................................................................................... Error! Bookmark not defined.

0.3 0.4

Chapter Summary .................................................................Error! Bookmark not defined. Solutions ...............................................................................Error! Bookmark not defined. Solutions to Exercises ............................................................... Error! Bookmark not defined. Solutions to Student Activities (Polls/Quizzes) .......................... Error! Bookmark not defined.

3-2

Chapter 3 Summarizing Data

3.1 Creating an Accumulating Total Variable

3-3

3.1 Creating an Accumulating Total Variable

Objectives
  

Explain how SAS initializes the value of a variable in the PDV. Prevent reinitialization of a variable in the PDV. Create an accumulating variable.

3

Business Scenario
A retail manager for Orion Star Sportswear asked to see her department’s daily sales for April, as well as a month-to-date total for each day.

Create a new data set, mnthtot, that includes the month-to-date total (Mth2Dte) for each day. Partial Listing of mnthtot
SaleDate 01APR2007 02APR2007 03APR2007 04APR2007 05APR2007 Sale Amt 498.49 946.50 994.97 564.59 783.01 Mth2Dte 498.49 1444.99 2439.96 3004.55 3787.56

4

3-4

Chapter 3 Summarizing Data

Input Data
The SAS data set orion.aprsales contains daily sales data from the Orion Star Sportswear department. Partial Listing of orion.aprsales SaleDate 01APR2007 02APR2007 03APR2007 04APR2007 05APR2007 06APR2007 07APR2007 SaleAmt 498.49 946.50 994.97 564.59 783.01 228.82 930.57

One observation for each day in April shows the date (SaleDate) and the total sales for that day (SaleAmt).

5

3.01 Quiz
Open and submit the program in p203a01. Does this program create the correct values for Mth2Dte? data mnthtot; set orion.aprsales; Mth2Dte=Mth2Dte+SaleAmt; run;

7

p203a01

3.1 Creating an Accumulating Total Variable

3-5

Creating an Accumulating Variable
By default, variables created with an assignment statement are initialized to missing at the top of each iteration of the DATA step. Mth2Dte=Mth2Dte+SaleAmt;

Mth2Dte is an example of an accumulating variable that
needs to keep its value from one observation to the next.

9

The RETAIN Statement
The RETAIN statement prevents SAS from reinitializing the values of new variables at the top of the DATA step.

General form of the RETAIN statement: RETAIN variable-name …; Previous values of retained variables are available for processing across iterations of the DATA step.

10

3-6

Chapter 3 Summarizing Data

The RETAIN Statement – Details
The RETAIN statement  retains the value of the variable in the PDV across iterations of the DATA step  initializes the retained variable to missing before the first iteration of the DATA step if an initial value is not specified  is a compile-time-only statement.  The RETAIN statement has no effect on variables that are read with SET, MERGE, or UPDATE statements; variables read from SAS data sets are automatically retained.

11

A variable referenced in the RETAIN statement appears in the output SAS data set only if it is given an initial value or referenced elsewhere in the DATA step.

Create an Accumulating Variable
Retain the values of Mth2Dte and set an initial value. data mnthtot; set orion.aprsales; retain Mth2Dte 0; Mth2Dte=Mth2Dte+SaleAmt; run;

If you do not supply an initial value, all the values of Mth2Dte will be missing.

12

p203d02



The input SAS data set must be...
tracking img