Académique Documents
Professionnel Documents
Culture Documents
data work.total;
set work.salary(keep = department wagerate);
by department;
if first.department then payroll = 0;
payroll + wagerate;
if last.department;
run;
The SAS data set named WORK.SALARY contains 10 observations for each
department, currently ordered by DEPARTMENT.
Which one of the following is true regarding the program above?
A. The BY statement in the DATA step causes a syntax error.
B. FIRST.DEPARTMENT & LAST.DEPARTMENT are variables in WORK.TOTAL
dataset.
C. The values of the variable PAYROLL represent the total for each department in the
WORK.SALARY data set.
D. The values of the variable PAYROLL represent a total for all values of
WAGERATE in the WORK.SALARY data set.
Answer: C. For every BY group we get the sum of wagerate in the Payroll variable
for each department.
Q3. The contents of the raw data file NAMENUM are listed below:
--------10-------20-------30
Joe xx
The following SAS program is submitted:
data test;
infile 'namenum';
input name $ number;
run;
Which one of the following is the value of the NUMBER variable?
A. xx
B. Joe
C. . (missing numeric value)
D. The value can not be determined as the program fails to execute due to errors.
Answer : C. It is because number is defined as a numeric variable so it is expecting
a numeric value but it reads xx, so number will be a missing value.
Q4. How many of the following variable names will not produce errors in an
assignment statement?
variable
var
1variable
var1
#var
_variable#
A. 0
B. 1
C. 3
D. 6
Answer : C ; variable var var1. A variable cannot start with numeric or special
characters except _. You also cannot use special characters anywhere in the name
either though numeric values are allowed.
Q5. Suppose the variable 'Unit_Cost_Price' (numeric) contains both missing and non
missing values. What would the following code return?
proc sort data=ecsql1.price_list;
by Unit_Cost_Price;
run;
Q7. Which of the following is a valid statement about the VALUE range in the PROC
FORMAT procedure? It cannot be...
A. A single character or numeric value
B. A range of character values
C. A list of unique values separated by commas
D. A combination of character and numeric values
Answer : D.
Q8. How many of the following statistics that PROC MEANS computes as default
statistics?
Standard deviation
Range
Count
Minimum value
Variance
Mode
A. 2
B. 3
C. 4
D. None of the above
Answer : B. By default, PROC MEANS calculates count, mean, standard deviation,
minimum and maximum value.
Q15. Which one of the following statements is true regarding the name of a SAS
array?
A. It is saved with the data set.
B. It can be used in procedures.
C. It exists only for the duration of the DATA step.
D. It can be the same as the name of a variable in the data set.
Answer : C.
Q16. The SASDATA.BANKS data set has five observations when the following SAS
program is submitted:
libname sasdata 'SAS-data-library';
data allobs;
set sasdata.banks;
capital=0;
do year = 2000 to 2020 by 5;
capital + ((capital+2000) * rate);
output;
end;
run;
How many observations will the ALLOBS data set contain?
A. 5
B. 15
C. 20
D. 25
Answer : D. Banks has 5 observations and then the do loop outputs for (20/5 + 1)
times. Therefore 5*(20/5 + 1) = 25 is the observation count .
Q17. The following SAS SORT procedure step generates an output data set:
proc sort data = sasuser.houses out = report;
by style;
run;
In which library is the output data set stored?
A.WORK
B.REPORT.
C.HOUSES
D.SASUSER
Answer : A. If library name is not specified then the data will be stored in temporary
dataset i.e. WORK.
Which one of the following SAS programs created this data set?
A.
data work.test;
capacity = 150;
if 100 le capacity le 200 then
airplanetype = 'Large' and staff = 10;
else airplanetype = 'Small' and staff = 5;
run;
B.
data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
end;
else
do;
airplanetype = 'Small';
staff = 5;
end;
run;
C.
data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
else
do;
airplanetype = 'Small';
staff = 5;
end;
run;
D.
data work.test;
capacity = 150;
if 100 le capacity le 200 then;
airplanetype = 'Small';
staff = 5;
else;
airplanetype = 'Large';
staff = 10;
run;
Answer : B. The problem with the options A,C and D is highlighted below in bold.
A. data work.test;
capacity = 150;
if 100 le capacity le 200 then
airplanetype = 'Large' and staff = 10;
else airplanetype = 'Small' and staff = 5;
run;
Log : NOTE: Variable staff is uninitialized.
C. data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
else /*end missing for if do loop*/
do;
airplanetype = 'Small';
staff = 5;
end;
run;
Log : ERROR 117-185: There was 1 unclosed DO block.
NOTE: The SAS System stopped processing this step because of errors.
D. data work.test;
capacity = 150;
if 100 le capacity le 200 then;
airplanetype = 'Small';
staff = 5;
else; /* there is no if associated with this else */
airplanetype = 'Large';
staff = 10;
run;
Log : ERROR 160-185: No matching IF-THEN clause
destination = 'CPH';
select(destination);
when('LHR') city = 'London';
when('CPH') city = 'Copenhagen';
otherwise;
end;
run;
Which one of the following is the value of the CITY variable?
A. London
B. Copenh
C. Copenhagen
D. ' ' (missing character value)
Answer : B.
Notice that the LENGTH statement in the SELECT group has not been specified.
Remember that without the LENGTH statement, values for Group might be
truncated, as the first value for Group (London) is not the longest possible value.
city = 'London' - It contains 6 characters.
'Copenhagen' will be truncated to 6 characters i..e Copenh.
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.
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.
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.
Q27. 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.
Answer : C.
Q28. 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.
Q30. 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
Answer : B.
A. rawdata1
B. rawdata2
C. 'rawdata1'
D. 'rawdata2'
Answer: B. Since we have already initialized the path with a filename, we do not
have to include quotation again.
Q32. The following SAS program is submitted and reads 100 records from a raw data
file:
data work.total;
infile 'file-specification' end = eof;
input name $ salary;
totsal + salary;
run;
Which one of the following IF statements writes the last observation to the output
data set?
A. if end = 0;
B. if eof = 0;
C. if end = 1;
D. if eof = 1;
Answer : D. End is a sas keyword which will become true when SAS reads last
record of a dataset. This value you cannot use directly in your program, so we create
a alias name eof (end of file), but you can name it anything. EOF will carry the same
value as internal variable END. So as we know 1=true and 0= false. if EOF = 1; will
output only the last observation.
Q33. In the following SAS program, the input data files are sorted by the NAMES
variable:
libname temp 'SAS-data-library';
data temp.sales;
merge temp.sales work.receipt;
by names;
run;
Which one of the following results occurs when this program is submitted?
A. The program executes successfully and a temporary SAS data set is created.
B. The program executes successfully and a permanent SAS data set is created.
C. The program fails execution because the same SAS data set is referenced for
both read and write operations.
D. The program fails execution because the SAS data sets on the MERGE statement
are in two different libraries.
data emplsal;
merge employee (in=ine) salary(in=ins);
by name;
if ine and ins;
run;
How many observation are in EMPLSAL dataset?
A. 4
B. 3
c. 2
D. 1
Answer : A.
Run the following SAS code and see what you got in the EMPSAL dataset:
data salary;
input name $ salary;
datalines;
Bruce 40000
Bruce 35000
Dan 37000
Dan .
;
run;
data employee;
input name $ age;
datalines;
Bruce 30
Dan 35
;
run;
data emplsal;
Q37. Which one of the following is true of the RETAIN statement in a SAS DATA step
program?
A. It can be used to assign an initial value to _N_ .
B. It is only valid in conjunction with a SUM function.
C. It has no effect on variables read with the SET, MERGE and UPDATE statements.
D. It adds the value of an expression to an accumulator variable and ignores missing
values.
Answer : C.
The RETAIN statement
- is a compile-time only statement that creates variables if they do not already exist
- initializes the retained variable to missing before the first execution of the DATA step
if you do not supply an initial value
- has no effect on variables that are read with SET, MERGE, or UPDATE statements.
Q39. Which one of the following is true when SAS encounters a data error in a DATA
step?
A. The DATA step stops executing at the point of the error, and no SAS data set is
created.
B. A note is written to the SAS log explaining the error, and the DATA step continues
to execute.
C. A note appears in the SAS log that the incorrect data record was saved to a
separate SAS file for further examination.
D. The DATA step stops executing at the point of the error, and the resulting DATA set
contains observations up to that point.
Answer : B. If it's a syntax error then the A occurs.
If it's an error with invalid data then B will occur .
If it's a problem with merging two or more datasets, then D will occur.
IDNumber Expenses
2542 100.00
3612 133.15
2198 234.34
2198 111.12
The following SAS program is submitted:
proc sort data = employee_info;
run;
Which one of the following BY statements completes the program and sorts the data
sequentially by ascending expense values within each ascending IDNUMBER value?
A. by Expenses IDNumber;
B. by IDNumber Expenses;
C. by ascending (IDNumber Expenses);
D. by ascending IDNumber ascending Expenses;
Answer : B. By default SAS will sort data in ascending order. IDNumber should be
specified before Expenses as we want IDNUMBER to be sorted in ascending.
((Delimiter mentioned "," is wrong. It should be " " to get "Of".
1.
2.