SAS Training Day3 - SAS Training Day3 SAS SAS Data Set Creation and modification Creating an Accumulating Variable By Default the SAS variables

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

View Full Document Right Arrow Icon
SAS Training – Day3 SAS Training – Day3
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 SAS Data Set Creation and modification Creating an Accumulating Variable By Default the SAS variables created with an assignment statement are initialized to missing at the top of the DATA step. When we want to retain a variable value across observations then we go for RETAIN statement. General form of RETAIN statement RETAIN variable-name <initial-value>…. .; Previous values of retained variables are available for processing across iterations of the DATA step.
Background image of page 2
3 SAS Data Set Creation and modification Creating an Accumulating Variable 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. 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. If we do not specify an initial value then all the values will be missing.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 SAS Data Set Creation and modification Creating an Accumulating Variable SalesDate SalesAmt 15066 498.49 15067 946.50 15068 994.97 15069 564.59 15070 783.01 data mnthtot; set prog2.daysales; retain Mth2Dte 0 ; Mth2Dte=Mth2Dte+SaleAmt; run ; SALESDATE SALESAMT MTH2DTE 15066 498.49 498.49 R Compile (0+498.49)
Background image of page 4
5 SAS Data Set Creation and modification Creating an Accumulating Variable SalesDate SalesAmt 15066 498.49 15067 946.50 15068 994.97 15069 564.59 15070 783.01 data mnthtot; set prog2.daysales; retain Mth2Dte 0 ; Mth2Dte=Mth2Dte+SaleAmt; run ; SALESDATE SALESAMT MTH2DTE 15066 498.49 498.49 R (0+498.49) Write out observation to mnthtot
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 SAS Data Set Creation and modification Creating an Accumulating Variable SalesDate SalesAmt 15066 498.49 15067 946.50 15068 994.97 15069 564.59 15070 783.01 data mnthtot; set prog2.daysales; retain Mth2Dte 0 ; Mth2Dte=Mth2Dte+SaleAmt; run ; SALESDATE SALESAMT MTH2DTE 15067 946.50 1444.99 R (498.49+946.50) Write out observation to mnthtot
Background image of page 6
7 SAS Data Set Creation and modification SUM statement What happens if there are missing value for SaleAmt? All the subsequent values of the Mth2Dte variable becomes missing. We can solve this issue using a Sum function . However a sum statement is a more efficient solution. The SUM statement is an alternative to the RETAIN statement when creating an accumulating variable. General form of SUM statement Variable + expression;
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 SAS Data Set Creation and modification SUM statement The SUM statement creates the variable on the left side of the plus sign if it does not exist initializes the variable to zero before the first iteration of the DATA step. automatically retains the variable
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2010 for the course USE 3425 taught by Professor Raman during the Spring '10 term at Punjab Engineering College.

Page1 / 62

SAS Training Day3 - SAS Training Day3 SAS SAS Data Set Creation and modification Creating an Accumulating Variable By Default the SAS variables

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

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