ST522 Final Exam (Modules 5-7)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the value of FOOT after execution? data _null_; call symputx('foot','No Internet orders'); %let foot=Some Internet orders; run;

"No internet orders" bc it calls symputx after everything else has run.

Character arguments in a FUNCTION statement must be followed by ____________________

$

How many macro variables are created here? What is it called? proc sql noprint; select sum(total_retail_price) format=dollar8. into :total from orion.order_fact where year(order_date)=2011 and order_type=3; quit; %put &=total;

1 variable is created It is called "total" (look at the "into" clause)

Name the 4 steps to define a HASH object

1) Declare HASH Object 2) Define the KEY components 3) Define the DATA components 4) Complete the definition

Name the 4 types of PROC SQL joins

1) INNER 2) LEFT (outer) 3)FULL (outer) 4)RIGHT (outer)

Name the 4 DATA step methods to combine data horizontally

1) MERGE 2) SET 3) UPDATE 4) MODIFY

What 3 things can SYMPUTX create macro variable with?

1) Static Values (Data Step Vars) 2) Dynamic Values (Data Step Expressions) 3)Dynamic Names (Character literals)

Given name=Joseph Berman with custID of 9, describe the first and second scan of indirect reference &&name&custID

1st: &name9 2nd: Joseph Berman

How many changes to this are required to create an order history for "custID 4" %let custID=9; proc print data=orion.order_fact; where customer_ID=&custID; var order_date order_type quantity total_retail_price; title1 "Customer Number: &custID"; title2 "Customer Name: &name9"; run;

2 changes. "9" should be changed to "4" on the first line & the line above RUN

How many columns & rows does the following array contain? array B{2,5}

2 rows / 5 columns

Which of the following ARRAY statements are similar to the statement array yr{1978:2011} Yr1978-Yr2011; and compile without errors? a) array yr{34} Yr1978-Yr2011; b) array yr{1978-2011} Yr1978-Yr2011; c) array yr{78:11} Yr1978-Yr2011; d) array yr{78-011} Yr1978-Yr2011;

A

How many elements are created by the following ARRAY statement? array myarray(5:9,7); a) 35 b) 0 bc the statement is incorrect c) 63

A 5 rows X 7 cols = 35 elements

Which of the following statements is FALSE regarding an ARRAY statement? a) It is an executable statement. b) It can be used to create variables. c) It must contain either all numeric or all character elements. d) It must be used to define an array before the array name can be referenced.

A An ARRAY statement is a compile-time only statement

If the value of cargosum is $1000 at the end of the first iteration of the DATA step shown below, what is the value of cargosum in the PDV when the DATA step is in its third iteration? if _n_=1 then set sasuser.summary (keep=cargosum); set sasuser.monthsum (keep=salemon revcargo); PctRev=revcargo/cargosum;

A SAS retains the initial $1000 value as long as the DATA step continues to iterate.

The summary data set contains one observation and the detail data set contains 50 observations. How many observations are in the data set combined? data combined; set summary; set detail; run; a) 1 b) 50 c) 100 d) none of the above

A When you use multiple SET statements, processing stops when SAS encounters the end-of-file marker on any data set, even if there is more data in the other data sets.

Which of the following are true regarding the hash iterator (hiter) object? a) You must define the hash object, which is referenced by the hiter object before the DECLARE statement for the hiter object. b) Ascending is the only valid method of moving through the hiter object. c) You can move through the hiter object using either the key or data items. d) The hiter object is an ordered view of the hash object.

A & D

Given the following program and data, what is the value of the variable Points in the fifth observation in the data set results? data results; array score{2,4} _temporary_ (40,50,60,70,40,50,60,70); set work.contest; Points=score{week,finish}; run; a) 40 b) 50 c) 60 d) 70

A - 40

Which of the following statements is true? a) Hash object keys can be character, numeric, or both. b) Hash objects use less memory than arrays. c) You use the FIND method to assign initial values to the key and data variables. d) The size of a hash object is determined at compile time.

A - There is no restriction on the type or number of key variables for a hash object.

What is PROC FCMP?

A method of simplifying the repetitive use of business rules. This enables you to read, write, and maintain complex code with independent and reusable subroutines.

What is an array?

A way to refer to a group of variables with a single name

Select the ARRAY dimension that correctly defines the compare array in the following program: data rainwear.coat; infile xyz; input category high1-high3/low1-low3; array compare{?,?} high1-high3 low1-low3; do i=1 to 2; do j=1 to 3; compare {i,j}= round(compare{i,j}*1.12);.... a) 2,3 b) 1,6 c) 3,2 d) 1,3

A) 2,3 There are six elements in the array, but there are three columns and two rows in the array based on the DO loops and the array references.

What does the ADD method do to a HASH object?

Adds the KEY and DATA values to the HASH Object

What do multiple ampersands preceding a name token denote?

An indirect reference

What does the SYMPUTX routine do?

Assigns to a macro variable any value available to the DATA step during execution time

When does the DATA step processing stop?

At the first end-of-file marker that is encountered

Where does the NEXT method start in the HASH object?

At the first item in the HASH object

When is a DO WHILE condition checked?

At the start of the loop

Which of the following do you use to retrieve matching data from the hash object? a) ADD method b) FIND method c) NEXT method d) PREV method

B

Which of these is an example of a table lookup? a) You have the data for January sales in one data set, February sales in a second data set, and March sales in a third. You need to create a report for the entire first quarter. b) You want to send birthday cards to employees. The employees' names and addresses are in one data set and their birthdates are in another. c) You need to calculate the amount that each customer owes for his purchases. The price per item and the number of items purchased are stored in the same data set.

B

You want to merge three data sets that do not all share a common variable. The first two share StartDate, and the last two share Instructor. How can you use a DATA step to merge these three data sets into one new data set? a) You use a MERGE statement in one DATA step to merge the three data sets by StartDate and Instructor. b) You sort the first two by StartDate and merge them into a temporary data set. Then you sort the temporary data set and the last file by Instructor and merge them into a final data set. c) You can merge these data sets only with a PROC SQL step. d) You cannot merge these three data sets at all because they do not have a common variable.

B If there are variables that are common to at least two of the input data sets, and if each input data set contains at least one of these variables, then you can use consecutive DATA steps to merge the data sets.

Given the ARRAY statement below, select the array reference for the array element q50. array ques{3,25} q1-q75; a) ques{2,q50} b) ques{2,25} c) ques{1,50} d) ques{3.0}

B It's 25 columns across, so the 50th element would be at the end of the 2nd row

Which type of SQL join most closely mimics a DATA step merge? a) inner join b) full outer join c) left outer join d) right outer join

B Like the DATA step, both matches and nonmatches are returned by a full outer join.

Which functions can be used to extract the first name and last name values and rearrange them as shown? EmpName = Lu, Patrick Changed = Patrick Lu a) SUBSTR b) LEFT c) CATX d) SCAN e) TRIM

B C D E

Which of the following statements instantiates a hash object named Sales and loads it with values for the orion.budget data set? a) declare object sales(); b)declare hash sales(dataset: 'orion.budget'); c) declare hash sales(orion.budget); d) declare hash sales(dataset: orion.budget);

B D is wrong because it doesn't have single quotes around orion.budget

Which TWO of the following pairs of methods are used to retrieve data starting from the top and bottom of a hiter object? FIRST( ) and PREV( ) FIRST( ) and NEXT( ) LAST( ) and PREV( ) LAST( ) and NEXT( )

B & C

What are the lookup keys in DATA step merges?

BY variables

Which of the following is true of the GROUPFORMAT option? a) available in both the DATA step and PROC steps b) must be used with the NOTSORTED option c) enables the DATA step to process data in formatted groups d) can be used in a WHERE or BY statement

C The GROUPFORMAT option can be used only in the DATA step and only in a BY statement. It does not require the NOTSORTED option.

Which of the following statements about the _IORC_ variable is false? a) If the most recent SET statement with the KEY= option executes successfully, the value of _IORC_ equals 0. b) SAS automatically creates _IORC_ when you use a SET statement with the KEY= option in a DATA step. c) A value of 0 for _IORC_ means that the most recent SET statement with the KEY= option did not execute successfully. d) You can use the _IORC_ variable to prevent nonmatching data from being included when you use an index to combine data from multiple data sets.

C If the value of _IORC_ is 0, the index search was successful.

If the data set country has seven observations and the data set orion.continent has five observations, what stops the execution of the DATA step that contains a MERGE statement? a) the end of file for country b) the end of file for orion.continent c) the end of file for both data sets

C The DATA step sequentially reads and attempts to match all observation from all data sets that are listed in the MERGE statement.

Which DATA step statement is used to route PUT statement output to an external file? a) INFILE b) INPUT c) FILE d) SET

C The FILE statement can route the output from a PUT statement to an external file.

Given the following program, which statement is false? if _n_=1 then do i=1 to 3; set sasuser.ctargets; array mnth{*} Jan-Dec; do j=1 to dim(mnth); targets{year,j}=mnth{j}; end; a) The IF-THEN statement specifies that the targets array loads once. b) During the first iteration of the DATA step, the outer DO loop executes three times. c) After the first iteration of the outer DO loop, SAS executes the second SET statement. d) During the second iteration of the DATA step, the condition _N_=1 is false, so the DO loop does not execute.

C The second SET statement is outside of a DO loop whose condition is that _N_=1 and I iterates from 1 to 3. The outer DO loop executes three times before the second SET statement executes.

Which statements creates a 4 column / 3 row array with "m1" through "m12" as the values? a) array Sales{4,3} m1-m12; b) array{3,4} Sales m1-m12; c) array Sales{3,4} m1-m12; d) array{4,12} Sales m1-m12;

C The syntax is: ARRAY array-name{rows,columns} variables-list;

Which of the following techniques can be used to combine data on a condition other than equality? a) multiple SET statements in the DATA step b) PROC SQL joins c) Either of the above can be used.

C When combining data conditionally, you can use multiple SET statements or PROC SQL.

Which of the following statements is false about using multiple SET statements in one DATA step? a) You can use multiple SET statements to combine observations from several SAS data sets. b) Processing stops when SAS encounters the end-of-file marker on any data set, even if there is more data in the other data sets. c) You can use multiple SET statements in one DATA step only if the data sets in each SET statement have a common variable. d) The variables in the PDV are not reinitialized when SAS executes a second SET statement.

C You can use multiple SET statements in one DATA step to combine observations from several data sets without a common variable.

How many elements are in the array that is defined array by the following ARRAY statement? B{12,2007:2011} _temporary_; a) 0 b) 48 c) 60 d) 24

C - 60

What does the OUT= option do?

Creates a SAS data set

What does the INTO clause do?

Creates macro variables from query results

Which of the following is an advantage of using multiple SET statements with the KEY= option? a) You can use an existing index. b) You can use the automatic variable _IORC_ to control nonmatching data. c) SAS reads only the necessary observations. d) all of the above

D

Which of the following can you create using the DATA step? a) custom reports b) data-dependent programs c) data sets d) all of the above

D The DATA step, although it is used primarily to create data sets, can also be used to create custom reports and data-dependent programs.

Which DO statement processes all of the elements in the Yearx array? array Yearx{12} Jan-Dec; a) do i=1 to dim(Yearx); b) do i=1 to 12; c) do 1=Jan to Dec; d) a and b

D The DIM function returns the dimension of a single dimension array. You can hardcode the STOP value, if you know what it is.

Complete the ARRAY statement below to create temporary array elements that have initial values of 10, 29, 104, and 119. array score{4} _____________________; a) temporary (10 29 104 119) b) _temporary_ 10 29 104 119 c) (temporary) 10, 29, 104, 119 d) _temporary_ (10, 29, 104, 119)

D The keyword _temporary_ requires the leading and trailing underscores. The list of initial values must be enclosed in parentheses and separated by commas.

Array values should be stored in a SAS data set when ________________________________. a) there are too many values to initialize easily in an array b) the values change frequently c) the same values are used in many programs d) all of the above

D - All of the above

Which of the following correctly explains the purpose of the DEFINEDONE method? a) defines the data variables for the hash object b) creates and names the hash object c) defines the key variables for the hash object d) completes the initialization of the hash object

D - The DEFINEDONE method completes the initialization of the hash object.

The KEY and DATA components of a HASH Object must also be defined as _____________________________

DATA step variables

What statement is used to create a HASH object?

DECLARE

With DATA step merges & PROC SQL joins, does the lookup table reside on DISK or IN MEMORY?

Disk

What happens when you run the portion beginning with "if 0 then..." data supplier_info; if _N_=1 then do; if 0 then set orion.supplier(keep=SupplierID SupplierName SupplierAddress Country); a) SAS adds these variables to the PDV. b) The SET statement does not execute. c) The CALL MISSING routine is no longer needed. d) These variables are initialized to missing. e) all of the above f) none of the above

E The non-executing SET statement creates the slots in the PDV and initializes the variables to missing, which replaces the CALL MISSING routine.

Which of the following values are available to the SYMPUTX routine? a) DATA step variables b) DATA step expressions c) DATA step character literals d) b and c only e) all of the above

E) All of the above

TRUE/FALSE: A RETURN statement is not required for each function definition

FALSE

TRUE/FALSE: A one-dimensional array CANNOT serve as a lookup table

FALSE

TRUE/FALSE: Data loaded into a hash object needs to be sorted or indexed

FALSE

TRUE/FALSE: The %LET statement is a macro trigger that works during execution time.

FALSE

TRUE/FALSE: The SYMPUTX routine is a DATA step statement that works during DATA step word-scanning time.

FALSE

TRUE/FALSE: An ARRAY statement is a exectution-time only statement

FALSE An ARRAY statement is a compile-time only statement

TRUE/FALSE: The CMPLIB option is required to create user-defined functions in PROC FCMP.

FALSE The CMPLIB option is not needed to CREATE user-defined functions and subroutines. It is needed to USE them.

TRUE/FALSE: You can only nest formats supplied by SAS.

FALSE You can nest formats that are supplied by SAS and user-defined formats.

TRUE/FALSE: A HASH object must be loaded with values from a SAS data set

FALSE - HASH object values can be hard coded as well

TRUE/FALSE: DO WHILE conditions are checked at the end of the loop.

FALSE. DO WHILE conditions are checked at the top of the loop. If the condition is false, the loop does not execute.

TRUE/FALSE: In a DATA step merge, the data sets are NOT sorted or indexed by the key columns.

FALSE. In a DATA step merge, the data sets must be sorted or indexed by the key columns.

TRUE/FALSE: You cannot use arrays in PROC FCMP.

FALSE. You can use arrays in PROC FCMP.

TRUE/FALSE: An indirect reference is coded with a single ampersand.

False

How long do HASH Objects exist?

For the duration of the DATA step

What does the UNIQUE option do?

Forces SAS to ignore duplicates in the KEY= index

What does PROC SUMMARY do?

Generates descriptive statistics

What does the temporary variable _IORC_ do?

Holds the input/output return code when the KEY= option is used.

Do PROC SQL joins & DATA step merges combine data sets horizontally or vertically?

Horizontally

What SQL clause creates macro variables? a) INTO b) CMAC c) MVAR d) MACRO

INTO

What does the RETURN statement do in a function?

It defines the expression that generates the value that the function returns.

What does they KEY= option change?

KEY= changes the reading of data from sequential to direct access.

A hash object resembles a table and contains a __________ component and a ________________ component

Key & Data

Table Location: Disk Lookup Table: ______________________ Technique: _________________________

Lookup Table: SAS Data set Technique: SQL join, MERGE, SET/SET KEY=

Table Location: DATA Step Lookup Table: ______________________ Technique: _________________________

Lookup Table: SAS Programming Statements Technique: IF-THEN-ELSE statements

Does this syntax by itself perform a table lookup? data catalogcustomers; set orion.catalog; set orion.customerdimmore; run;

No

Do DATA step merges and PROC SQL joins always produce the same results?

No.

Can a DATA step merge be used to match based on an inequality?

No. The DATA step merge requires matches to be based on equality.

In a HASH object, the KEY & DATA components can be _______________ or _____________________

Numeric or Character

Two ampersands resolves to......

One ampersand.

%let custid=9; %let name9=Joe; %put &name&custid; How many times are the macro variables scanned in the PUT statement?

One time

What is the FIND method used for in a HASH object?

Retrieve data from the HASH object

What does the SYMGET function do?

Retrieves a macro variable's value during DATA step execution.

What does a NON-ZERO value for _IORC_ mean?

SAS did not find an observation matching the current value in the KEY= index

What does a value of 0 for _IORC_ mean?

SAS found an observation matching the current value in the KEY= index

The ARRAY statement below creates temporary array elements. What is created if _temporary_ is omitted? array ContName{91:96} $ 30 _temporary_ ('North America'......);

SAS variables ContName1-ContName6 and array elements are created.

What should you use to explicitly handle non matches when combining data sets?

SQL OUTER JOIN

What does the CMPLIB= system option do?

Specifies one or more data sets that SAS searches for user-defined function entries.

What does the SEPARATED BY argument do?

Stores multiple values in a single macro variable

TRUE/FALSE - A one dimensional array is like a numbered row

TRUE

TRUE/FALSE: A RETURN statement can be embedded within conditional expressions.

TRUE

TRUE/FALSE: Key components and data components specified in the hash object must be DATA step variables in the PDV.

TRUE

TRUE/FALSE: Multiple functions can be defined per FCMP step.

TRUE

TRUE/FALSE: The CALL SYMPUTX statement creates macro variables in the DATA step

TRUE

TRUE/FALSE: The HASH Object is sized dynamically

TRUE

TRUE/FALSE: The KEY component of a HASH object can be composite

TRUE

TRUE/FALSE: The data component of a hash table can contain multiple values per key value.

TRUE

TRUE/FALSE: One advantage of PROC SQL joins for conditionally combining data over multiple SET statements in the DATA step is that the data does not have to be pre-sorted or indexed.

TRUE PROC SQL can be used to join data that does not share a commonly named column, is not sorted or indexed, and has joins that are not based on equality.

Table Location: Memory Lookup Table: Array Technique: _________________________

Technique: Array reference

Table Location: Memory Lookup Table: Hash object Technique: _________________________

Technique: FIND method

Table Location: Memory Lookup Table: User Defined Format Technique: _________________________

Technique: FORMAT, PUT statement, PUT function

What is used to declare an Array?

The ARRAY statement

Why are statements in the DO group programmed to execute only one time?

They are executable. HASH object memory is not released and reused each time. You can run out of memory if there's a lot of data to load.

TRUE/FALSE: An indirect reference is coded with multiple ampersands.

True

TRUE/FALSE: The %LET statement is a macro trigger that works during word-scanning time.

True

TRUE/FALSE: The SYMPUTX routine is a DATA step statement that works during DATA step execution time.

True

TRUE/FALSE: Two ampersands always resolve to one ampersand.

True

True/False: The INTO clause create multiple macro variables

True

How long does forward macro variable scanning continue?

Unit no more references can be resolved.

How are values retrieved from the DATA component in a hash object?

Values are retrieved based on values in the KEY component

What are the lookup keys in PROC SQL joins?

WHERE or ON variables

When would a DATA step merge and a PROC SQL join NOT produce the same results?

When there are non-matches.

Is the following explanation of the difference between the SYMPUTX and the %LET statement accurate? -The SYMPUTX routine is a DATA step statement that works during DATA step execution time. -The %LET statement is a macro trigger that works during word-scanning time.

Yes

%let custid=9; %let name9=Joe; %put &name&custid; Will this program generate an error?

Yes. Apparent symbolic reference NAME not resolved. (need && in front of name)

What two values can the temporary variable _IORC_ have?

Zero or Non-Zero

What temporary variable does SAS create when the KEY= option is used?

_IORC_

What is the SYMPUTX routine?

a DATA step statement that assigns a text value to a macro value.

A SAS function is a routine that accepts ________________, performs a data manipulation, and returns a _____________________.

arguments / value

Which technique creates macro variables during execution time? a) %LET statement b) SYMPUTX routine c) INTO clause d) both b and c

d) both B & C

Why is the following code incorrect (declares a hiter)? data work.report; if _N_=1 then do; if 0 then set sasuser.cities(keep=Code City Name); declare hash airports(dataset: 'sasuser.cities'); airports.definekey('Code'); airports.definedata('City', 'Name'); airports.definedone(); declare.hiter fly(); end;

declare.hiter fly(); SHOULD BE declare hiter fly(); (no period & needs to be named after a HASH object)

What statement is used to end HASH object definition?

definedone(_)

Write an OPTIONS statement that adds the orion.formats catalog to the path that SAS searches when it looks for format definitions.

options fmtsearch=(ORION);

What is the default SAS data set SAS will search for functions?

work.functions


Set pelajaran terkait

Spanish 1 Midterm: Short Answer Questions

View Set

OSHA 30 Health and Safety Program

View Set

Principles of Information Security, 4th Edition. Chapter 1 Review Questions

View Set

High Risk Antepartum Maternity Exam #1

View Set

**Study Guide for Ecology EXAM 2**

View Set

FIT-041-S003 - Fitness For Living Well

View Set

Foundations of Business Chapter 1

View Set