2.1 Flashcards
Which of the following can be done using a SAS data step?
a) read and write tables
b) filter rows
c) compute columns
d) conditionally process
e) subset columns
f) all of the above
f) all of the above
True/False - In the compilation phase of a SAS DATA step, SAS prepares the code and establishes data attributes and the rules for execution.
True - In the execution phase, SAS follows these rules to read, manipulate, and write data.
What is the first thing SAS does in the compilation phase of the DATA step?
a) Creates the PDV
b) Creates the output table metadata
c) Runs through your program to check for syntax errors
d) Reads the first row of data into the PDV
c) Runs through your program to check for syntax errors
True/False - In the compilation phase of the SAS DATA step, SAS builds a critical area of memory called the Program Data Vector (PDV)
True
Which of the following is not part of the SAS compilation phase?
a) PDV is used to hold and manipulate data
b) SAS establishes rules for the PDV based on your code, such as which columns will be dropped, or which rows from the input table will be read
c) SAS creates the descriptor portion, or table metadata
d) All of the above are part of the compilation phase
a) PDV is used to hold and manipulate data. This is part of the execution phase
Given the DATA step below, what will be the length of the Ocean column?
data storm_complete;
set pg2.storm_summary_small;
length Ocean $ 8.;
if substr(Basin, 2, 1) = “1” then Ocean=”Indian”;
else if substr(Basin, 2, 1) = “A” then Ocean=”Atlantic”;
else Ocean=”Pacific”;
run;
a) 8
b) 6
c) 32
d) the code will error
a) 8 - In this code, the LENGTH statement defines the character column Ocean with a length of 8. If the LENGTH statement was placed after then IF-THEN statements, SAS would have used the assignment statement OCEAN=”Indian” to define Ocean with a length of 6.
True/False - Any column in a DROP statement of a DATA step will not be added and read into the PDV.
False - The DROP statement does not remove a column from the PDV. Instead, SAS marks the column with a drop flag so that it’s dropped later in execution.
Which of the following statements are ‘compile-time statements’ and are NOT executed for each row in a table during the execution phase of a SAS DATA step?
a) WHERE
b) LENGTH
c) FORMAT
d) DROP
c) FORMAT
True/False - You can use an explicit OUTPUT statement in the DATA step to force SAS to write the contents of the PDV to the output table at specific points in the program. There will still be an explicit OUTPUT statement at the end of the DATA step.
False - If you use an explicit OUTPUT statement anywhere in a DATA step, you have taken control of the output and there is no implicit OUTPUT at the conclusion of the DATA step. The implicit RETURN at the end of the DATA step still returns processing to the top of the DATA step.
Given the DATA step below, which DATA statement syntax will drop the Returns column from the sales_high table and the Inventory column from the sales_low. a) data sales_high (drop Returns) sales_low (drop Inventory); b) data sales_high (drop=Returns) sales_low (drop=Inventory); c) data sales_high sales_low; drop Returns Inventory; d) data sales_high / drop=Returns sales_low / drop=Inventory;
b) data sales_high (drop=Returns)
sales_low (drop=Inventory);
Which of the statements below is true?
a) When you use a DROP= or KEEP= data set option on a table in the SET statement, the excluded columns are not read into the PDV, so they are not available for processing.
b) When you use a DROP= or KEEP= data set option on a table in the DATA statement, the excluded columns are not read into the PDV, so they are not available for processing.
a) When you use a DROP= or KEEP= data set option on a table in the SET statement, the excluded columns are not read into the PDV, so they are not available for processing.
When you use a DROP or KEEP statement or a DROP= or KEEP= data set option in the DATA statement, columns are included in the PDV and CAN be used for processing. They are flagged to be dropped when an implicit or explicit OUTPUT is reached.
Which statement is false concerning the compilation phase of the DATA step?
a) Initial values are assigned to the columns.
b) The program data vector (PDV) is created.
c) The DATA step is checked for syntax errors.
d) The descriptor portion of the output table is created.
a) Initial values are assigned to the columns.
Initial values are assigned to columns at the beginning of the execution phase.
Which statement is NOT a compile-time-only statement?
a) KEEP
b) LENGTH
c) SET
d) WHERE
c) SET
At execution time, the SET statement is processed to read data into the PDV. The compile-time statements of KEEP, LENGTH, and WHERE are not processed at execution time. The rules of these statements are processed in the compilation phase so that their impact will be observed in the output table.
Which statement is true concerning the execution phase of the DATA step?
a) Data is processed in the program data vector (PDV)
b) An implied OUTPUT occurs at the top of the DATA step
c) An implied REINITIALIZE occurs at the bottom of the DATA step
d) Columns read from the input table are set to missing when SAS returns to the top of the DATA step.
a) Data is processed in the program data vector (PDV)
During execution, data manipulation occurs in a PDV. An implied OUTPUT and RETURN (not REINITIALIZE) occurs at the bottom of the DATA step. When SAS returns to the top of the DATA step, columns read from the input table are retained and computed columns are set to missing.
True/False - The DATA step debugger in SAS Enterprise Guide can be used with DATA and PROC steps.
False - The DATA step debugger in SAS Enterprise Guide works only with DATA steps.