Multiple choice technology programming languages

You are creating a PROC SQL query that will list all employees who have spent (or overspent) their allotted 120 hours of vacation for the current year. The hours that each employee used are stored in the existing column Spent. Your query defines a new column, Balance, to calculate each employee’s balance of vacation hours. Which query will produce the report that you want?

  1. proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where balance <= 0

  2. proc sql; select name, spent, 120-spent as Balance from Company.Absences where calculated balance <= 0;

  3. proc sql; select name, spent, 120-spent as Balance from Company.Absences where balance <= 0;

  4. proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where calculated balance <= 0;

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When referring to a calculated column in the WHERE clause, you must use the CALCULATED keyword to inform PROC SQL that the column is created in the SELECT clause. Option B correctly defines the Balance column and references it with 'calculated balance' in the WHERE clause. Options A and C fail without CALCULATED, while D redundantly uses it in the SELECT clause.

AI explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where balance &lt;= 0

This option is incorrect because it references a column balance in the where clause, which does not exist in the table.

Option B) proc sql; select name, spent, 120-spent as Balance from Company.Absences where calculated balance &lt;= 0;

This option is correct because it calculates the balance of vacation hours using the expression 120-spent and assigns it to the column Balance. It then filters the records where the calculated balance is less than or equal to zero.

Option C) proc sql; select name, spent, 120-spent as Balance from Company.Absences where balance &lt;= 0;

This option is incorrect because it references a column balance in the where clause, which does not exist in the table.

Option D) proc sql; select name, spent, 120-spent as calculated Balance from Company.Absences where calculated balance &lt;= 0;

This option is incorrect because it references a column calculated balance in the where clause, which is not defined in the select statement.

The correct answer is Option B. This option correctly calculates the balance of vacation hours and filters the records where the calculated balance is less than or equal to zero.