SAS Practice Exam Flashcards
Which statement about SAS libraries is true?
Select one: A. You refer to a SAS library by a logical name called a libname.
B. A SAS library is a collection of one or more SAS files that are referenced and stored as a unit.
C. A single SAS library must contain files that are stored in different physical locations.
D. At the end of each session, SAS deletes the contents of all SAS libraries.
B By definition, a SAS Library is a collection of one or more SAS files that are referenced and stored as a unit. The correct answer is: A SAS library is a collection of one or more SAS files that are referenced and stored as a unit.
Assume that Sasuser.One does not exist and that the following SAS program is submitted at the beginning of a new SAS session:
data sasuser.one;
x=1;
y=27;
output one;
run;
A. The data set Sasuser.One is created with 2 variables and 3 observations
B. The data set Sasuser.One is created with 2 variables and 0 observations
C. The DATA step does not execute
D. The data set Sasuser.One is created with 2 variables and 1 observation
The OUTPUT statement is told to use Work.One, but it is not a data set that is specified on the DATA statement. This generates a syntax error and stops the execution of the DATA step. At compile time, a data set Sasuser.One with 2 variables and 0 observations would be created, but only if it did not already exist. A pre-existing Sasuser.One would not be affected by this DATA step. The correct answer is: The data set Sasuser.One is created with 2 variables and 0 observations
This question will ask you to provide a line of missing code. The following SAS program is submitted: libname myxlsx xlsx ‘C:\data\sales.xlsx’; proc print data = myxlsx.qtr1; run; In the space below, write the statement that will remove the library reference MYXLSX from the Excel Workbook sales.xlsx?
There are two acceptable variations on the statement. First, using explicit clear: libname myxlsx clear; Second, omitting the clear is also acceptable syntax: libname myxlsx; Either answer would be recognized as correct. If you got this question wrong because of differences in spacing, please know that the actual exam is more accommodating of such differences. On the actual exam, so long as your syntax would be accepted by SAS as valid, it will be marked correct. The correct answer is: libname myxlsx clear;
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 the SAS data set WORK.BOTH? Select one:
A. Id Char1 Char2 — —– —– 111 E
B. Id Char1 Char2 — —– —– 111 A
C. Id Char1 Char2 — —– —– 111 A E
D. Id Char1 Char2 — —– —– 644 D G
The correct answer is B. The set statement is reading sequentially by groups through WORK.ONE and then WORK.TWO. This is NOT a Merge. The first record is A and the second record is B. If you got this question wrong because of differences in spacing, please know that the actual exam is more accommodating of such differences. On the actual exam, so long as your syntax would be accepted by SAS as valid, it will be marked correct. The correct answer is: Id Char1 Char2 — —– —– 111 A
The variable Name in the data set Employee has a $CHAR10. format. The variable Name in the data set Sales has a $CHAR15. format. The following SAS program is submitted: data both; merge employee sales; by name; run; What is the format for the variable Name in the data set Both? Select one:
A. no format defined
B. $CHAR
C. $CHAR10
D. $CHAR15
The first attribute seen for a variable is the one used in the current DATA step. Given that the Work.Employee data set is positioned first on the MERGE statement, the variable Name would have a format of $CHAR10. In the new data set Work.Both. The correct answer is: $CHAR10
Given the following SAS data set WORK.CLASS:
Name Gender Age
Anna F 23
Ben M 25
Bob M 21
Brian M 27
Edward M 26
Emma F 32
Joe M 34
Sam F 32
Tom M 24
The following program is submitted:
data WORK.MALES WORK.FEMALES(drop=age);
set WORK.CLASS;
drop gender;
if Gender=”M” then output WORK.MALES;
else if Gender=”F” then output WORK.FEMALES;
run;
How many variables are in the data set WORK.MALES? Select one:
A. The program does not execute due to a syntax error.
B. 1
C. 2
D. 3
The (drop=age) data set option only applies to the preceding data set, WORK.FEMALES. the drop gender statement applies to both output data sets. WORK.MALES will be left with only the NAME and AGE variables. The correct answer is: 2
Given the following SAS data set WORK.TOYS:
Product Group Price ——— ———– —–
Cards Indoors 9.99
Marbles Indoors 8.99
Drum Instruments 12.99
Hula-Hoop Outdoors 12.99
Ball Outdoors 8.49
The following SAS program is submitted:
data WORK.GROUPS;
set WORK.TOYS;
if Group=”Outdoors” then Price_Gp=”C”;
if Price ge 12.99 then Price_Gp=”A”;
else if Price ge 8.99 then Price_Gp=”B”;
run;
What will be the value of Price_Gp for Hula-Hoop and Ball? Select one:
A. Hula-Hoop: ‘A’, Ball: ‘ ‘ (missing value)
B. Hula-Hoop: ‘A’, Ball: ‘C’
C. Hula-Hoop: ‘C’, Ball: ‘ ‘ (missing value)
D. Hula-Hoop: ‘C’, Ball: ‘C’
The correct answer is B. For the Product Hula-Hoop, the first ‘IF’ statement set Price_Gp to ‘C’ as the value of Group is ‘Outdoor’. The second ‘IF’ statement sets Price_Gp to ‘A’ as the Price is 12.99 and ‘Else” statement is not executed. For the Product Ball, the first ‘IF’ statement set Price_Gp to ‘C’ as the value of Group is ‘Outdoor’. The second ‘IF’ statement is false and ‘Else’…‘IF’ is also false. The correct answer is: Hula-Hoop: ‘A’, Ball: ‘C’
Which of the following SAS programs creates a variable named City with a value of Chicago? Select one:
A. data work.airport; AirportCode=’ord’; if (AirportCode=’ord’) City=’Chicago’; run;
B. data work.airport; AirportCode=’ORD’; if AirportCode=’ORD’ then City=Chicago; run;
C. data work.airport; AirportCode=’ORD’; if AirportCode=’ORD’; then City=’Chicago’; run;
D. data work.airport; AirportCode=’ORD’; if AirportCode=’ORD’ then City=’Chicago’; run;
The assignment City=’Chicago’ creates a variable named City with a value of Chicago. A subsetting IF cannot include an assignment; a THEN outside of the IF statement is not allowed; and the assignment City=Chicago involves two variables. The correct answer is: data work.airport; AirportCode=’ORD’; if AirportCode=’ORD’ then City=’Chicago’; run;
The variable Name in the data set Employee has a $CHAR10. format. The variable Name in the data set Sales has a $CHAR15. format. The following SAS program is submitted: data both; length name $ 20; merge sales employee; by id; run; What is the format for the variable Name in the data set Both? Select one:
A. $20
B. $CHAR10
C. $CHAR15
D. $CHAR20
The first attribute seen for a variable is the one used in the current data step. Given that the Work.Sales data set is positioned first on the MERGE statement, the variable Name would have a format of $CHAR15. in the new data set Work.Both. The LENGTH statement only gives the variable Name a predefined maximum length. The correct answer is: $CHAR15
Given the SAS data set WORK.ONE:
X Y Z
1 A 27
1 A 33
1 B 45
2 A 52
2 B 69
3 B 70
4 A 82
4 C 91
The following SAS program is submitted:
data WORK.TWO;
set WORK.ONE;
by X Y;
if First.Y;
run;
proc print data=WORK.TWO noobs;
run;
Which report is produced? Select one:
A. X Y Z – – – 1 B 45 2 A 52 2 B 69 3 B 70 4 A 82 4 C 91
B. X Y Z – – – 1 A 27 1 B 45 2 A 52 2 B 69 3 B 70 4 A 82 4 C 91
C. X Y Z – – – 1 A 33 1 B 45 2 A 52 2 B 69 3 B 70 4 A 82 4 C 91
D. X Y Z – – – 1 A 27 1 B 45 2 A 52 2 B 69 4 A 82 4 C 91
The output data set is dependent upon the sub-setting if statement being TRUE. The first . temporary variable has a value of 1 when it is the first variable within the group. Therefore, the first. y will have a value of 1 when it is the first value of y within the value of X. The correct answer is:
X Y Z – – –
1 A 27
1 B 45
2 A 52
2 B 69
3 B 70
4 A 82
4 C 91
The SAS data set named WORK.SALARY contains 10 observations for each department, and is currently ordered by Department. The following SAS program is submitted:
data WORK.TOTAL;
set WORK.SALARY(keep=Department MonthlyWageRate);
by Department;
if First.Department=1 then Payroll=0;
Payroll+(MonthlyWageRate*12);
if Last.Department=1;
run;
Which statement is true? Select one:
A. The BY statement in the DATA step causes a syntax error.
B. The statement Payroll+(MonthlyWageRate*12); in the data step causes a syntax error.
C. The values of the variable Payroll represent the annual total for each department in the WORK.SALARY data set.
D. The values of the variable Payroll represent an annual total for all values of MonthlyWageRate in the WORK.SALARY data set.
The correct answer is C. A is not correct because the BY statement is used correctly in the data step. B is not correct because the SUM type statement as written is syntactically correct. D is not correct as the observations are being processed by groups by departments. The correct answer is: The values of the variable Payroll represent the annual total for each department in the WORK.SALARY data set.
The following SAS program is submitted:
data WORK.NEW;
year=2011;
amount=5000;
do i=1 to 5;
year=year+1;
do qtr=1 to 4;
amount=amount*1.1;
end;
end;
run;
proc print data=WORK.NEW noobs;
run;
Which output is correct? Select one:
A. year amount i qtr
2017 33637.50 6 5
B. year amount i qtr
2016 33637.50 6 5
C. year amount i qtr
2016 33637.50 5 5
D. year amount i qtr
2016 33637.50 6 4
B is correct the because index variable of the DO loop is increased at the bottom of the loop and evaluated at the top. It will always be one increment past the range. Year is being calculated within the assignment statement within the outer DO loop. This statement is executed five times. The correct answer is: year amount i qtr 2016 33637.50 6 5
Complete the code below to reference a data set named data_in that is contained in the library cert. You must use the macro variable defined in the program in place of the library name. %let library = cert.data_in; libname cert “C:\workshop\cert”; data work.data_out; set Answer &library ; run;
The correct answer is &library. An ampersand is used to reference the macro variable. The correct answer is: &library
Given the SAS program shown below: %let category=Upper; data work.totals; set libr.input; if range eq then amount=4000; else amount= 2000; run; In the space below, enter the code required to reference the macro variable defined in the program.
The correct answer is: “&category”
The following SAS program is submitted:
data work.look;
x=2;
if x=1 then y=100;
if x=2 then y=200;
if x=3 then y=300;
else y=27;
run;
What are the values for x and y in the output data set? Select one:
A. There is a syntax error: x and y are both set to missing.
B. There is a syntax error: x=2, y is set to missing.
C. There are no errors: x=2, y=200.
D. There is a logic error: x=2, y=27.
The ELSE statement is only dependent upon the last IF statement. The first two IF statements in the example code do not have an associated ELSE statement and are totally independent of each other or the third IF statement. Given X equals 2, the Y value is assigned a value of 200 by the second IF statement. Then, because X does not equal 3, the third IF statement’s condition is false, the ELSE statement is executed, and a value of 27 is assigned to Y. The final values are: X=2, Y=27. The correct answer is: There is a logic error: x=2, y=27.