Base SAS Certification Questions and Answers Part – 3

21. The following SAS program is submitted:

data work.one;
x = 3;
y = 2;
z = x ** y;
run;

Which one of the following is the value of the variable Z in the output data set?

A. 6
B. 9
C. . (missing numeric value)
D. The program fails to execute due to errors.

** = exponentiation
X**Y raise X to the power of Y
So 3 to the power of 2 = 9

22. The following SAS program is submitted:

data work.new;
length word \$7;
amount = 7;
if amount = 5 then word = ‘CAT’;
else if amount = 7 then word = ‘DOG’;
else word = ‘NONE!!!’;
amount = 5;
run;

Which one of the following represents the values of the AMOUNT and WORD variables?

A. amount word
5 DOG

B. amount word
5 CAT

C. amount word
7 DOG

D. amount word
7 ‘ ‘ (missing character value)

Answer : A. When SAS reads in the iterations in sequence, it first writes 7 to the variable ‘amount’ in PDV. Then it reads through the condition and writes ‘DOG’ for variable ‘word’ in PDV. Then it again encounters the value 5 and writes to ‘Amount’ in PDV.

23. The following SAS program is submitted:

data _null_;
set old;
put sales1 sales2;
run;
Where is the output written?

A. the SAS log
B. the raw data file that was opened last
C. the SAS output window or an output file
D. the data set mentioned in the DATA statement

24. The following SAS program is submitted:

data work.report;
set work.sales_info;
if qtr(sales_date) ge 3;
run;

The SAS data set WORK.SALES_INFO has one observation for each month in the year 2000 and the variable SALES_DATE which contains a SAS date value for each of the twelve months.

How many of the original twelve observations in WORK.SALES_INFO are written to the WORK.REPORT data set?

Answer : C. The qtr (quarter) values of each of the months (July through December) 7,8,9,10,11,12 is 3,3,3,4,4,4..Therefore 6 obs are included in the final dataset.

25. The following SAS DATA step is submitted:

data sasdata.atlanta sasdata.boston work.portland work.phoenix;
set company.prdsales;
if region = ‘NE’ then output boston;
if region = ‘SE’ then output atlanta;
if region = ‘SW’ then output phoenix;
if region = ‘NW’ then output portland;
run;

Which one of the following is true regarding the output data sets?

A. No library references are required.
B. The data sets listed on all the IF statements require a library reference.
C. The data sets listed in the last two IF statements require a library reference.
D. The data sets listed in the first two IF statements require a library reference.

Answer : D. The datasets in the first two IF statements require “sasdata” libref.

26. The following SAS program is submitted:

proc sort data=work.employee;
by descending fname;

proc sort data=work.salary;
by descending fname;

data work.empdata;
merge work.employee work.salary;
by fname;
run;

Which one of the following statements explains why the program failed execution?

A. The SORT procedures contain invalid syntax.
B. The merged data sets are not permanent SAS data sets.
C. The data sets were not merged in the order by which they were sorted.
D. The RUN statements were omitted after each of the SORT procedures.

Answer : C. The two proc sorts are arranged in descending order. However, the merge is in ascending order. Hence, the two data sets won’t be merged.

In merge if you choose to sort by descending then you must use descending with merge statement otherwise it will not merge because of reason ( C ). It does not matter if you sort by ascending order.

27. Which one of the following is true of the SUM statement in a SAS DATA step program?

A. It is only valid in conjunction with a SUM function.
B. It is not valid with the SET, MERGE and UPDATE statements.
C. It adds the value of an expression to an accumulator variable and ignores missing values.
D. It does not retain the accumulator variable value from one iteration of the SAS DATA step to the next.

28. The SAS data sets WORK.EMPLOYEE and WORK.SALARY are listed below:

WORK.EMPLOYEE
fname age
Bruce 30
Dan 40
Dan 25000

WORK.SALARY
fname salary
Bruce 25000
Bruce 35000

The following SAS program is submitted:

data work.empdata;
merge work.employee work.salary;
by fname;
totsal + salary;
run;

How many variables are output to the WORK.EMPDATA data set?

A. 3
B. 4
C. 5
D. No variables are output to the data set as the program fails to execute due to errors.

Answer : B. The variables are: Fname, age, salary and totsal.
Note: Obs will not be counted here.

29. The following SAS program is submitted:

data work.sets;
do until (prod gt 6);
prod + 1;
end;
run;

Which one of the following is the value of the variable PROD in the output data set?

A. 5
B. 6
C. 7
D. 8

Answer : C. Because of prod + 1 statement, SAS compiler will assume a retain prod 0; statement.

First loop => prod = 1 => (1 gt 6) => false, loop continues
Second loop => prod = 2 => (2 gt 6) => false, loop continues
…..
last loop => prod = 7 => (7 gt 6) => true, do until loop exits and pdv writes prod value of 7 to output dataset.

30. Which of the following is not an error identified during the compilation phase?

A. Quotation marks are unbalances
B. No RUN statement in the step
C. An option is invalid
D. Semicolons are missing in statements