2.5 Flashcards
What is needed to successfully concatenate two SAS tables where the column names are different for the “same” column?
a) REPLACE function in the SET statement
b) RENAME option in the SET statement
c) RENAME option in the DATA statement
d) DROP function
b) RENAME option in the SET statement
When concatenating tables, how can you prevent character fields in the tables listed after the first from being unintentionally truncated?
a) Use a FORMAT statement to specify the length of the character fields
b) Use an INFORMAT statement to specify the length of the character fields
c) Use a LENGTH statement before the SET statement to explicitly define the length of the character columns
d) Use a PUT statement to set the appropriate length
c) Use a LENGTH statement before the SET statement to explicitly define the length of the character columns
Which of the following are true regarding the SAS MERGE statement?
a) The MERGE statement replaces the SET statement
b) You can only list two tables in the MERGE statement
c) The tables must be sorted by the columns listed in the BY statement
d) In the compilation phase, all of the columns from the first table listed on the MERGE statement and their attributes are added to the PDV. SAS then examines the second table on the MERGE statement.
a, b, d
b - You can list multiple tables on the MERGE statement, as long as each table has the common matching column that is listed on the BY statement.
True/False - In a one-to-many MERGE, values read from the tables in the MERGE statement are automatically retained for each BY group.
True
How would SAS handle a MERGE where there are two tables with the same number of rows, however, one row in each table doesn’t have match on the BY column to the other?
a) Only the row in the first table will be output
b) Only the row in the second table will be output
c) Both rows will be output
d) Neither row will be output
c) Both rows will be output, the columns that appear in both tables will be output. The rest of the columns remain as missing when the row is written to the output table.
Which statement writes only matching rows to the output table?
data class2; merge pg2.class_update(in=inUpdate) pg2.class_teachers(in=inTeachers); by name; ???; run;
a) where inUpdate=1 and inTeachers=1;
b) where inUpdate=1 or inTeachers=1;
c) if inUpdate=1 and inTeachers=1;
d) if inUpdate=1 or inTeachers=1;
c) if inUpdate=1 and inTeachers=1;
If you are merging two tables with the same column names, however, you want the columns in each to be retained in the output table, what do you need to do?
a) Use the RENAME option in the data step
b) Use the RENAME option in the MERGE step
c) By default SAS will add a 1 to the column with the same name that’s read into the PDV second
b) Use the RENAME option in the MERGE step.
True/False - Merging three or more tables without a common column can be done in one DATA step.
False - This would require multiple DATA steps and assumes that there is at least one matching column per pair of tables. This is more easily accomplished with PROC SQL.
Which is the simplest option if you want to create multiple tables including matches and non-matches
a) DATA step
b) PROC SQL
a) This can be accomplished in a single DATA step when PROC SQL would require multiple queries.
Which statement is true concerning concatenating tables?
a) All tables must have the same number of columns.
b) Columns in all tables must have matching names and lengths.
c) Tables must be in the same library.
d) Missing values are generated for columns that exist in one input table and not in another.
d) Missing values are generated for columns that exist in one input table and not in another.
Tables with different columns can be concatenated, but missing values are generated for columns that exist in one input table and not in another.
Which statement renames the existing column Location in work.travel as Destination?
a) set vacations(rename=(Location=Destination)) travel;
b) set vacations travel(rename=(Destination=Location));
c) set vacations travel(rename=(Location=Destination));
d) set vacations travel(rename(Destination=Location));
c) set vacations travel(rename=(Location=Destination));
Parentheses surround all data set options, and another set of parentheses surrounds the columns listed for the RENAME= data set option.
Which statement is true concerning merging with matching rows?
a) The MERGE statement must refer to temporary input tables.
b) The columns in the BY statement can be in only one of the tables.
c) Only two input tables can be specified in the MERGE statement.
d) The input tables must be sorted by the columns in the BY statement.
d) The input tables must be sorted by the columns in the BY statement.
With match-merging, each input table must first be sorted on the values of the BY columns or have an appropriate index.
How many rows are in the both output table given the following input tables and code?
work.agetable
Name Age
Bob 12
Sue 15
work.foodtable Name Food Bob Pizza Bob Cupcakes Sue Burgers Sue Grapes Sue Brownies
data both; merge agetable foodtable; by Name; run;
a) two
b) three
c) four
d) five
d) There will be two rows for Bob and three rows for Sue.
How many rows are in the empsauc output table given the following input tables and code?
work.empsau First Region EmpID Togar E 121150 Kylie S 121151 Birin W 121152 work.phonec EmpID Phone 121150 +61(2)5555-1795 121152 +61(2)5555-1667 121153 +61(2)5555-1348
data empsauc; merge empsau phonec; by EmpID; run; a) two b) three c) four d) five
c) There will be a matching row for 121150, a nonmatching row for 121151, a matching row for 121152, and a nonmatching row for 121153.
What is the result of the following step?
work.donors1 ID Type Units 2304 O 16 1129 A 48 1129 A 50 2486 B 63 work.donors2 ID Code Units 1129 63 32 2304 61 45 1387 64 67
data combine;
merge donors1 donors2;
by ID;
run;
a) The table combine is created with four columns and five rows.
b) The step fails because the BY column ID is not properly sorted.
c) The step fails because Units is in both tables and not the BY column.
d) The step fails because of duplicate ID values within the donors1 table.
b) The two tables are not sorted by ID, so the step produces an error.