SAS Practice Exam Flashcards

1
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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?

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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’

A

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’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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;

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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;

A

The correct answer is &library. An ampersand is used to reference the macro variable. The correct answer is: &library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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.

A

The correct answer is: “&category”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The following SAS program is submitted:

data work.test;

type=’SQL’;

if type=’SAS’ then description=’SAS Program’;

else description=’other’;

length description 8;

run;

What occurs when the program is submitted? Select one:

A. The variable Description is created as an 11-byte character variable and is assigned the value ‘SAS program’ in the DATA step.

B. The variable Description is created as a 5-byte character variable and is assigned the value ‘SAS P’ in the DATA step.

C. The variable Description is created as an 8-byte character variable and is assigned the value ‘SAS Prog’ in the DATA step.

D. The variable Description is created as an 11-byte character variable and the DATA step fails due to errors.

A

At compile time, because of the assignment within the IF statement, the variable Description will be created as an 11-byte character variable in the descriptor portion of the data set. A later attempt by the LENGTH statement to define this variable as numeric will cause a syntax error that will stop the execution of this step and prevent a value from being assigned to the variable. The correct answer is: The variable Description is created as an 11-byte character variable and the DATA step fails due to errors.

17
Q

The following SAS program is submitted: proc means data=work.schools median; run; Assume that Work.Schools has two numeric variables and the following PROC MEANS report is produced: PROC MEANS report Which of the following SAS statements completes the program and creates the desired report? Select one:

A. by location;

B. class location;

C. group by location;

D. by location; id location;

A

The CLASS statement was used to generate this report. It does not assume that the data set is in sorted order and it provides a very compact and easy to read report. The correct answer is: class location;

18
Q

A PROC PRINT report was created with the following title: Asia Sports Vehicle Summary After the PROC PRINT report is run, a programmer would next like to produce a PROC FREQ report with the following title: Asia Sports Vehicle Summary Distribution by Make Which statement(s) would produce the new report titles? Select one:

A. title “Distribution by Make”;

B. title “Asia Sports Vehicle Summary”; title “Distribution by Make”;

C. title “Asia Sports Vehicle Summary”; title2 “Distribution by Make”;

D. title “Asia Sports Vehicle Summary”; subtitle “Distribution by Make”;

A

A and B are not correct because they only specify Title1. D is not correct because the Subtitle statement does not exist. C is the correct answer because specifies Title1 and Title2. Since the first title line was already specified, it’s not necessary to repeat it. The correct answer is: title “Asia Sports Vehicle Summary”; title2 “Distribution by Make”;

19
Q

Given the code below:

title;

proc format;

value yrgroup low - ‘31dec1991’d = [year.] ‘01jan1992’d - high = [monyy.] ;

run;

proc print data=SASHelp.retail noobs;

where date > ‘01Jan1991’d;

var date sales;

format date yrgroup.;

where date > ‘01Jan1980’d;

run;

Which statement describes the results? Select one:

A. The report generated by the PRINT procedure will summarize sales by year through 1991 and after by month and year.

B. The FORMAT procedure will fail but the PRINT procedure will summarize by date disregarding the FORMAT statement.

C. The FORMAT procedure will fail to create a format and thus the PRINT procedure will fail as the format cannot be found.

D. The PRINT procedure will fail as there are conflicting WHERE statements.

A

When multiple WHERE statements are coded, the last WHERE statement takes precedence. Use nested formats to summarize by varying levels. The correct answer is: The report generated by the PRINT procedure will summarize sales by year through 1991 and after by month and year.

20
Q

Assume that Work.Ds1 and Work.Ds2 exist and the following SAS program is submitted: ods pdf file=’results.pdf’; proc print data=work.ds1; run; proc freq data=work.ds1; proc freq data=work.ds2; run; ods pdf close; How many PDF files are created? Select one:

A. 1 PDF file with all the output combined

B. 2 PDF files – one file for each data set used

C. 2 PDF files – one for the PRINT output and one for the FREQ output

D. 3 PDF files – one per procedure request

A

The ODS specification in this example will combine all of the output into a single PDF document. The correct answer is: 1 PDF file with all the output combined