Chapter 5. Creating new variables and SAS functions

Chapter 5. Creating new variables and SAS functions - 1...

Info iconThis preview shows pages 1–11. 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

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight 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 Creating new variables and SAS functions 2 ¡ Assignment statement ¡ numeric assignment operators and functions ¡ Character assignment operators and functions ¡ Comparison and IF-THEN-ELSE construct ¡ Working with Date variables ¢ Reading dates using date informats ¢ Dates manipulation and date functions ¢ Printing dates using date formats 3 Assignment statement ¡ Assignment statement in Data Step create or modify SAS variables ¢ total = import + retained + reexport; *Example 5.1 assignment statement; libname ch5 'C:\temp'; data trade; set ch5.trade1; total=import+retained+reexport; run; proc print; run; 4 Obs year category import retained reexport total 1 1995 1 61158 42953 19534 123645 2 1995 2 562415 142897 546247 1251559 3 1995 3 543075 225708 336550 1105333 ... 5 ¡ An assignment has the form ¢ variable = expression ; ¡ The variable receives the new information ¡ The required information / calculations are specified in the expression ¡ When the expression contains character data, you must enclose the data in quotation marks ¡ Use length statement to define the required storage for variables (in particular for character variables). 6 Numeric variables ¡ A numeric variable is a variable whose values are numbers ¡ SAS uses double-precision floating point representation for calculating and storing numeric variables ¡ SAS can perform all kinds of mathematical operations on numeric variables ¡ SAS functions extend the mathematical calculation capability for numeric expressions 7 Arithmetic operators ¡ Order of operations in arithmetic expressions follows rules in mathematical expression ¢ Parentheses > exponentiation > multiplication and division > addition and subtraction x = y ∗∗ z ∗∗ exponentiation x = y / z / Division x = y ∗ z ∗ Multiplication x = y − z − Subtraction x = y + z + Addition Example Symbol Operation 8 Missing values in numeric variable ¡ A period ( . ) represents missing value in data lines (raw data). ¡ In an expression, a missing numeric values is represented by a period ¢ export = . ; ¡ In PROC output, a missing numeric value is printed as a period (by default) ¡ Some PROC eliminate missing values from analysis; other do not. ¢ some have options to choose from 9 Some common SAS mathematical functions Smallest integer that is greater than or equal to x CEIL(x) Square root of a value SQRT(x) Sign of a value SIGN(x) Remainder from the division of x by y, fuzzed to avoid most unexpected floating-point results MOD(x,y) Natural (base e) logarithm LOG(x) Factorial FACT(n) Value of the exponential function EXP(x) Absolute value ABS(x) Description Function 10 ¡ SAS has other numeric functions in the categorical of...
View Full 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 / 33

Chapter 5. Creating new variables and SAS functions - 1...

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

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