## SAS Base (57)

Given the SAS data set WORK.ONE:

 N BeginDate 1 09JAN201 2 12JAN201

The following SAS program is submitted:

data WORK.TWO;
set WORK.ONE;
Day=<_insert_code_>;
format BeginDate date9.;
run;

The data set WORK.TWO is created, where Day would be 1 for Sunday, 2 for Monday, 3 for Tuesday, … :

 N BeginDate Day 1 09JAN2010 7 2 12JAN2010 3

Which expression successfully completed the program and creates the variable Day?

A. day(BeginDate)
B. weekday(BeginDate)
C. dayofweek(BeginDate)
D. getday(BeginDate,today())

## SAS Base (56)

The following output is created by the FREQUENCY procedure:

 Frequency Percent Row Pct Col Pct
Table of Region by Product
Region Product
Corn Cotton Oranges Total
East
 2 22.22 50 50
 1 11.11 25 33.33
 1 11.11 25 50
 4 44.44
South
 2 22.22 40 50
 2 22.22 40 66.67
 1 11.11 20 50
 5 55.56
Total
 4 44.44
 3 33.33
 2 22.22
 9 100

Which TABLES statement was used to completed the following program
that produced the output?

proc freq data=sales;
<_insert_code_>
run;

A. tables region product;
B. tables region,product;
C. tables region/product;
D. tables region*product;

 Region Frequency Percent Cumulative Frequency Cumulative Percent East 4 44.44 4 44.44 South 5 55.56 9 100.00
 Product Frequency Percent Cumulative Frequency Cumulative Percent Corn 4 44.44 4 44.44 Cotton 3 33.33 7 77.78 Oranges 2 22.22 9 100.00

## SAS Base (55)

The following SAS program is submitted:

data WORK.DATE_INFO;
X=”01Jan1960″D ;
run;

Variable X contains what value?

A. the numeric value 0
B. the character value “01Jan1960”
C. the date value 01011960
D. the code contains a syntax error and does not execute.

This question has another version. A space is placed between the closing quotation mark and letter D. This will cause a compile error and the answer would be D.

## SAS Base (54)

Consider the following data step:

data WORK.TEST;
set SASHELP.CLASS(obs=5);
retain City ‘Beverly Hills’;
State=’California’;
run;

The computed variables City and State have their values assigned using two different methods, a RETAIN statement and an Assignment statement. Which statement regarding this program is true?

A. The RETAIN statement is fine, but the value of City will be truncated to 8 bytes as the LENGTH statement has been omitted.
B. Both the RETAIN and assignment statement are being used to initialize new variables and are equally efficient. Method used is a matter of programmer preference.
C. The assignment statement is fine, but the value of City will be truncated to 8 bytes as the LENGTH statement has been omitted.
D. City’s value will be assigned one time, State’s value 5 times.

1. As RETAIN statement assigns the value at compile time, the code will be executed once and only once. Assignment statement, however, respecifies the value in every iteration.
2. SAS automatically sets variables that are assigned values by an assignment statement to missing before each iteration of the DATA step. On the contrary, RETAIN statement retains the value from one iteration to the next.

AS this program reads the first 5 observations (5 iterations) in CLASS data set,  the value of State is specified 5 times, and the variable is reset to missing when SAS begins to read the next observation. City is initialized as ‘Beverly Hills’ before DATA step and won’t be reset to missing.

## SAS Base (53)

The following SAS program is submitted:

data WORK.TOTAL_SALARY;
retain Total;
set WORK.SALARY;
by Department;
if First.Department
then Total=0;
Total=sum(Total, Wagerate);
if Last.Total;
run;

What is the initial value of the variable Total?

A. 0
B. Missing
C. The value of the first observations Wagerate
D. Cannot be determined from the information given

## SAS Base (52)

Given the SAS data set WORK.EMP_NAME:

 Name EmpID Jill 1864 Jack 2121 Joan 4698 John 5463

Given the SAS data set WORK.EMP_DEPT:

 EmpID Department 2121 Accounti 3567 Finance 4698 Marketin 5463 Accounti

The following program is submitted:

data WORK.ALL;
merge WORK.EMP_NAME(in=Emp_N)
WORK.EMP_DEPT(in=Emp_D);
by Empid;
if (Emp_N and not Emp_D) or (Emp_D and not Emp_N);
run;

How many observations are in data set WORK.ALL after submitting the program?

A. 1
B. 2
C. 3
D. 5

 Obs Name EmpID Department 1 Jill 1864 2 3567 Finance

For the details of MERGE statement and IN option, please check SAS Base (28).

## SAS Base (51)

The following program is submitted:

proc contents data=_all_;
run;

Which statement best describes the output from the submitted program?

A. The output contains only a list of the SAS data sets that are contained in the WORK library.
B. The output displays only the contents of the SAS data sets that are contained in the WORK library.
C. The output displays only the variables in the SAS data sets that are contained in the WORK library.
D. The output contains a list of the SAS data sets that are contained in the WORK library and displays the contents of those data sets.

## SAS Base (50)

Given the SAS data set WORK.ONE:

 Id Char1 111 A 158 B 329 C 644 D

and the SAS data set WORK.TWO:

 Id Char2 111 E 538 F 644 G

The following program is submitted:

data WORK.BOTH;
set WORK.ONE WORK.TWO;
by Id;
run;

What is the first observation in SAS data set WORK.BOTH?

A.

 Id Char1 Char2 111 A

B.

 Id Char1 Char2 111 E

C.

 Id Char1 Char2 111 A E

D.

 Id Char1 Char2 644 D G

 Obs Id Char1 Char2 1 111 A 2 111 E 3 158 B 4 329 C 5 538 F 6 644 D 7 644 G

## SAS Base (49)

The following SAS program is submitted:

data WORK.TOTALSALES(keep=MonthSales{12});
set WORK.MONTHLYSALES(keep=Year Product Sales);
array MonthSales{12};
do i=1 to 12;
MonthSales{i}=Sales;
end;
drop i;
run;

The program fails execution due to syntax errors.
What is the cause of the syntax error?
A. An array cannot be referenced on a keep= data set option.
B. The keep= data set option should be (keep=MonthSales*).
C. The keep= data set option should be the statement KEEP MonthSales{12}.
D. The variable MonthSales does not exist.