Chapter 4 Creating New Variables Using SAS Functions

Chapter 4 Creating New Variables Using SAS Functions -...

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

View Full Document Right Arrow Icon
STAT1303 Data Management 4. Creating New Variables Using SAS Functions 4C r e a t i n gN e wV a r i a b l e sU s i n gS A SF u n c t i o n s In previous chapter, we have used the SAS procedures for data summarization in which simple calculation is performed. In this chapter, the creation of new variables using the SAS functions are discussed because more complicated calculation is necessary for realistic data management and analysis. 4.1 Assignment Statement To create or modify SAS variables, an assignment statement is used in Data Step. Typically, an assignment statement is speciFed in the form of variable = expression ; The variable receives the new information and the required information / calculations are speciFed in the expression. When the expression contains character data, we must enclose the data in quotation marks or double quotation marks. To deFne the required storage for variables (in particular for character variables), the LENGTH statement should be used. Example 4.1. Assignment statement. *Example4.1-assignmentstate m e n t ; libname mylib ’D:/temp’; data trade; set mylib.trade1; total = import+retained+reexport; run; proc print; run; Obs year category import retained reexport total 11 9 9 5 1 6 1 1 5 8 4 2 9 5 3 1 9 5 3 4 1 2 3 6 4 5 21 9 9 5 2 5 6 2 4 1 5 1 4 2 8 9 7 5 4 6 2 4 71 2 5 1 5 5 9 31 9 9 5 3 5 4 3 0 7 5 2 2 5 7 0 8 3 3 6 5 5 01 1 0 5 3 3 3 ... TOTAL = IMPORT + RETAINED + REEXPORT; Then, a new variable TOTAL which is the sum of IMPORT, RETAINED and REEXPORT, is created. 4.2 Numeric Assignment Operators and Functions 4.2.1 Numeric Variables A numeric variable is a variable whose values are numbers. In SAS, numeric variables are stored and calculated in double-precision ±oating point representation. All kinds of mathematical operations on numeric variables can be performed by SAS and SAS functions extend the mathematical calculation capability for numeric expressions. HKU STAT1303 (2011-12, Semester 1) 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
STAT1303 Data Management 4. Creating New Variables Using SAS Functions 4.2.2 Arithmetic Operators Operation Symbol Example Addition + x=y+z Subtraction - x=y-z Multiplication x=y*z Division / x=y/z Exponentiation ⇤⇤ x=y**z The order of operations in arithmetic expressions follows rules in mathematical expression Parentheses > exponentiation > multiplication and division > addition and subtraction. Example 4.2. Arithmetic operators. *Example4.2-Arithematicoper a t o r s ; libname mylib ’D:/temp’; data trade; set mylib.trade1; total = import+retained+reexport; total2 = total**2; run; proc print; run; Obs year category import retained reexport total total2 11 9 9 5 1 6 1 1 5 8 4 2 9 5 3 1 9 5 3 4 1 2 3 6 4 5 1 5 2 8 8 0 8 6 0 2 5 21 9 9 5 2 5 6 2 4 1 5 1 4 2 8 9 7 5 4 6 2 4 7 1 2 5 1 5 5 91 . 5 6 6 3 9 9 9 E 1 2 31 9 9 5 3 5 4 3 0 7 5 2 2 5 7 0 8 3 3 6 5 5 0 1 1 0 5 3 3 3 1 . 2 2 1 7 6 1 E 1 2 ...
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/09/2012 for the course STAT 1301 taught by Professor Smslee during the Spring '08 term at HKU.

Page1 / 18

Chapter 4 Creating New Variables Using SAS Functions -...

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