Data Analytics:Data Manipulation Techniques Lesson 3

Ace your homework & exams now with Quizwiz!

Which of the following functions can convert the values of the numeric variable Level to character values? a. put(Level, 3.) b. put(3., Level) c. input(3., Level) d. input(Level, 3.)

Correct answer: a The PUT function explicitly converts numeric values to character values. You specify the keyword PUT followed by the variable name and then the format. The variable name and format are enclosed in parentheses and separated by a comma.

Which function could be used to remove the non-numeric symbols in Phone? Phone202-555-0190202.555.0110(202)555-0133[202]555-0128 a. COMPRESS b. COMPBL c. SCAN d. FIND

Correct answer: a The second argument of the COMPRESS function can be used to specify all symbols to remove from the values of Phone, as shown in the following example: Phone=compress(Phone, '-.()[] '); The optional third argument of COMPRESS could further simplify this code by working with entire character classes instead of having to specify individual characters. For example, the 'd' modifier specifies only digits, and the 'k' modifier instructs COMPRESS to keep the specified items instead of removing them. So specifying 'kd' for the third argument causes COMPRESS to keep only digits. The following example illustrates this use of the third argument of COMPRESS: Phone=compress(Phone,,'kd');

Functions and CALL routines both return a value that must be used in an assignment statement or expression. a. True b. False

Correct answer: b A function returns a value that must be used in an assignment statement or expression, but a CALL routine alters existing column values or performs other system functions.

How many rows are written to output based on the following statement? if find(Location, "Oahu", "i") > 0 then output; Location Honolulu, Oahu Kaanapali, Maui Hilo, Hawaii kailua, oahu LAIE, OAHU a. 0 b. 1 c. 3 d. 5

Correct answer: c The "I" modifier as the third argument in the FIND function makes the search case insensitive.

Which of the following functions converts the character values of Base to numeric values? a. put(comma10.2, Base) b. put(Base, comma10.2) c. input(Base, comma10.2) d. input(comma10.2, Base)

Correct answer: c The INPUT function explicitly converts character values to numeric values. You specify the keyword INPUT followed by the variable name and then the informat. The variable name and informat are enclosed in parentheses and separated by a comma. A numeric informat is needed for character-to-numeric conversions.

Which statement reads CityCountry and correctly assigns a value to Country? CityCountryCountryAthens, GreeceGreeceNew Delhi, IndiaIndiaAuckland, New ZealandNew Zealand a. Country=scan(CityCountry, 2); b. Country=scan(CityCountry, -1); c. Country=scan(CityCountry, 2, ','); d. Country=scan(CityCountry, 2, ', ');

Correct answer: c The SCAN function should return the second word using only the comma as a delimiter.

Which expression rounds each value of Sales to the nearest hundredth (or two decimal places)? a. round(Sales) b. round(Sales, 2) c. round(Sales, .01) d. round(Sales, dollar10.2)

Correct answer: c Use the second argument in the ROUND function to specify the rounding unit.

Which step is not required when converting a character column named Date to a numeric SAS date column with the same name? a. Rename the Date column to a new name, such as CharDate. b. Use the INPUT function to read the renamed CharDate character column and create a numeric column named Date. c. Specify an appropriate informat in the INPUT function. d. Format the new numeric Date column.

Correct answer: d Formatting the new column is not required but is recommended.

Which function calculates the average of the columns Week1, Week2, Week3, and Week4? a. mean(Week1, Week4) b. mean(Week1-Week4) c. mean(of Week1, Week4) d. mean(of Week1-Week4)

Correct answer: d Numeric column lists are specified with a hyphen between the first and last columns in the range. The keyword OF must be used if a column list is used as an argument in a function.

Which expression creates CityCountry? CityCountryCityCountry Athens Greece Athens, Greece New Delhi India New Delhi, India Auckland New Zealand Auckland, New Zealand a. cat(City, ", ", Country) b. cats(", ", City, Country) c. catx(City, ", ", Country) d. catx(", ", City, Country)

Correct answer: d The CATX function concatenates strings together, removes leading and training blanks, and inserts the separator that is defined as the first argument.

SCAN(string, n <, 'delimiters'>)PROPCASE(string <, 'delimiters'>)

FIND(string, substring <, 'modifiers'>)

These functions can be used to truncate decimal values:

Function What it Does CEIL (number) Returns the smallest integer that is greater than or equal to the argument. FLOOR (number) Returns the largest integer that is less than or equal to the argument .INT (number) Returns the integer value.

These functions can be used to combine strings into a single character value. The arguments can be either character or standard numeric values

FunctionWhat it does CAT(string1, ... stringn) Concatenates strings together, does not remove leading or trailing blanks CATS(string1, ... stringn) Concatenates strings together, removes leading or trailing blanks from each string CATX('delimiter', string1, ... stringn) Concatenates strings together, removes leading or trailing blanks from each string, and inserts the delimiter between each string

These functions return a numeric value that identifies the location of selected characters:

FunctionWhat it does LENGTH(string) Returns the length of a non-blank character string, excluding trailing blanks, returns 1 for a completely blank string ANYDIGIT(string) Returns the first position at which a digit is found in the string ANYALPHA(string) Returns the first position at which an alpha character is found in the string ANYPUNCT(string) Returns the first position at which punctuation character is found in the string TRANWRD(source, target, replacement)

DATA output-table; SET input-table (RENAME=(current-column=new-column)); ... column1 = INPUT(source, informat); column2 = PUT(source, format); ... RUN;

The INPUT function converts a character value to a numeric value using a specified informat. SAS automatically tries to convert character values to numeric values using the w. informat. The PUT function converts a numeric or character value to a character value using a specified format. SAS automatically tries to convert numeric values to character values using the BEST12. format. If SAS automatically converts the data, a note is displayed in the SAS log. If you explicitly tell SAS to convert the data with a function, a note is not displayed in the SAS log. Some functions such as the CAT functions automatically convert data from numeric to character and also remove leading blanks on the converted data. No note is displayed in the SAS log.

These functions can be used to remove characters from a string: Function What it does COMPBL(string) Returns a character string with all multiple blanks in the source string converted to single blanks COMPRESS (string <, characters>) Returns a character string with specified characters removed from the source string STRIP(string) Returns a character string with leading and trailing blanks removed

The SCAN function returns the nth word in a string. If n is negative, the SCAN function begins reading from the right side of the string.The default delimiters are as follows: blank ! $ % & ( ) * + , - . / ; < ^ |The optional third argument enables you to specify a delimiter list. All delimiter characters are enclosed in a single set of quotation marks. The PROPCASE function converts all uppercase letters to lowercase letters. It then converts to uppercase the first character of each word.The default delimiters are as follows: blank / - ( . tabThe optional second argument enables you to specify a delimiter list. All delimiter characters are enclosed in a single set of quotation marks.

DATEPART(datetime-value) TIMEPART(datetime-value)

These functions can be used the extract a date or time component of a datetime value:

INTNX(interval,start,increment <,'alignment'>)

This function can be used to adjust or shift date values:

INTCK('interval',start-date,end-date <,'method'>)

This function can be used to count the number of intervals that have occured between a start and end date. You can specify 'C' to use the continuous method for counting intervals:


Related study sets

BIOL 416 FINAL EXAM (OLD EXAM Qs)

View Set