Module 8 PPT Lesson 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Automatic Character-to-Numeric Conversion

-The values in GrossPay contain commas, which cannot be converted by the w. informat, so GrossPay is assigned a missing value. -To explicitly convert the values in GrossPay, use the INPUT function.

Automatic Character-to-Numeric Conversion SAS automatically converts a character value to a numeric value when the character value is used in a numeric context, such as the following:

-assignment to a numeric variable -an arithmetic operation -logical comparison with a numeric value -a function that takes numeric arguments ! The WHERE statement and the WHERE= data set option do not perform any automatic conversion in comparisons.

Automatic Character-to-Numeric Conversion The automatic conversion

-uses the w. informat -produces a numeric missing value from a character value that does not conform to standard numeric notation.

Business Scenario

Analysts want to calculate statistics to summarize and average each employee's quarterly contributions for the year.

LENGTH Function The LENGTH function returns the length of a non-blank character string, excluding trailing blanks.

General form of the LENGTH function:

Open and submit the program file p205a01. Find and correct the syntax error. Check the log for the corrected program. How many observations and variables are in the shoes data set? data shoes; set orion.product_list; if substr(right(Product_Name,33,13))= 'Running Shoes'; run;

Misplaced parentheses are some of the most common syntax errors with functions. After running the corrected program, the shoes data set has eight observations and five variables.

15.12 Short Answer Poll

Open and run the program p205a02. Did GrossPay become a numeric variable?

Automatic Numeric-to-Character Conversion

SAS converts the numeric values in Code into character values automatically.

FIND Function

The FIND function searches a target string for a specified substring.

ROUND Function

The ROUND function returns a value rounded to the nearest multiple of rounding unit.

TRANWRD Function: Details

The TRANWRD function replaces or removes all occurrences of a given word (or a pattern of characters) within a character string. These details apply when you use the TRANWRD function: -The TRANWRD function does not remove trailing -lanks from target or replacement. -If NewVar is not previously defined, it is given a length of 200. -If the target string is not found in the source, then no replacement occurs.

Converting a Variable to Another Data Type Step 3 Use a DROP= data set option in the DATA statement to exclude the original variable from the output SAS data set.

The compilation for this program shows the PDV being created with a numeric GrossPay variable.

Converting a Variable to Another Data Type

This assignment statement does not change GrossPay from a character variable to a numeric variable. A variable is character or numeric. After the variable's type is established, it cannot be changed. By following three steps, you can create a new variable with the same name and a different type.

SCAN Function: Details When you use the SCAN function:

When you use the SCAN function: a.A missing value is returned if there are fewer than n words in the string. b.If n is negative, the SCAN function selects the word in the character string starting from the end of string. c.The length of the created variable is the length of the first argument starting in SAS release 9.4. d.The length of the created variable is 200 bytes in SAS release 9.3 and earlier. e.Delimiters before the first word have no effect. f.Any character or set of characters can serve as delimiters. g.Two or more contiguous delimiters are treated as a single delimiter.

c

Which SUBSTR function can extract the group of five numbers from the middle of the Item_Code value? a. substr(Item_Code,5,7) b. substr(Item_Code,5) c. substr(Item_Code,7,5) d. substr(Item_Code,'mid',5)

SUBSTR Function (Left Side) This form of the SUBSTR function (left side of assignment statement) replaces characters in a character variable.

Example: Replace two characters starting at position 11.

d

15.07 Multiple Choice Poll What expression completes the assignment statement to correctly extract 2007 from the Text variable? data Scan_Quiz; Text="New Year's Day, January 1st, 2007"; Year= ??? ; run; a. scan(Text,-1); b. scan(Text,6); c. scan(Text,6,', '); d. All of the above would work.

b The INT and the FLOOR functions give different results if the argument value is negative.

15.09 Poll Given the same value as an argument, do the INT and the FLOOR functions always return the same result? a.Yes b.No

b Adding the amount from all three orders and then subtracting the amount of the smallest order leaves the sum of the two largest orders.

15.10 Multiple Choice Poll Ord1, Ord2, and Ord3 are variables that contain the sale amounts of the last three orders from all customers who have three orders or more. Which of the following expressions can calculate the total of the two largest orders? a. sum(max(of Ord1-Ord3),max(of Ord1-Ord3)) b. sum(of Ord1-Ord3)-min(of Ord1-Ord3) c. max(of Ord1-Ord3) + min(of Ord1-Ord3) d. none of the above

15.11 Short Answer Poll Fill in the missing expression in the DATA step below. The expression should calculate TotalValue by multiplying SharePrice by MyShares. data Input_Quiz; SharePrice="$130.25"; MyShares=125; TotalValue= ???? MyShares; run;

15.11 Short Answer Poll

SAS Functions SAS provides a large library of functions for manipulating data during DATA step execution. A SAS function is often categorized by the type of data manipulation performed: a.Array b.Character c.Date and Time d.Descriptive Statistics e.Financial f.Mathematical g.all of the above

A SAS function is often categorized by the type of data manipulation performed: a.Array b.Character c.Date and Time d.Descriptive Statistics e.Financial f.Mathematical g.all of the above

Data Conversion

Data types can be converted two ways: -automatically by enabling SAS to do it for you -explicitly with these functions:


Ensembles d'études connexes

Chapter 11: Managing Application Security

View Set

MSSC Test 2 (Through Tolerencing)

View Set