SASBase认证考试70题0110.docx
《SASBase认证考试70题0110.docx》由会员分享,可在线阅读,更多相关《SASBase认证考试70题0110.docx(12页珍藏版)》请在冰豆网上搜索。
SASBase认证考试70题0110
SAS-Base认证考试—70题(01-10)
∙
∙
∙LAST.VARIABLE:
同一个BY变量(组),若新的变量值最后一次出现时,其last.variable值为1。
另外,在BY变量右面有多个变量时,先按第一个变量排序,若第一个变量的观测存在重复时,才按第二个变量排序。
Q2
GiventhefollowingrawdatarecordsinTEXTFILE.TXT:
----|----10---|----20---|----30
John,FEB,13,25,14,27,Final
John,MAR,26,17,29,11,23,Current
Tina,FEB,15,18,12,13,Final
Tina,MAR,29,14,19,27,20,Current
Thefollowingoutputisdesired:
Obs Name Month Status Week1 Week2 Week3 Week4 Week5
1 John FEB Final 13
25 14
27 .
2 John MAR Current 26
17 29
11 $23
3 Tina FEB Final 15
18 12
13 .
4 Tina MAR Current 29
14 19
27 $20
WhichSASprogramcorrectlyproducesthedesiredoutput?
A.dataWORK.NUMBERS;
lengthName4Month
3Status$7;
infile'TEXTFILE.TXT'dsd;
inputNameMonth
;
ifMonth='FEB'theninputWeek1Week2Week3Week4Status$;
elseifMonth='MAR'theninputWeek1Week2Week3Week4Week5Status$;
formatWeek1-Week5dollar6.;
run;
procprintdata=WORK.NUMBERS;
run;
B.dataWORK.NUMBERS;
lengthName4Month
3Status$7;
infile'TEXTFILE.TXT'dlm=','missover;
inputNameMonth
;
ifMonth='FEB'theninputWeek1Week2Week3Week4Status$;
elseifMonth='MAR'theninputWeek1Week2Week3Week4Week5Status$;
formatWeek1-Week5dollar6.;
run;
procprintdata=WORK.NUMBERS;
run;
C.dataWORK.NUMBERS;
lengthName4Month
3Status$7;
infile'TEXTFILE.TXT'dlm=',';
inputNameMonth
@;
ifMonth='FEB'theninputWeek1Week2Week3Week4Status$;
elseifMonth='MAR'theninputWeek1Week2Week3Week4Week5Status$;
formatWeek1-Week5dollar6.;
run;
procprintdata=WORK.NUMBERS;
run;
D.dataWORK.NUMBERS;
lengthName4Month
3Status$7;
infile'TEXTFILE.TXT'dsd@;
inputNameMonth
;
ifMonth='FEB'theninputWeek1Week2Week3Week4Status$;
elseifMonth='MAR'theninputWeek1Week2Week3Week4Week5Status$;
formatWeek1-Week5dollar6.;
run;
procprintdata=WORK.NUMBERS;
run;
答案:
C
本题知识点:
INFILE语句与指示器@、@@
INFILEfilespecificationoptions;
其中,filespecification用来定义文件,options给出选择项;
∙filespecification有以下三种形式:
①、fileref(文件标志)
②、’filename’(文件名)
③、CARDS指明输入的数据,紧跟着CARDS语句
∙ 下列选择项(options)可以出现在INFILE语句中:
①、COLUMN=variable或COL=variable定义一个变量,其值是指针所在的当前列位置。
②、END=variable定义一个变量,作为文件结束的标志。
③、EOF=label是一个语句标号,当INFILE语句读到文件末尾时,作为隐含的GOTO语句的目标。
④、LENGHT=variable定义一个变量,其值是当前输入数据行的长度。
⑤、FIRSTOBS=linenumber要求从指定的行开始读取数据,而不是从文件的第一个记录开始。
⑥、OBS=n指定从一个顺序输入文件中读取数据的最后一个行(即第1~第n行)。
一个观察可能占n行。
⑦、DLM=若分隔符不是空格,则使用DLM=指定
⑧、DSD忽略引号中数值的分隔符;自动将字符数据中的引号去掉;将两个相邻分隔符视为缺失值处理。
⑨、MISSOVER阻止INPUT进入下一行读取,未赋值变量视为缺失值。
⑩、TRUNCOVER 与MISSOVER相似,但在COLUMNINPUT或FORMATTEDINPUT中使用。
比较@与@@的区别:
∙@用于1个数据行用多个input语句读取,停留到下一个INPUT语句。
∙@@用于1个数据行含有多个观测值读取时,停留到下一个DATA步。
Q3
ThefollowingSASprogramissubmitted:
dataWORK.DATE_INFO;
Day="01";
Yr=1960;
X=mdy(Day,01,Yr);
run;
WhatisthevalueofthevariableX?
A.thenumericvalue0
B.thecharactervalue"01011960"
C.amissingvalueduetosyntaxerrors
D.thestepwillnotcompilebecauseofthecharacterargumentinthemdyfunction.
答案:
A
本题知识点:
数据类型的自动转换
在SAS中,日期时间是以1960年1月1日0时0分0秒作为起点的。
因此,mdy(1,1,1960)=0。
若把日期时间表示为常数时,要使用相应的格式,带单或双引号,在后面紧跟一个D(日期)、T(时间)、DT(日期时间)。
在本题中,日期函数的参数应该是数值,若是字符串,会先尝试字符串是否可以转换为数值,这是自动转换。
自动转换是指系统产生一个临时的变量来完成赋值或运算。
当自动转换发生时,会在LOG窗口中给出提示。
1)、字符型变量->数值型变量
在下面的情况中,VarB是一个字符型变量,其它是数字型变量。
∙赋值于一个数字型变量,如:
VarA=VarB;
∙在算术运算中使用,如:
VarA=VarB+0;
∙与一个数字型变量进行比较,如:
ifVarB>=VarA;
∙在函数中,参数要求数字型变量,如:
VarA=sum(VarB,0);
2)、数值型变量->字符型变量
在下面的情况中,VarB是一个数字型变量,其它是字符型变量。
∙赋值于一个字符型变量,如:
VarA=VarB;
∙在与要求字符的运算符一起使用,如:
VarA=''||VarB;
∙在函数中,参数要求字符型变量,如:
VarA=trim(VarB);
Q4
TheExcelworkbookREGIONS.XLScontainsthefollowingfourworksheets:
EAST
WEST
NORTH
SOUTH
Thefollowingprogramissubmitted:
libnameMYXLS'regions.xls';
WhichPROCPRINTstepcorrectlydisplaystheNORTHworksheet?
A.procprintdata=MYXLS.NORTH;run;
B.procprintdata=MYXLS.NORTH$;run;
C.procprintdata=MYXLS.'NORTH'e;run;
D.procprintdata=MYXLS.'NORTH$'n;run;
答案:
D
本题知识点:
打印Excel的某个工作表的数据
WHATISTHAT“$”CHARACTER?
LookingatSASExploreritmaybesurprisingthateachdatasetwrittentoExcelappearstwice,oncewiththeexpectednameandoncewithatrailing“”.Unlikeatypicaldatasource,datainanExcelspreadsheetneednotbeleftandtopaligned.ForthisExcelhasnamedrangeswhichallowdatatobeplacedanywhereinsideaspreadsheet.BydefaultSASreadsandwritesdatafromnamedrangesonspreadsheets,butwillalsoreadspreadsheetdatadirectlyintheabsenceofanamedrange.WhenanewSASdatasetiscreatedinanExcellibrary,SAScreatesbothaspreadsheetandanamedrange.Eachisgiventhesamename,withthespreadsheetdenotedbyatrailing“
”.
IntheexampleatrightCLASSisthenamedrangecreatedbytheExcelengineandCLASS$isthespreadsheetcreatedbytheExcelenginetoholdthenamedrange.WithinSAS,thenamedrangeisreferredtoasWrkbk.CLASS,andthespreadsheetisreferencedusingthenameliteralWrkbk.’CLASS$’n.
SASnameliteralsarenametokenswrittenasstringswithinquotationmarks,followedbythelettern.NameliteralsallowtheuseofspecialcharactersthatarenototherwiseallowedinSASnames,likethe“$”usedbytheExcellibnameenginetodistinguishworksheetsfromnamedranges.FormoreinformationseetheRecommendedReadings.
摘自《De-MystifyingtheSASLIBNAMEEngineinMicrosoftExcel:
APracticalGuide》
Q5
Whichstatementspecifiesthatrecords1through10aretobereadfromtherawdatafilecustomer.txt?
A.infile'customer.txt'1-10;
B.input'customer.txt'stop@10;
C.infile'customer.txt'obs=10;
D.input'customer.txt'stop=10;
答案:
C
本题知识点:
INFILE的选项
FIRSTOBS=常数,要求从指定的行开始读取数据,而不是从文件的第一个记录开始。
OBS=常数,指定从一个顺序输入文件中读取数据的最后一个行(即第1~第n行)。
一个观测可能占n行。
Q6
AfteraSASprogramissubmitted,thefollowingiswrittentotheSASlog:
101 dataWORK.JANUARY;
102 setWORK.ALLYEAR(keep=productmonthnum_SoldCost);
103 ifMonth='Jan'thenoutputWORK.JANUARY;
104 Sales=Cost*Num_Sold;
105 keep=ProductSales;
-----
22
ERROR22-322:
Syntaxerror,expectingoneofthefollowing:
!
!
!
&,*,**,+,-,
,<=,<>,=,>,>=,
AND,EQ,GE,GT,IN,LE,LT,MAX,MIN,NE,NG,NL,
NOTIN,OR,^=,|,||,~=.
106 run;
WhatchangesshouldbemadetotheKEEPstatementtocorrecttheerrorsintheLOG?
A.keep=(ProductSales);
B.keepProduct,Sales;
C.keep=Product,Sales;
D.keepProductSales;
答案:
D
本题知识点:
KEEP语句与KEEP=选项
在处理大型数据集时,KEEP=选项的效率较高。
∙KEEP语句:
KEEPvariable(s); 不能用于过程步。
∙KEEP=选项:
data-set-name(KEEP=variable(s)) 可以用于数据步(如,DATA语句、SET语句)、过程步。
其中,variable(s)是具体变量,不能是数组、_N_、_ERROR_等。
Q7
WhichofthefollowingchoicesisanunacceptableODSdestinationforproducingoutputthatcanbeviewedinMicrosoftExcel?
A.MSOFFICE2K
B.EXCELXP
C.CSVALL
D.WINXP
答案:
D
本题知识点:
ODS输出
Mostofthesedestinationsaredesignedtocreateoutputforviewingonascreenorforprinting.
TheOUTPUTdestinationcreatesSASdatasets.TheMARKUPdestinationisageneralpurpose
toolforcreatingoutputinformatsdefinedby tagsets.ThisincludesXML(eXtensibleMarkup
Language),EXCELXP,LaTeX,CSV(comma-separatedvalues),andmanyotherformatswheredata
canbethoughtofasseparatedbytags.TheDOCUMENTdestination,ontheotherhand,allows
youtocreateareusableoutput“document”thatyoucanrerenderforanydestination.So,ifyour
bossdecideshereallywantsthatreportinPDF,notRTF,youcanreplaytheoutputdocument
withouthavingtoreruntheentireSASprogramthatcreatedthedata.Withanoutputdocument,
youcanalsorearrange,duplicate,ordeletetablestofurthercustomizeyouroutput.
摘自《TheLittleSASBook》(Fourth) P152页
Q8
TheSASdatasetnamedWORK.SALARYcontains10observationsforeachdepartment,andiscurrentlyorderedbyDepartment.
ThefollowingSASprogramissubmitted:
dataWORK.TOTAL;
setWORK.SALARY(keep=DepartmentMonthlyWageRate);
byDepartment;
ifFirst.Department=1thenPayroll=0;
Payroll+(MonthlyWageRate*12);
ifLast.Department=1;
run;
Whichstatementistrue?
A.ThebystatementintheDATAstepcausesasyntaxerror.
B.ThestatementPayroll+(MonthlyWageRate*12);inthedatastepcausesasyntaxerror.
C.ThevaluesofthevariablePayrollrepresentthemonthlytotalforeachdepartmentintheWORK.SALARYdataset.
D.ThevaluesofthevariablePayrollrepresentamonthlytotalforallvaluesofWAGERATEintheWORK.SALARYdataset.
答案:
C
本题知识点:
类似第1题
Q9
datacourse;
inputexam;
datalines;
50.1
;
run;
procformat;
valuescore1–50=‘Fail’
51–100=‘Pass’;
run;
procreportdata=coursenowd;
columnexam;
defineexam/displayformat=score.;
run;
Whatisthevalueforexam?
A. Fail
B. Pass
C. 50.1
D. Nooutput
答案:
C
本题知识点:
PROCFORMAT语句
PROCFORMAT;
VALUEname
range-1=’formatted-text-1′;
range-2=’formatted-text-2′;
……
range-n=’formatted-text-n’;
若name为字符串设计格式,则必须在开头加$,长度不超过32字节;
name不能以数字结尾,除了下划线外,不能含其他的任何特殊字符。
在range右侧文本可达到32767字节。
∙变量值是字符串要加引号。
∙range是多个值,要用逗号。
∙连续的要用-。
∙关键字low、high指代变量中最小和最大的非缺失值。
∙用<排除或指代某些范围。
∙other是给其他没列在VALUE中的变量分配格式。
Q10
ThefollowingSASprogramissubmitted:
dataWORK.RETAIL;
Cost='$20.000';