?
the VIEWTABLE window in Referencing Files and Setting Options.
10. The SAS data set Sashelp.Prdsale contains the variables Region and Salary with 4 observations per Region. Sashelp.Prdsale is sorted primarily by Region and within Region by Salary in descending order.
The following program is submitted:
data one;
set sashelp.prdsale; retain temp;
by region descending salary; if first.region then do;
temp=salary; output; end;
if last.region then do;
range=salary-temp; output; end; run;
For each region, what is the number of observation(s) written to the output data set? a. 0 b. 1 c. 2 d. 4
Correct answer: c
The expression first.region is true once for each region group. The expression last.region is true once for each region group. Therefore, each OUTPUT statement executes once for a total of 2 observations in the output data set.
You can learn about the FIRST.variable expression and the OUTPUT statement in Reading SAS Data Sets.
11. The following SAS program is submitted:
proc contents data=sasuser.houses; run;
The exhibit below contains partial output produced by the CONTENTS procedure.
Data Set Name Member Type Engine Created
2003 03:09:25 PM Last Modified 2003 03:09:25 PM Protection
SASUSER.HOUSES Observations DATA Variables V9 Indexes Tuesday, April 22,
Observation Length 56 Tuesday, April 22, Deleted Observations Compressed
SAS中文论坛网站http://www.mysas.net
SAS中文论坛FTP站ftp://mysas.vicp.net
15 6 0
0 NO
Data Set Type Label Residential housing
for sale
Data Representation WINDOWS_32 Encoding wlatin1 Western (Windows)
Sorted
NO
Which of the following describes the Sasuser.Houses data set? a. The data set is sorted but not indexed. b. The data set is both sorted and indexed. c. The data set is not sorted but is indexed. d. The data set is neither sorted nor indexed. Correct answer: d
The exhibit above shows partial output from the CONTENTS procedure, In the top right-hand column of the output, you see that Indexes has a value of 0, which indicates that no indexes exist for this data set. Also, Sorted has a value of NO, which indicates that the data is not sorted.
You can learn about the CONTENTS procedure in Referencing Files and Setting Options.
12.The following SAS program is submitted:
proc sort data=work.test;
by fname descending salary; run;
Which one of the following represents how the observations are sorted? a. The data set Work.Test is stored in ascending order by both Fname and Salary values. b. The data set Work.Test is stored in descending order by both Fname and Salary values. c. The data set Work.Test is stored in descending order by Fname and ascending order by Salary values. d. The data set Work.Test is stored in ascending order by Fname and in descending order by Salary values. Correct answer: d
The DESCENDING keyword is placed before the variable name it modifies in the BY statement, so the correct description is in descending order by Salary value within ascending Fname values.
You can learn about the SORT procedure and the DESCENDING keyword in Creating List Reports.
13.The following SAS program is submitted:
data names;
SAS中文论坛网站http://www.mysas.net SAS中文论坛FTP站ftp://mysas.vicp.net
title='EDU';
if title='EDU' then
Division='Education'; else if title='HR' then
Division='Human Resources'; else Division='Unknown'; run;
Which one of the following represents the value of the variable Division in the output data set? a. Educatio b. Education c. Human Re
d. Human Resources Correct answer: b
The length of the variable Division is set to 9 when the DATA step compiles. Since the value of the variable Title is EDU, the first IF condition is true; therefore, the value of the variable Division is Education. You can learn about
? ?
the length of a variable in Understanding DATA Step Processing IF-THEN statements in Creating and Managing Variables.
14.Which one of the following SAS programs creates a variable named City with a value of Chicago? a. data work.airports;
AirportCode='ord';
if AirportCode='ORD' City='Chicago'; run;
data work.airports; b.
AirportCode='ORD';
if AirportCode='ORD' City='Chicago'; run;
data work.airports; c.
AirportCode='ORD';
if AirportCode='ORD' then City='Chicago'; run;
data work.airports; d.
AirportCode='ORD'; if AirportCode='ORD'; then City='Chicago'; run;
Correct answer: c
The correct syntax for an IF-THEN statement is: IF expression THEN statement;
In this example, the variable City is assigned a value of Chicago only if the expression AirportCode='ORD' is true.
SAS中文论坛网站http://www.mysas.net SAS中文论坛FTP站ftp://mysas.vicp.net
You can learn about IF-THEN statements in Creating and Managing Variables. 15.The following SAS program is submitted:
data work.building; code='DAL523';
code='SANFRAN604'; code='HOUS731'; length code $ 20; run;
Which one of the following is the length of the code variable? a. 6 b. 7 c. 10 d. 20
Correct answer: a
The DATA step first goes through a compilation phase, then an execution phase. The length of a variable is set during the compilation phase and is based on the first time the variable is encountered. In this case, the variable code is set to the length of the text string DAL523 which is 6 characters long. The next assignment statements are ignored during compilation. The LENGTH statement is also ignored since the length has already been established, but a note will be written to the log. You can learn about
the compilation phase of the DATA step in Understanding DATA Step Processing
? the LENGTH statement in Creating and Managing Variables.
?
16. Which of the following statements creates a numeric variable named IDnumber with a value of 4198?
a. IDnumber=4198; b. IDnumber='4198'; c. length IDnumber=8; d. length IDnumber $ 8; Correct answer: a
The first reference to the SAS variable in the DATA step sets the name, type, and length of the variable in the program data vector (PDV) and in the output SAS data set. The assignment statement IDnumber=4198; is the first reference and creates a numeric variable named IDnumber with a default storage length of 8 bytes. You can learn about
?
creating variables in the DATA step in Understanding DATA Step Processing
SAS中文论坛网站http://www.mysas.net SAS中文论坛FTP站ftp://mysas.vicp.net
?
numeric variables in Basic Concepts.
17. The following program is submitted:
data fltaten;
input jobcode $ salary name $; cards;
FLAT1 70000 Bob FLAT2 60000 Joe FLAT3 30000 Ann ; run;
data desc;
set fltaten;
if salary>60000 then description='Over 60'; else description='Under 60'; run;
What is value of the variable named description when the value for salary is 30000?
a. b. c. d. Under 6 Under 60 Over 60
' ' (missing character value)
Correct answer: a
The variable description is being created by the IF-THEN/ELSE statement during
compilation. The first occurrence of the variable description is on the IF statement, and since it is assigned the value Over 60, the length of the variable is 7. Therefore, for the salary value of 30000, description has the value of Under 6 (the 0 is truncated.) You can learn about
the compilation phase of the DATA step in Understanding DATA Step Processing
? IF-THEN/ELSE statements in Creating and Managing Variables.
?
18. A raw data file is listed below.
1---+----10---+----20---+--- 10 23 20 15
The following program is submitted:
data all_sales;
infile 'file-specification'; input receipts;
SAS中文论坛网站http://www.mysas.net SAS中文论坛FTP站ftp://mysas.vicp.net