SAS_Sort_accum_total - Sort And Sort Accumulating...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Sort And Sort And Accumulating Accumulating Totals Totals Last Updated : 29June, 2004 Center of Excellence Data Warehousing
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Objectives Understand how the SAS System initializes the value of a variable in the PDV. Prevent reinitialization of a variable in the PDV. Create an accumulating variable.
Background image of page 2
Creating an Accumulating Variable The SAS data set prog2.daysales contains daily sales data for a retail store. There is one observation for each day in April showing the date ( SaleDate ) and the total receipts for that day ( SaleAmt ). Sal eDat e Sal eAmt 01APR2001 498. 49 02APR2001 946. 50 03APR2001 994. 97 04APR2001 564. 59 05APR2001 783. 01 06APR2001 228. 82 07APR2001 930. 57 08APR2001 211. 47 09APR2001 156. 23 10APR2001 117. 69 11APR2001 374. 73 12APR2001 252. 73
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Creating an Accumulating Variable The store manager also wants to see a running total of sales for the month as of each day. Partial Output Sal e Sal eDat e Amt Mt h2Dt e 01APR2001 498. 49 498. 49 02APR2001 946. 50 1444. 99 03APR2001 994. 97 2439. 96 04APR2001 564. 59 3004. 55 05APR2001 783. 01 3787. 56
Background image of page 4
Creating Mth2Dte By default, variables created with an assignment statement are initialized to missing at the top of the DATA step. An accumulating variable must retain its value from one observation to the next. Mth2Dte=Mth2Dte+SaleAmt;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The RETAIN Statement General form of the RETAIN statement: The RETAIN statement prevents SAS from re- initializing the values of new variables at the top of the DATA step. Previous values of retained variables are available for processing across iterations of the DATA step. RETAIN variable-name < initial-value > … ;
Background image of page 6
The RETAIN Statement 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 execution of the DATA step if an initial value is not specified is a compile-time-only statement.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Retain Mth2Dte and Set an Initial Value If you do not supply an initial value, all the values of Mth2Dte will be missing. retain Mth2Dte 0;
Background image of page 8
data mnthtot; set prog2.daysales; retain Mth2Dte 0; Mth2Dte=Mth2Dte+SaleAmt; run; Creating an Accumulating Variable
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
... ... Sal eDat e Sal eAmt 15066 498. 49 15067 946. 50 15068 994. 97 15069 564. 59 15070 783. 01 SALEAMT data mnthtot; set prog2.daysales; retain Mth2Dte 0; Mth2Dte=Mth2Dte+SaleAmt; run; MTH2DTE SALEDATE R Compile
Background image of page 10
... ... Sal eDat e Sal eAmt 15066 498. 49 15067 946. 50 15068 994. 97 15069 564. 59 15070 783. 01 SALEAMT . data mnthtot; set prog2.daysales; retain Mth2Dte 0; Mth2Dte=Mth2Dte+SaleAmt; run; MNTH2DTE SALEDATE . R Execute 0
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
... Sal eDat e Sal eAmt 15066 498. 49 15067 946. 50 15068 994. 97 15069 564. 59 15070 783. 01 SALEAMT . data mnthtot;
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 77

SAS_Sort_accum_total - Sort And Sort Accumulating...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online