Chapter2
2. How many program steps are executed when the program below is processed?
data user.tables;
set work.jobs;run;
proc sort data=user.tables;
by name;
run;
proc print data=user.tables;
run;
a. three
b. four
c. five
d. six
正确答案:a
解析:data,proc为程序步骤
10. What is a SAS library?
a. a collection of SAS files, such as SAS data sets and catalogs
b. in some operating environments, a physical collection of SAS files
c. a group of SAS files in the same folder or directory
d. all of the above
正确答案:d
解析:每个SAS文件都存储在一个SAS库中。SAS库是SAS文件的集合,例如SAS数据集和目录。在某些操作环境中,SAS库是文件的物理集合。在其他情况下,文件仅在逻辑上相关。在
在Windows和UNIX环境中,SAS库通常是同一文件夹或目录中的一组SAS文件。
Chapter3
1. How long do librefs remain in effect?
a. until the LIBNAME statement is changed
b. until the LIBNAME statement is cleared
c. until the SAS session ends
d. all of the above
正确答案:d
在LIBNAME语句被更改、取消或SAS会话结束之前,libref一直有效
2. Which of the following statements are true?
a. When using the default engine, you do not have to specify the libref in the LIBNAME statement.
b. When using the default engine, you do not have to specify the engine name in the LIBNAME statement.
c. When using the default engine, you do not have to specify the SAS library in the LIBNAME statement.
d. When using the default engine, you have to specify the libref, engine name, and the SAS library in the LIBNAME statement.
正确答案:b
解析:当您使用默认引擎时,不必在LIBNAME语句中指定引擎名称。但是,您必须指定libref和SAS数据库名称
3. When you specify an engine for a library, what are you specifying?
a. the file format for files that are stored in the library
b. the version of SAS that you are using
c. permission to access to other software vendors' files
d. instructions for creating temporary SAS files
正确答案:a
解析:SAS引擎是SAS用于写入和读取SAS库中的文件的一组内部指令。每个引擎都为存储在库中的文件指定文件格式,从而使SAS能够访问具有特定格式的文件。一些引擎访问SAS文件,而其他引擎支持访问其他供应商的文件。
4. Which statement prints a summary of all the files stored in the library named Area51?
a. proc contents data=area51._all_ nods;
解析:要使用contents过程打印库内容的摘要,请使用句号将_ALL_选项附加到libref。添加NODS选项将抑制有关文件的详细信息。
5. Which of the following programs correctly references a SAS data set named SalesAnalysis that is stored in a permanent SAS library?
a.
data saleslibrary.salesanalysis;
set mydata.quarter1sales;
if sales>100000;
run;
b.
data mysales.totals;
set sales_2017.salesanalysis;
if totalsales>50000;
run;
c.
proc print data=salesanalysis.quarter1;
var sales salesrep month;
run;
d.
proc freq data=2017data.salesanalysis;
tables quarter*sales;
run;
e. none of the above
解析:列出的所有程序都违反了分配libref的规则。Librefs长度为1 ~ 8个字符,必须以字母或下划线开头,只能包含数字、字母或下划线。在分配了一个libref之后,将它指定为SAS文件的两级名称中的第一级。
Chapter4
2. Which type of delimited file does PROC IMPORT read by default?
b. varying record-length files
解析:默认情况下,IMPORT过程将带分隔符的文件读取为不同记录长度的文件。如果您的外部文件具有固定长度的格式,则在包含RECFM=F和LRECL=选项的PROC IMPORT语句之前使用OPTIONS语句
8. To override the DATA step default behavior that writes observations to output, what should you use in a DATA step?覆盖
a. DROP= and KEEP= data set options
b. an OUTPUT statement
c. an OUT= option
d. a BY statement
data work.usa5;
set cert.usa(keep=manager wagerate);
if _n_=5 then output;
run;
proc print data=work.usa5;
run;
解析:在DATA步骤中放置显式OUTPUT语句将覆盖自动输出,因此只有在执行显式OUTPUT语句时才会将观察结果添加到数据集中。方法的默认行为
数据的步骤。
Chapter5
8. When the source of the errors in the program is not apparent, which statement or statements can you use to examine errors and print messages to the log?
a. PUTLOG statement
b. PUT statement
c. VAR statement
d. a and b only
e. none of the above
data work.loan01;
set cert.loan;
if code='1' then type='variable';
else if code='2' then type='fixed';
else type='unknown';
put 'MY NOTE: The condition was met.';
run;
9. What types of errors can the PUTLOG statement help you resolve?
a. syntax errors
b. semantic errors
c. logic errors
d. all of the above
解析:当程序语句遵循规则并执行,但结果不正确时,会发生逻辑错误。您可以在DATA步骤中使用PUTLOG语句来帮助识别逻辑错误
Chapter7
3. Unless otherwise directed, how does the DATA step execute?
a. once for each compilation phase
b. once for each DATA step statement
c. once for each record in the input file
d. once for each variable in the input file
正确答案:c
解析:除非另有指示,否则DATA步骤对输入文件中的每个记录执行一次。
6. Which of the following actions occurs at the beginning of an iteration of the DATA step?
a. The automatic variables _N_ and _ERROR_ are incremental by one.
b. The DATA step stops execution.
c. The descriptor portion of the data set is written.
d. The values of variables created in programming statements are reset to missing in the program data vector
正确答案:d
解析:默认情况下,在DATA步骤结束时,程序数据向量中的值作为观察值写入数据集。然后,控制返回到DATA步骤的顶部,自动变量_N_的值加1,在编程语句中创建的变量的值被重置为missing。如果需要,自动变量_ERROR_将被重置为0
Chapter8
3. Which temporary variables are available for DATA step programming during BYgroup processing only, but are not added to the data set?
a. FIRST.variable and LAST.variable.
b. _N_ and _ERROR variables.
c. Both a and b.
d. none of the above
正确答案:a
解析:In the DATA step, during BY-group processing only, the temporary variables FIRST.variable and LAST.variable are available for DATA step programming, but they do not appear in the output data set.
5. What statement correctly describes a BY group?
a. It contains temporary variables that SAS creates for each BY variable.
b. It includes all observations with the same BY value.
c. It names a variable or variables by which the data set is sorted.
d. It is a method of processing observations from one or more SAS data sets that are group or ordered by one or more common variables.
正确答案:b
解析:BY组包括所有具有相同BY值的观测值。如果在BY语句中使用多个变量,则BY组是一组具有这些变量相同值组合的观测值。每个BY组都有变量的唯一值组合。
7. Which program creates the following output?
a.
proc sort data=cert.choices out=work.choices;
by day flavor;
run;
proc print data=work.choices;
run;
b.
proc sort data=cert.choices out=work.choices;
by day;
run;
proc print data=work.choices;
run;
c.
proc print data=cert.choices out=work.choices;
by day;
run;
d.
proc sort data=cert.choices out=work.choices;
by flavor;
run;
proc print data=work.choices;
run;
正确答案:a 记得看清楚分组后的排序
7. Which program contains an error?
a.
data stresstest(drop=timemin timesec);
set cert.tests;
TotalTime=(timemin*60)+timesec;
SumSec+totaltime;
run;
b.
proc print data=stresstest;
label totaltime='Total Duration of Test';
drop sumsec;
run;
c.
proc print data=stresstest(keep=totaltime timemin);
label totaltime='Total Duration of Test';
run;
d.
data stresstest;
set cert.tests;
TotalTime=(timemin*60)+timesec;
keep id totaltime tolerance;
run;
正确答案:b
解析:要选择变量,可以在任何DATA步骤中使用DROP或KEEP语句。还可以在任意格式的数据集名称后面使用DROP=或KEEP=数据集选项
DATA或PROC步骤。但是,不能在P
ROC步骤中使用DROP或KEEP语句。
8. If you submit the following program, which variables appear in the new data set?
data work.cardiac(drop=age group);
set cert.fitness(keep=age weight group);
if group=2 and age>40;
run;
只剩weight
3. For the observation shown below, what is the result of the IF-THEN statements?
if status='OK' and type=3 then Count+1;
if status='S' or action='E' then Control='Stop';
a. Count = 12 Control = Go
b. Count = 13 Control =Stop
c. Count = 12 Control =Stop
d. Count = 13 Control = Go
Chapter10
1. Which program combines Work.One and Work.Two to produce Work.Three?
a.
data work.three;
set work.one;
set work.two;
run;
b.
data work.three;
set work.one work.two;
run;
c.
data work.three;
set work.one work.two;
by varx;
run;
d.
data work.three;
merge work.one work.two;
by varx;
run;
正确答案:a work.two覆盖work.one中的vax值,其他合并在一起不显示缺失
8. What happens if you submit the following program to merge Cert.Donors1 and Cert.Donors2, shown below?
data work.merged;
merge cert.donors1 cert.donors2;
by id;
run;
a. The merged data set contains some missing values because not all observations have matching observations in the other data set.
b. The merged data set contains eight observations.
c. The DATA step produces errors.
d. Values for Units in Cert.Donors2 overwrite values of Units in Cert.Donors1.
正确答案:c
解析:这两个输入数据集不是按by变量的值排序的,因此data步骤产生错误并停止处理。
10. If you merge data sets Work.Reps, Work.Close, and Work.Bonus by ID, what is the value of Bonus in the third observation in the new data set?
a. $4,000
b. $3,000
c. missing
d. You cannot tell from the information given
正确答案:a
解析:
Chapter11
5. Which of the following statements is false regarding the program shown below?
注意output
data work.invest;
do year=1990 to 2004;
Capital+5000;
capital+(capital*.10);
output;
end;
run;
a. The OUTPUT statement writes current values to the data set immediately.
b. The last value for Year in the new data set is 2005.
c. The OUTPUT statement overrides the automatic output at the end of the DATA step.
d. The DO loop performs 15 iterations.
解析:
OUTPUT语句覆盖DATA步骤末尾的自动输出。
在DO循环的最后一次迭代中,Year, 2004的值被写入数据集。
1.output存在:
2.output不存在:
注意:如果加了proc print 输出中的结果(不是sas表中)只有2005
6. How many observations will the data set Work.Earn contain?
data work.earn;
Value=2000;
do year=1 to 20;
Interest=value*.075;
value+interest;
output;
end;
run;
a. 0
b. 1
c. 19
d. 20
1.do loops 不用于proc语句
2. During each execution of the following DO loop, the value of Earned is calculated and is added to its previous value. How many times does this DO loop execute?
data work.earnings;
Amount=1000;
Rate=.075/12;
do month=1 to 12;
Earned+(amount+earned)*rate;
end;
run;
a. 0
b. 1
c. 12
d. 13
解析:循环12次,最后month显示为13,output的话共显示12条,没有output只显示为1条13
Chapter12
proc format lib=formtlib
proc format lib=formtlib;
value colorfmt
1='Red'
2='Green'
3='Blue';
run;
跟label一样中间的赋值不加;
7. Which keyword can be used to label missing numeric values as well as any values that are not specified in a range?
a. LOW
b. MISS
c. MISSING
d. OTHER
正确答案:d
解析:MISS和MISSING是无效的关键字,LOW不包括缺失的数值。关键字OTHER可以在VALUE语句中用于标记缺失的值以及没有具体包含在范围中的任何值
8. You can place the FORMAT statement in either a DATA step or a PROC step. What happens when you place it in a DATA step?
By placing the FORMAT statement in a DATA step, you permanently associate the defined format with variables(通过在DATA步骤中放置FORMAT语句,可以永久地将定义的格式与变量关联起来)
10. Which keyword, when added to the PROC FORMAT statement, displays all the formats in your catalog?
a. CATALOG
b. LISTFMT
c. FMTCAT
d. FMTLIB
libname formtlib 'c:\sas\formats\lib';
proc format library=formtlib fmtlib;
run;
Chapter13
3. SAS does not automatically make adjustments for daylight saving time, but it does make adjustments for which one of the following?
a. leap seconds
b. leap years
c. Julian dates
d. time zones
解析:SAS会自动调整闰年
4. An input data file has date expressions in the form 10222001. Which SAS informat should you use to read these dates?
a. DATE6.
b. DATE8.
c. MMDDYY6.
d. MMDDYY8.
解析:长度为8,date格式15Oct17 (转换这种带oct的为数字:month=month(day)day为变量)
日期间隔 : TotDays=lastday-firstday+1; 记得加1 (与一般医院病案首页实际天数一致)
Chapter14
3. A typical value for the numeric variable SiteNum is 12.3. Which statement correctly converts the values of SiteNum to character values when creating the variable Location?
a. Location=dept||'/'||input(sitenum,3.1);
b. Location=dept||'/'||input(sitenum,4.1);
c. Location=dept||'/'||put(sitenum,3.1);
d. Location=dept||'/'||put(sitenum,4.1);
正确答案:d
解析:100.0 4.1
Chapter15
4. Which of the following statements is true regarding BY-group processing?
a. BY variables must be either indexed or sorted.
b. Summary statistics are computed for BY variables.
c. BY-group processing is preferred when you are categorizing data that contains few variables.
d. BY-group processing overwrites your data set with the newly grouped observations.
正确答案:a
解析:
与CLASS处理不同,BY-group处理要求数据已经按照BY变量的顺序排序或建立索引。除非数据集观测值已经排序,否则在对任何BY组使用PROC MEANS之前必须运行SORT过程。
警告:
如果不使用OUT=选项指定输出数据集,PROC SORT将使用新排序的观察值覆盖初始数据集。
BY-group结果的布局与CLASS组结果的布局不同。
Chapter16
6. The table of contents that was created by the CONTENTS= option contains a numbered heading for which of the following?
a. each procedure
b. each procedure that creates output
c. each procedure and DATA step
d. each HTML file created by your program
10. What is the purpose of the PATH= option?
ods html path='d:\output' (url=none)
body='body.html'
contents='contents.html'
frame='frame.html';
a. It creates absolute link addresses for loading HTML files from a server.
b. It creates relative link addresses for loading HTML files from a server.
c. It allows HTML files to be loaded from a local drive.
d. It specifies the location of HTML file output.
8. What is the purpose of the following URL= suboptions?
ods html body='d:\output\body.html' (url='body.html')
contents='d:\output\contents.html' (url='contents.html')
frame='d:\output\frame.html';
b. To create relative link addresses for loading the files from a server.