SAS_Sort_accum_total - Sort And Sort Accumulating...

Info icon This preview shows pages 1–15. 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
Image of page 1

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

View Full Document Right 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.
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
Image of page 3

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

View Full Document Right 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
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;
Image of page 5

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

View Full Document Right 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 > … ;
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.
Image of page 7

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

View Full Document Right 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;
Image of page 8
data mnthtot; set prog2.daysales; retain Mth2Dte 0; Mth2Dte=Mth2Dte+SaleAmt; run; Creating an Accumulating Variable
Image of page 9

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

View Full Document Right 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
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
Image of page 11

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

View Full Document Right 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; MNTH2DTE SALEDATE . R 498.49 0 15066
Image of page 12
... ... 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 15066 498.49 0 498.49 0+498.49
Image of page 13

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

View Full Document Right Arrow Icon
... ... Write out observation to  mnthtot .
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern