2.5 Flashcards

1
Q

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

A

b) RENAME option in the SET statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

c) Use a LENGTH statement before the SET statement to explicitly define the length of the character columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True/False - In a one-to-many MERGE, values read from the tables in the MERGE statement are automatically retained for each BY group.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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;

A

c) if inUpdate=1 and inTeachers=1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

b) Use the RENAME option in the MERGE step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True/False - Merging three or more tables without a common column can be done in one DATA step.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which is the simplest option if you want to create multiple tables including matches and non-matches

a) DATA step
b) PROC SQL

A

a) This can be accomplished in a single DATA step when PROC SQL would require multiple queries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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));

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

d) There will be two rows for Bob and three rows for Sue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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
A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

b) The two tables are not sorted by ID, so the step produces an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which statement best describes the rows in the output table?

data bonuses;
merge managers(in=M)
staff(in=S);
by EmpID;
if M=0 and S=1;
run;
a) all the matching rows from both managers and staff
b) only the rows from managers that have no match in staff
c) only the rows from staff that have no match in managers
d) all the matching and nonmatching rows from both managers and staff

A

c) S=1 specifies that the staff table must contribute to the row, and M=0 specifies that the managers table must not contribute to the row.

17
Q

What are the values of C and A during the third iteration of the DATA step?

work.clients
Name	ID
Ankerton	11123
Davis	22298
Masters	33351
work.amounts
Name	Amt
Ankerton	92
Ankerton	43
Masters	27
data client_amount;
    merge clients(in=C) 
          amounts(in=A);
    by Name;
run;
 a)  C=0 and A=0
 b)  C=1 and A=0
 c)  C=0 and A=1
 d)  C=1 and A=1
A

b) The third iteration is for the nonmatch of Davis. Davis is in the clients table (C=1) and not the amounts table (A=0).

18
Q

What is the value of Location in the output table?

loc1
Code	Location
A	France
loc2
Code	Location
A	Belgium
loc3
Code	Location
A	Italy
data locALL;
    merge loc1 loc2 loc3;
    by Code;
run;
 a)  Italy
 b)  France
 c)  Belgium
 d)  France Belgium Italy
A

a) The value of Location is based on the last table read. The loc3 table has a value of Italy for Location.

19
Q

True/False - The DATA step can be used to merge the following three tables:

dataset1
Student	Test	Score
dataset2
Subject	Test
dataset3
Subject	AvgScore
A

False - Two DATA steps are needed. In the first DATA step, dataset1 and dataset2 can be merged by Test. In the second DATA step, dataset3 can be merged with the result of the first DATA step by Subject.