SAS Chapter 15: Combining Data Horizontally

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Moxleyv
M
Moxleyv
Community Contributor
Quizzes Created: 38 | Total Attempts: 21,441
Questions: 10 | Attempts: 162

SettingsSettingsSettings
SAS Chapter 15: Combining Data Horizontally - Quiz


Practice for the SAS advance certification exam.


Questions and Answers
  • 1. 

    According to the data set descriptions below, which of the variables listed qualify as BY variables for a DATA step match-merge?

    • A.

      Code and IDnum

    • B.

      Manager and Supervisor

    • C.

      Manager and IDnum

    • D.

      There are no variables that are common to both of these data sets.

    Correct Answer
    C. Manager and IDnum
    Explanation
    Remember that common variables might not have the same names. Manager and IDnum are the only two variables listed that match according to type and description. You can use the RENAME= option to rename one of these variables so that they can be used as BY variables in the MERGE statement of the DATA step.

    Rate this question:

  • 2. 

    Suppose you want to merge Dataset1, Dataset2, and Dataset3. Also suppose that Dataset1 and Dataset2 have the common variableStartdate, Dataset2 and Dataset3 have the common variable Instructor, and that these data sets have no other common variables. 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 Dataset1, Dataset2, and Dataset3 by Startdate and Instructor.

    • B.

      You sort Dataset1 and Dataset2 by Startdate and merge them into a temporary data set in a DATA step. Then you sort the temporary data set and Dataset3 by Instructor and merge them into a new data set in a DATA step.

    • 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.

    Correct Answer
    B. You sort Dataset1 and Dataset2 by Startdate and merge them into a temporary data set in a DATA step. Then you sort the temporary data set and Dataset3 by Instructor and merge them into a new data set in a DATA step.
    Explanation
    In order to merge multiple data sets in a DATA step, the data sets must have a common variable. However, 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 subsequent DATA steps to merge the data sets. You can also use a PROC SQL step to merge data sets that do not have common variables.

    Rate this question:

  • 3. 

    Which of the following programs correctly creates a table with the results of a PROC SQL inner join matched on the values of empcode?

    • A.

      proc sql; select newsals.empcode allemps.lastname newsals.salary contrib.amount from sasuser.allemps, sasuser.contrib, sasuser.newsals where empcode=allemps.empid and empcode=contrib.empid; quit;

    • B.

      proc sql; create table usesql as select newsals.empcode allemps.lastname newsals.salsry contrib.amount from sasuser.allemps, sasuser.contrib, sasuser.newsals quit;

    • C.

      proc sql; create table usesql as; select newsals.empcode, allemps.lastname, newsals.salary, contrib.amount; from sasuser.allemps, sasuser.contrib, sasuser.newsals; where empcode=allemps.empid and empcode=contrib.empid; quit;

    • D.

      proc sql; create table usesql as select newsals.empcode, allemps.lastname, newsals.salary, contrib.amount from sasuser.allemps, sasuser.contrib, sasuser.newsals where empcode=allemps.empid and empcode=contrib.empid; quit;

    Correct Answer
    D. proc sql; create table usesql as select newsals.empcode, allemps.lastname, newsals.salary, contrib.amount from sasuser.allemps, sasuser.contrib, sasuser.newsals where empcode=allemps.empid and empcode=contrib.empid; quit;
    Explanation
    You can use PROC SQL to join data from data sets that do not have a single common variable among them. If you create a new table with the result of an inner join in a PROC SQL step, the resulting data set can be similar or identical to the result of a DATA step match-merge.

    Rate this question:

  • 4. 

    To process a default DATA step match-merge, SAS first reads the descriptor portion of each data set and sets up the PDV and the descriptor portion of the new data set. Which of the following accurately describes the rest of this process?

    • A.

      Next, SAS sequentially match-merges observations and writes the new observation to the PDV, then to the new data set. When the BY value changes in all the input data sets, the PDV is initialized to missing. Missing values for variables, as well as missing values that result from unmatched observations, are written to the new data set.

    • B.

      Next, SAS sequentially match-merges observations and writes the new observation to the PDV, then to the new data set. After each DATA step iteration, the PDV is initialized to missing. Missing values for variables, as well as missing values that result from unmatched observations, are omitted from the new data set.

    • C.

      Next, SAS creates a Cartesian product of all possible combinations of observations and writes them to the PDV, then to the new data set. Then SAS goes through the new data set and eliminates all observations that do not have matching values of the BY variable.

    • D.

      Next, SAS creates a Cartesian product of all possible combinations of observations and writes them to the PDV, then to the new data set. The new data set is then ordered by values of the BY variable.

    Correct Answer
    A. Next, SAS sequentially match-merges observations and writes the new observation to the PDV, then to the new data set. When the BY value changes in all the input data sets, the PDV is initialized to missing. Missing values for variables, as well as missing values that result from unmatched observations, are written to the new data set.
    Explanation
    In a DATA step match-merge, SAS reads observations from the input data sets sequentially and match-merges them with observations from other input data sets. Combined observations are created when SAS writes values from all input data sets to the variables in the PDV. These observations, as well as any observations that contain missing or nonmatched values, are then written to the new data set. A PROC SQL join creates a Cartesian product of matches and then eliminates nonmatching data.

    Rate this question:

  • 5. 

    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 (EOF) marker on either data set (even if there is more data in the other data set).

    • 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 a second SET statement is executed.

    Correct Answer
    C. You can use multiple SET statements in one DATA step only if the data sets in each SET statement have a common variable.
    Explanation
    You can use multiple SET statements in one DATA step to combine observations from several data sets, and the data sets do not need to have a common variable. When you use multiple SET statements, you need to keep in mind the process that SAS uses to combine data from the input data sets. Otherwise, you might achieve unexpected results.

    Rate this question:

  • 6. 

    Select the program that correctly creates a new data set named Sasuser.Summary that contains one observation with summary data created from the Salary variable of the Sasuser.Empdata data set.

    • A.

      proc sum data=sasuser.emdata noprint; output out=sasuser.summary sum=Salarysum; run;

    • B.

      proc means data=sasuser.empdata noprint; var salary; output out=sasuser.summary sum=Salarysum; run;

    • C.

      proc sum data=sasuser.empdata noprint; var salary; output out=sasuser.summary sum=Salarysum; run;

    • D.

      proc means data=sasuser.empdata noprint; output=sasuser.summary sum=Salarysum; run;

    Correct Answer
    B. proc means data=sasuser.empdata noprint; var salary; output out=sasuser.summary sum=Salarysum; run;
    Explanation
    You can use the MEANS procedure to create a new data set that contains a summary statistic. You use the NOPRINT option to suppress the default report and the OUTPUT statement to route the results from the MEANS procedure to a new data set. You use the VAR statement to focus the procedure on one or more specific variables from the input data set.

    Rate this question:

  • 7. 

    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? data sasuser.percent1; if _n_=1 then set sasuser.summary (keep=cargosum); set sasuser.monthsum (keep=salemon revcargo); PctRev=revcargo/cargosum; run;

    • A.

      $1000

    • B.

      $3000

    • C.

      The value is missing.

    • D.

      The value cannot be determined without seeing the data that is in Sasuser.Summary.

    Correct Answer
    A. $1000
    Explanation
    The _N_ variable records how many times the DATA step has iterated. In the example shown above, _N_ is used to ensure that only the first observation is read from Sasuser.Summary. Since the values in the PDV are not reinitialized after each DATA step iteration, this value will be retained as long as the DATA step continues to iterate. Therefore, if the value of Cargosum is $1000 in the first iteration, it will be $1000 in each subsequent iteration as well.

    Rate this question:

  • 8. 

    According to the data set shown, what is the value of Totalrev in the PDV at the end of the fourth iteration of the DATA step?

    • A.

      The value is missing.

    • B.

      $350.00

    • C.

      $520.00

    • D.

      $1100.00

    Correct Answer
    D. $1100.00
    Explanation
    Totalrev is the accumulator variable of the sum statement, which is automatically initialized with a value of 0. If the expression in a sum statement produces a missing value, SAS replaces the missing value with a value of 0. As the DATA step iterates, the sum statement retains the accumulator variable so that it will accumulate a total.

    Rate this question:

  • 9. 

    Which of the following programs correctly uses an index to combine data from two input data sets?

    • A.

      data work.profit; set sasuser.sale2000(keep=routeid flightid date rev1st revbusiness revecon revcargo) key=flightdate; set sasuser.dnunder; Profit=sum(rev1st, revbusiness, revecon, revcargo, -expenses); run;

    • B.

      data work.profit; set sasuser.dnunder; set sasuser.sale2000(keep=routeid flightid date rev1st revbusiness revecon revcargo) key=flightdate; where routeid='0000103'; Profit=sum(rev1st, revbusiness, revecon, revcargo, -expenses); run;

    • C.

      data work.profit; set sasuser.dnunder; set sasuser.sale2000(keep=routeid flightid date rev1st revbusiness revecon revcargo); key=flightdate; Profit=sum(rev1st, revbusiness, revecon, revcargo, -expenses); run;

    • D.

      data work.profit; set sasuser.dnunder; set sasuser.sale2000(keep=routeid flightid date rev1st revbusiness revecon revcargo) key=flightdate; Profit=sum(rev1st, revbusiness, revecon, revcargo, -expenses); run;

    Correct Answer
    D. data work.profit; set sasuser.dnunder; set sasuser.sale2000(keep=routeid flightid date rev1st revbusiness revecon revcargo) key=flightdate; Profit=sum(rev1st, revbusiness, revecon, revcargo, -expenses); run;
    Explanation
    You use the KEY= option in a SET statement to cause SAS to use an index to combine data from multiple data sets. When the SET statement with the KEY= option executes, the program data vector must already contain a value for the indexed variable. You cannot use WHERE processing on a data set that has been read with the KEY= option within the same DATA step.

    Rate this question:

  • 10. 

    Which of the following statements about the _IORC_ variable is false?

    • A.

      It is automatically created when you use either a SET statement with the KEY= option or the MODIFY statement with the KEY= option in a DATA step.

    • B.

      A value of zero for _IORC_ means that the most recent SET statement with the KEY= option (or MODIFY statement with the KEY= option) did not execute successfully.

    • C.

      A value of zero for _IORC_ means that the most recent SET statement with the KEY= option (or MODIFY statement with the KEY= option) executed 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.

    Correct Answer
    B. A value of zero for _IORC_ means that the most recent SET statement with the KEY= option (or MODIFY statement with the KEY= option) did not execute successfully.
    Explanation
    When you use the KEY= option, SAS creates an automatic variable named _IORC_, which stands for INPUT/OUTPUT Return Code. If the value of _IORC_ is zero, the index search was successful. The _IORC_ variable is also created automatically when you use a MODIFY statement in a DATA step.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • May 27, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 01, 2013
    Quiz Created by
    Moxleyv

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.