notes8 - 1 1 Notes 8: Reading and Modifying SAS Data Sets...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 1 Notes 8: Reading and Modifying SAS Data Sets Selecting Variables SAS Functions 2 Create a temporary SAS data set named onboard from the permanent SAS data named st.dfwlax and create a variable that represents the total passengers on board. Sum FirstClass and Economy values to compute Total . New Variable Reading a SAS Data Set Flight Date Dest FirstClass Economy 439 14955 LAX 20 137 921 14955 DFW 20 131 114 14956 LAX 15 170 Total 157 151 185 SAS date values st.dfwlax 3 To create a SAS data set using a SAS data set as input , you must use a DATA statement to start a DATA step and name the SAS data set being created (output data set: onboard) SET statement to identify the SAS data set being read ( input data set: st.dfwlax ). To create a variable , you must use an assignment statement to add the values of the variables FirstClass and Economy and assign the sum to the variable Total. Reading a SAS Data Set 4 By default, the SET statement reads all of the observations from the input SAS data set variables from the input SAS data set. General form of a DATA step: Reading a SAS Data Set DATA output- SAS-data-set ; SET input- SAS-data-set ; additional SAS statements RUN; DATA output- SAS-data-set ; SET input- SAS-data-set ; additional SAS statements RUN; 5 An assignment statement evaluates an expression assigns the resulting value to a variable. General form of an assignment statement: Assignment Statements variable=expression; variable=expression; 6 Operators are s symbols that request arithmetic calculations s SAS functions. Operands are s variable names s constants. An expression contains operands and operators that form a set of instructions that produce a value. SAS Expressions 2 7 Selected operators for basic arithmetic calculations in an assignment statement: Operator Action Example Priority + Addition Sum=x+y; III - Subtraction Diff=x-y; III * Multiplication Mult=x*y; II / Division Divide=x/y; II ** Exponentiation Raise=x**y; I - Negative prefix Negative=-x; I Using Operators 8 Flight $ 3 Date N 8 Dest $ 3 FirstClass N 8 Economy N 8 PDV Compiling the DATA Step libname st ' SAS-data-library '; data onboard; set st.dfwlax; Total=FirstClass+Economy; run; 9 Flight $ 3 Date N 8 Dest $ 3 FirstClass N 8 Economy N 8 Total N 8 PDV Compiling the DATA Step libname st ' SAS-data-library '; data onboard; set st.dfwlax; Total=FirstClass+Economy; run; 10 Flight Date Dest FirstClass Economy 439 12/11/00 LAX 20 137 921 12/11/00 DFW 20 131 114 12/12/00 LAX 15 170 Flight Date Dest FirstClass Economy Total . . . . st.dfwlax PDV onboard Executing the DATA Step data onboard; set st.dfwlax; Total=FirstClass+Economy; run; Flight Date Dest FirstClass Economy Total 11 Flight Date Dest FirstClass Economy 439 12/11/00 LAX 20 137 921 12/11/00 DFW 20 131 114 12/12/00 LAX 15 170 Flight Date Dest FirstClass Economy Total 439 12/11/00 LAX 20 137 ....
View Full Document

Page1 / 9

notes8 - 1 1 Notes 8: Reading and Modifying SAS Data Sets...

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

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