SAS上机练习题(全部,含参考答案)

合集下载

SAS练习题及答案

SAS练习题及答案

1.SAS系统主要完成以数据为中心的四大功能,其中核心功能为:统计分析功能2.在SAS系统的组成模块中,能进行数据管理和数据加工、处理的模块……BASE模块3.SAS显示管理系统窗口中能够提交当前运行的SAS程序执行过程的窗口为:…………………………………………………………………PGM窗口4.如下一段SAS程序:DATA ;INPUT X @@;CARDS:2 3 4 9 1 ;RUN;模块当运行程序以后SAS系统会产生SAS数据集………………………………………( C )A. DATAB. NULLC. DATA1D.程序错误5.INPUT语句一般用来指定数据的读入方式,可以读取各种类型的数据包括字符型,现有如下的一段程序:DATA ONE;INPUT NAME $ SCORE;CARDS;Wanglin 85Zhang dong-feng 90;那么在第二个观测中读取到的NAME 为……………………………………………(B)A. Zhang dong-fengB. ZhangC. Zhang doD. Zhang dong6.假设变量X的值为5,有如下程序IF X<5 THENX=X+3;ELSEX=X-2;则执行程序以后变量X的值为………………………………………………………( B)A. 5B.3C.8D. 程序错误7.DATA TEST;DO I=1 TO 3;PUT I= ;END;RUN;程序结果在LOG窗口输出形式为……………………………………………………( A )A. I=1 I=2 I=3B.I=2 I=3 I=4C. 不显示D. I=3 I=2 I=18.假设变量X1=-10.253 X2=-5 则[SIGN(X1)+ABS(X2)]/INT(X1)的运算结果为………………………………………( B)A.-4B.-0.4C. 4D.0.5759.逻辑运算[(5<1)|(4<>2)]&(7>2)的结果为:……………………………………( 1 )10.以下几个统计量在UNIVARIATE过程中能求得到得而在MEANS过程中无法求得的是………………………………………………………………………………………( B )A. meanB. varC. Q1D.range11.SAS系统主要完成以数据为中心的四大功能,其中能够将Excel、Lotus、DBF、TXT等数据转化成SAS 数据集属于…………………………… (数据管理功能 )12. SAS数据集是关系型结构,分成两部分:描述部分和。

SAS认证考试(官方练习题集和校正答案)

SAS认证考试(官方练习题集和校正答案)

1. A raw data file is listedbelow.The following program issubmitted using this file asinput:data work.family;infile 'file-specification';<insert INPUTstatement here>run;Which INPUT statementcorrectly reads the values forthe variable Birthdate asSAS date values?a.input relation$ first_name$ birthdate date9.;b.input relation$ first_name$ birthdatemmddyy8.;c.input relation$ first_name$ birthdate :date9.;d.input relation$ first_name$ birthdate :mmddyy8.;Correct answer: dAn informat is used to translate the calendar date to a SAS datevalue. The date values are in the form of two-digit values formonth-day-year, so the MMDDYY8. informat must be used.When using an informat with list input, the colon-formatmodifier is required to correctly associate the informat with thevariable name.You can learn about•informats in Reading Date and Time Values•the colon-format modifier in Reading Free-FormatData.2. A raw data file is listed below.1---+----10---+----20---+---Jose,47,210Sue,,108The following SAS program is submitted using the raw data fileabove as input:data employeestats;<insert INFILE statement here>input name $ age weight;run;The following output is desired:name age weightJose47210Sue.108Which of the following INFILE statements completes theprogram and accesses the data correctly?a.infile 'file-specification' pad;b.infile 'file-specification' dsd;c.infile 'file-specification' dlm=',';d.infile 'file-specification' missover;Correct answer: bThe PAD option specifies that SAS pad variable length recordswith blanks. The MISSOVER option prevents SAS fromreading past the end of the line when reading free formatteddata. The DLM= option specifies the comma as the delimiter;however, consecutive delimiters are treated as one by default.The DSD option correctly reads the data with commas asdelimiters and two consecutive commas indicating a missingvalue like those in this raw data file.You can learn about•the PAD option in Reading Raw Data in Fixed Fields•the MISSOVER option in Creating MultipleObservations from a Single Record•the DLM= option and the DSD option in Reading Free-Format Data.3. The following program is submitted:data numrecords;infile cards dlm=',';input agent1 $ agent2 $ agent3 $;cards;jones,,brownjones,spencer,brown;run;What is the value for the variable named Agent2 in the secondobservation?a.Brownb.Spencerc.' ' (missing character value)d.There is no value because only one observation iscreated.Correct answer: dThe CARDS statement enables you to read instream data. Anynumber of consecutive commas are considered to be a singledelimiter as a result of the DLM= option, and the length of eachvariable defaults to 8 bytes. Therefore, the values jones,brownjon, and spencer are assigned to Agent1, Agent2, andAgent3, respectively, for the first observation. The rest of thedata on the record is not read by the INPUT statement and is notoutput to the data set.You can learn about•the CARDS statement in Creating SAS Data Sets fromRaw Data•the default length of variables in Reading Free-FormatData.4. A raw data file is listed below.1---+----10---+----20---+----30---+----40---+----50TWOSTORY 1040 2 1SANDERS ROAD $55,850CONDO 2150 4 2.5JEANS AVENUE $127,150The following program is submitted using this file as input:data work.houses;infile 'file-specification';<insert INPUT statement here>run;Which one of the following INPUT statements reads the rawdata file correctly?a.input @1 style $8.+1 sqfeet 4.+1 bedrooms 1.@20 baths 3.street 16.@40 price dollar8;b.input @1 style $8+1 sqfeet 4.+1 bedrooms 1.@20 baths 3.street $16@40 price dollar8.;c.input @1 style $8.+1 sqfeet 4.+1 bedrooms 1.@20 baths 3.street $16.@40 price dollar8.;d.input @1 style $8.+1 sqfeet 4.+1 bedrooms 1.@20 baths 3street 16.@40 price dollar8.;Correct answer: cFormatted input requires periods as part of the informat name.The period is missing from the variables Style and Street inAnswer b, the variable Baths in Answer d, and the variablePrice in Answer a (which is also missing a dollar sign to readthe variable Street as a character value).You can learn about formatted input and informats in ReadingRaw Data in Fixed Fields.5. The following SAS program is submitted at the start of a newSAS session:libname sasdata 'SAS-data-library';data sasdata.sales;set sasdata.salesdata;profit=expenses-revenues;run;proc print data=sales;run;The SAS data set Sasdata.Salesdata has ten observations.Which one of the following explains why a report fails togenerate?a.The DATA step fails execution.b.The SAS data set Sales does not exist.c.The SAS data set Sales has no observations.d.The PRINT procedure contains a syntax error.Correct answer: bThe DATA step creates a permanent SAS data set,Sasdata.Salesdata. The PRINT procedure is printing atemporary SAS data set, Sales, that is stored in the Worklibrary. At the beginning of the SAS session, Work.Sales doesnot exist.You can learn about•creating permanent data sets with the DATA step inCreating SAS Data Sets from Raw Data•temporary data sets in Basic Concepts.6. Which action assigns a reference named SALES to a permanentSAS data library?a.Issuing the command:libref SALES 'SAS-data-library'b.Issuing the command:libname SALES 'SAS-data-library'c.Submitting the statement:libref SALES 'SAS-data-library';d.Submitting the statement:libname SALES 'SAS-data-library';Correct answer: dThe LIBNAME statement assigns a reference known as a librefto a permanent SAS data library. The LIBNAME commandopens the LIBNAME window.You can learn about the LIBNAME statement in ReferencingFiles and Setting Options.7. The following SAS program is submitted:data newstaff;set staff;<insert WHERE statement here>run;Which one of the following WHERE statements completes theprogram and selects only observations with a Hire_date ofFebruary 23, 2000?a.where hire_date='23feb2000'd;b.where hire_date='23feb2000';c.where hire_date='02/23/2000'd;d.where hire_date='02/23/2000';Correct answer: aA SAS date constant must take the form of one- or two-digitday, three-digit month, and two- or four-digit year, enclosed inquotation marks and followed by a d ('ddmmmyy<yy>'d).You can learn about SAS date constants in Creating SAS DataSets from Raw Data.8. Which one of the following SAS date formats displays the SASdate value for January 16, 2002 in the form of 16/01/2002?a.DATE10.b.DDMMYY10.c.WEEKDATE10.d.DDMMYYYY10.Correct answer: bThe requested output is in day-month-year order and is 10 byteslong, so DDMMYY10. is the correct format. AlthoughWEEKDATE10. is a valid SAS format, it does not display theSAS date value as shown in the question above.DDMMYYYY10. is not a valid SAS date format, and theDATE w. format cannot accept a length of 10.You can learn about•the DDMMYY10. format in Creating List Reports•the WEEKDATE10. format in Reading Date and TimeValues.9. Which one of the following displays the contents of an externalfile from within a SAS session?a.the LIST procedureb.the PRINT procedurec.the FSLIST procedured.the VIEWTABLE windowCorrect answer: cThe PRINT procedure and VIEWTABLE window display thevalues in SAS data sets. The FSLIST procedure displays thevalues in external files. There is no LIST procedure in SAS.You can learn about•the PRINT procedure in Creating List Reports•the VIEWTABLE window in Referencing Files andSetting Options.10. The SAS data set Sashelp.Prdsale contains the variablesRegion and Salary with 4 observations per Region.Sashelp.Prdsale is sorted primarily by Region and withinRegion by Salary in descending order.The following program is submitted:data one;set sashelp.prdsale;retain temp;by region descending salary;if first.region thendo;temp=salary;output;end;if last.region thendo;range=salary-temp;output;end;run;For each region, what is the number of observation(s) written tothe output data set?a.0b.1c. 2d.4Correct answer: cThe expression first.region is true once for each regiongroup. The expression last.region is true once for each regiongroup. Therefore, each OUTPUT statement executes once for atotal of 2 observations in the output data set.You can learn about the FIRST.variable expression and theOUTPUT 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 theCONTENTS procedure.Data Set Name SASUSER.HOUSES Observations15Member Type DATA Variables6Engine V9Indexes0Created Tuesday, April 22,2003 03:09:25 PMObservationLength56Last Modified Tuesday, April 22,2003 03:09:25 PMDeletedObservationsProtection Compressed NO Data Set Type Sorted NOLabel Residential housing for saleDataRepresentationWINDOWS_32Encoding wlatin1 Western (Windows)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: dThe exhibit above shows partial output from the CONTENTSprocedure, In the top right-hand column of the output, you seethat Indexes has a value of 0, which indicates that no indexesexist for this data set. Also, Sorted has a value of NO, whichindicates that the data is not sorted.You can learn about the CONTENTS procedure in ReferencingFiles 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 aresorted?a.The data set Work.Test is stored in ascending order byboth Fname and Salary values.b.The data set Work.Test is stored in descending order byboth Fname and Salary values.c.The data set Work.Test is stored in descending order byFname and ascending order by Salary values.d.The data set Work.Test is stored in ascending order byFname and in descending order by Salary values.Correct answer: dThe DESCENDING keyword is placed before the variable nameit modifies in the BY statement, so the correct description is indescending order by Salary value within ascending Fnamevalues.You can learn about the SORT procedure and theDESCENDING keyword in Creating List Reports.13. The following SAS program is submitted:data names;title='EDU';if title='EDU' thenDivision='Education';else if title='HR' thenDivision='Human Resources';else Division='Unknown';run;Which one of the following represents the value of the variableDivision in the output data set?catiocationc.Human Red.Human ResourcesCorrect answer: bThe length of the variable Division is set to 9 when the DATAstep compiles. Since the value of the variable Title is EDU, thefirst IF condition is true; therefore, the value of the variableDivision is Education.You can learn about•the length of a variable in Understanding DATA StepProcessing•IF-THEN statements in Creating and ManagingVariables.14. Which one of the following SAS programs creates a variablenamed City with a value of Chicago?a.data work.airports;AirportCode='ord';if AirportCode='ORD' City='Chicago';run;b.data work.airports;AirportCode='ORD';if AirportCode='ORD' City='Chicago';run;c.data work.airports;AirportCode='ORD';if AirportCode='ORD' then City='Chicago';run;d.data work.airports;AirportCode='ORD';if AirportCode='ORD';then City='Chicago';run;Correct answer: cThe correct syntax for an IF-THEN statement is: IF expressionTHEN statement;In this example, the variable City is assigned a value ofChicago only if the expression AirportCode='ORD' is true.You can learn about IF-THEN statements in Creating andManaging 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.6b.7c.10d.20Correct answer: aThe DATA step first goes through a compilation phase, then anexecution phase. The length of a variable is set during thecompilation phase and is based on the first time the variable isencountered. In this case, the variable code is set to the lengthof the text string DAL523 which is 6 characters long. The nextassignment statements are ignored during compilation. TheLENGTH statement is also ignored since the length has alreadybeen established, but a note will be written to the log.You can learn about•the compilation phase of the DATA step inUnderstanding DATA Step Processing•the LENGTH statement in Creating and ManagingVariables.16. Which of the following statements creates a numeric variablenamed IDnumber with a value of 4198?a.IDnumber=4198;b.IDnumber='4198';c.length IDnumber=8;d.length IDnumber $ 8;Correct answer: aThe first reference to the SAS variable in the DATA step setsthe name, type, and length of the variable in the program datavector (PDV) and in the output SAS data set. The assignmentstatement IDnumber=4198; is the first reference and creates anumeric variable named IDnumber with a default storage lengthof 8 bytes.You can learn about•creating variables in the DATA step in UnderstandingDATA Step Processing•numeric variables in Basic Concepts.17. The following program is submitted:data fltaten;input jobcode $ salary name $;cards;FLAT1 70000 BobFLAT2 60000 JoeFLAT3 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 thevalue for salary is 30000?a.Under 6b.Under 60c.Over 60d.' ' (missing character value)Correct answer: aThe variable description is being created by the IF-THEN/ELSE statement during compilation. The first occurrenceof the variable description is on the IF statement, and since itis assigned the value Over 60, the length of the variable is 7.Therefore, for the salary value of 30000, description has thevalue of Under 6 (the 0 is truncated.)You can learn about•the compilation phase of the DATA step inUnderstanding DATA Step Processing•IF-THEN/ELSE statements in Creating and ManagingVariables.18. A raw data file is listed below.1---+----10---+----20---+---102320The following program is submitted:data all_sales;infile 'file-specification';input receipts;<insert statement(s) here>run;Which statement(s) complete(s) the program and produce(s) arunning total of the Receipts variable?a.total+receipts;b.total 0;sum total;c.total=total+receipts;d.total=sum(total,receipts);Correct answer: aThe SUM function and the assignment statement do not retainvalues across iterations of the DATA step. The sum statementtotal+receipts; initializes total to 0, ignores missing valuesof receipt, retains the value of total from one iteration to thenext, and adds the value of receipts to total.You can learn about the sum statement in Creating andManaging Variables.19. A raw data file is listed below.1---+----10---+----20---+---1901 21905 11910 61925 11941 1The following SAS program is submitted and references the rawdata file above:data money;infile 'file-specification';input year quantity;total=total+quantity;What is the value of total when the data step finishesexecuting?a.0b.1c.11d. . (missing numeric value)Correct answer: dThe variable Total is assigned a missing value during thecompilation phase of the DATA step. When the first record isread in, SAS processes: total=.+2; which results in a missingvalue. Therefore the variable Total remains missing for allobservations.You can learn about•the compilation phase of the DATA step inUnderstanding DATA Step Processing•using missing values with arithmetic operators inCreating SAS Data Sets from Raw Data.20. The following program is submitted:data test;average=mean(6,4,.,2);run;What is the value of average?a.0b.3c.4d. . (missing numeric value)Correct answer: cThe MEAN function adds all of the non-missing values anddivides by the number of non-missing values. In this case, 6 + 4+ 2 divided by 3 is 4.You can learn about the MEAN function in Transforming Datawith SAS Functions.21. The following SAS program is submitted:data work.AreaCodes;Phonenumber=3125551212;Code='('!!substr(Phonenumber,1,3)!!')';run;Which one of the following is the value of the variable Code inthe output data set?a.( 3)b.(312)c.3d.312Correct answer: aAn automatic data conversion is performed whenever a numericvariable is used where SAS expects a character value. Thenumeric variable is written with the BEST12. format and theresulting character value is right-aligned when the conversionoccurs. In this example, the value of Phonenumber is convertedto character and right-aligned before the SUBSTR function isperformed. Since there are only 10 digits in the value ofPhonenumber, the right-aligned value begins with two blanks.Therefore the SUBSTR function picks up two blanks and a 3,and uses the BEST12. format to assign that value to Code. Then,the parentheses are concatenated before and after the two blanksand a 3.You can learn about automatic data conversion and theSUBSTR function in Transforming Data with SAS Functions.22. The following SAS program is submitted:data work.inventory;products=7;do until (products gt 6);products+1;end;run;Which one of the following is the value of the variableproducts in the output data set?a.5b.6c.7d.8Correct answer: dA DO UNTIL loop always executes at least once because thecondition is not evaluated until the bottom of the loop. In theSAS program above, the value of Products is incremented from7 to 8 on the first iteration of the DO UNTIL loop, before thecondition is checked. Therefore the value of Products is 8.You can learn about DO UNTIL loops in Generating Datawith DO Loops.23. The following program is submitted:data work.test;set work.staff (keep=salary1 salary2 salary3);<insert ARRAY statement here>run;Which ARRAY statement completes the program and createsnew variables?a.array salary{3};b.array new_salary{3};c.array salary{3} salary1-salary3;d.array new_salary{3} salary1-salary3;Correct answer: bAlthough each of the ARRAY statements listed above is a validstatement, only Answer B creates new variables namednew_salary1, new_salary2 and new_salary3. Answer C andAnswer D both create an array that groups the existing data setvariables salary1, salary2, and salary3. Since the array inAnswer A is named salary, it also uses the existing data setvariables.You can learn about creating new variables in an ARRAYstatement in Processing Variables with Arrays.24. Which of the following permanently associates a format with avariable?a.the FORMAT procedureb.a FORMAT statement in a DATA stepc.an INPUT function with format modifiersd.an INPUT statement with formatted style inputCorrect answer: bTo permanently associate a format with a variable, you use theFORMAT statement in a DATA step. You can use theFORMAT procedure to create a user-defined format. You usethe INPUT function to convert character data values to numericvalues with an informat. You use the INPUT statement to readdata into a data set with an informat.You can learn about•permanently assigning a format to a variable in Creatingand Managing Variables•the FORMAT statement in Creating List Reports•the FORMAT procedure in Creating and ApplyingUser-Defined Formats•the INPUT function in Transforming Data with SASFunctions•the INPUT statement in Reading Raw Data in FixedFields.25. The following report is generated:Which of the following steps created the report?a.proc freq data=sasuser.houses;tables style price /nocum;format price dollar10.;label style="Style of homes"price="Asking price";run;b.proc print data=sasuser.houses;class style;var price;table style,n price*mean*f=dollar10.;label style="Style of homes"price="Asking price";run;c.proc means data=sasuser.houses n mean;class style;var price;format price dollar10.;label style="Style of homes"price="Asking price";run;d.proc report data=sasuser.houses nowd headline;column style n price;define style / group "Style of homes";define price / mean format=dollar8."Asking price";run;Correct answer: dThe FREQ procedure cannot create the average asking price.The CLASS statement and the VAR statement are not valid foruse with the PRINT procedure. The MEANS procedure outputwould have both the N statistic and the N Obs statistic since aCLASS statement is used. The REPORT procedure producedYou can learn about•the FREQ procedure in Producing DescriptiveStatistics•the PRINT procedure in Creating List Reports•the MEANS procedure in Producing DescriptiveStatistics•the REPORT procedure in Creating Enhanced List andSummary Reports.26. A SAS report currently flows over two pages because it is toolong to fit within the specified display dimension. Which one ofthe following actions would change the display dimension sothat the report fits on one page?a.Increase the value of the LINENO option.b.Decrease the value of the PAGENO option.c.Decrease the value of the LINESIZE option.d.Increase the value of the PAGESIZE option.Correct answer: dThe PAGESIZE= SAS system option controls the number oflines that compose a page of SAS procedure output. Byincreasing the number of lines available per page, the reportmight fit on one page.You can learn about the PAGESIZE= option in ReferencingFiles and Setting Options.27. Which one of the following SAS REPORT procedure optionscontrols how column headings are displayed over multiplelines?a.SPACE=BEL=d.BREAK=Correct answer: bThe SPLIT= option specifies how to split column headings. TheSPACE=, LABEL= and BREAK= options are not valid optionsin PROC REPORT.You can learn about the SPLIT= option for the REPORTprocedure in Creating Enhanced List and Summary Reports.28. The following SAS program is submitted:ods html file='newfile.html';proc print data=sasuser.houses;run;proc means data=sasuser.houses;run;proc freq data=sasuser.shoes;run;ods html close;proc print data=sasuser.shoes;run;How many HTML files are created?a.1b.2c. 3d.4Correct answer: aBy default, one HTML file is created for each FILE= option orBODY= option in the ODS HTML statement. The ODS HTMLCLOSE statement closes the open HTML file and ends theoutput capture. The Newfile.html file contains the output fromthe PRINT, MEANS, and FREQ procedures.You can learn about the ODS HTML statement in ProducingHTML Output.29. A frequency report of the variable Jobcode in the Work.Actorsdata set is listed below.Jobcode Frequency Percent CumulativeFrequencyCumulativePercentActor I233.33233.33 Actor II233.33466.67 Actor III233.336100.00Frequency Missing = 1The following SAS program is submitted:data work.joblevels;set work.actors;if jobcode in ('Actor I', 'Actor II') thenjoblevel='Beginner';if jobcode='Actor III' thenjoblevel='Advanced';else joblevel='Unknown';run;Which of the following represents the possible values for the variable joblevel in the Work.Joblevels data set?a.Advanced and Unknown onlyb.Beginner and Advanced onlyc.Beginner, Advanced, and Unknownd.' ' (missing character value)Correct answer: aThe DATA step will continue to process those observations that satisfy the condition in the first IF statement Although Joblevel might be set to Beginner for one or more observations, the condition on the second IF statement willevaluate as false, and the ELSE statement will execute and overwrite the value of Joblevel as Unknown.You can learn about•the IF statement in Creating SAS Data Sets from RawData•the ELSE statement in Creating and ManagingVariables.30. The descriptor and data portions of the Work.Salaries data setare shown below.Variable Type Len Posname Char80salary Char816status Char88name status salaryLiz S15,600Herman S26,700Marty S35,000The following SAS program is submitted:proc print data=work.salaries;where salary<20000;run;What is displayed in the SAS log after the program is executed?a.A NOTE indicating that 1 observation is read.b.A NOTE indicating that 0 observations were read.c.A WARNING indicating that character values have beenconverted to numeric values.d.An ERROR indicating that the WHERE clause operatorrequires compatible variables.Correct answer: dSalary is defined as a character variable. Therefore, the valuein the WHERE statement must be the character value 20,000enclosed in quotation marks.You can learn about the WHERE statement in Creating ListReports.31. Which of the following statements is true when SAS encountersa syntax error in a DATA step?a.The SAS log contains an explanation of the error.b.The DATA step continues to execute and the resultingdata set is complete.c.The DATA step stops executing at the point of the errorand the resulting data set contains observations up to thatpoint.d.A note appears in the SAS log indicating that theincorrect statement was saved to a SAS data set forfurther examination.Correct answer: aSAS scans the DATA step for syntax errors during thecompilation phase. If there are syntax errors, those errors getwritten to the log. Most syntax errors prevent further processingof the DATA step.You can learn about how SAS handles syntax errors in theDATA step in Understanding DATA Step Processing.32. Which TITLE statement would display JANE'S DOG as the textof the title?a.title "JANE"S DOG";b.title 'JANE"S DOG';c.title "JANE'S DOG";d.title 'JANE' ' 'S DOG';Correct answer: c。

SAS上机练习题(全部-含参考答案)

SAS上机练习题(全部-含参考答案)

SAS上机练习题(全部-含参考答案)重庆医科大学--卫生统计学统计软件包SAS上机练习题(一)1、SAS常用的窗口有哪三个?请在三个基本窗口之间切换并记住这些命令或功能键。

2、请在PGM窗口中输入如下几行程序,提交系统执行,并查看OUTPUT窗和LOG窗中内容,注意不同颜色的含义;并根据日志窗中的信息修改完善程序。

DATS EX0101;INPUTT NAME $ AGE SEX;CARDS;XIAOMIN 19 1LIDONG 20 1NANA 18 2;PROD PRONT DATS=EX1;RUN;PROC PRINT DATA=EX1;V AR NAME AGE;RUN;3、将第2题的程序、结果及日志保存到磁盘。

4、试根据如下例1的程序完成后面的问题:表1 某班16名学生3门功课成绩表如下问题:1)建立数据集;2)打印至少有1门功课不及格同学的信息;(提示,使用if语句)参考程序:data a;input id sh wl bl;cards;083 68 71 65084 74 61 68085 73 75 46086 79 80 79087 75 71 68084 85 85 87085 78 79 75086 80 76 79087 85 80 82088 77 71 75089 67 73 71080 75 81 70118 70 54 75083 70 66 84084 62 73 65099 82 70 79;run;data b;set a;if sh<60 or wl<60 or bl<60 then output ;run ;proc print data =b;var id sh wl bl;run ;5、根据下列数据建立数据集表2 销售数据开始时间 终止时间费用2005/04/28 25MAY 2009 $123,345,0002005 09 18 05OCT2009 $33,234,5002007/0822SEP2$345,600/12 009200405 08 30JUN2009$432,334,500提示:(格式化输入;数据之间以空格分隔,数据对齐;注意格式后面的长度应以前一个位置结束开始计算,如果读入错误,可试着调整格式的宽度;显示日期需要使用输出格式)开始时间,输入格式yymmdd10.终止时间,输入格式date10.费用,输入格式dollar12.参考程序:data a;input x1 yymmdd10. x2 date10. x3 dollar13.;cards;2005/04/28 25MAY2009 $123,345,0002005 09 18 05OCT2009 $33,234,5002007/08/12 22SEP2009 $345,60020040508 30JUN2009 $432,334,500;run;proc print;run;proc print;format x1 yymmdd10. x2 date9. x3 dollar13.;run;6、手机号码一编码规则一般是:YYY-XXXX-ZZZZ,其YYY为号段;XXXX一般为所在地区编码;ZZZZ 为对应的个人识别编号。

SAS练习题及程序答案

SAS练习题及程序答案

1.随机取组随机取组 有无重复试验的两种有无重复试验的两种 本题是无重复本题是无重复 DATA PGM15G; DO A=1 TO 4; /*A 为窝别*/ DO B=1 TO 3; ; /*B /*B 为雌激素剂量*/ INPUT X @@; X @@; /*X /*X 为子宫重量*/OUTPUT ;END ;END ;CARDS ;106 116 145 42 68 115 70 111 133 42 63 87 ; RUN ;ods html ; /*将结果输出成网页格式,SAS9.0以后版本可用*/ PROC GLM DATA =PGM15G; CLASS A B;MODEL X=A B / X=A B / SS3SS3;MEANS A B; /*给出因素A 、B 各水平下的均值和标准差*/MEANS B / B / SNK SNK ; /*对因素B (即剂量)各水平下的均值进行两两比较*/ RUN ;ODS HTML CLOSE ;2. 2*3析因设计析因设计 两因素两因素 完全随机完全随机 统计方法统计方法 2*3析因设计析因设计 tiff =f 的开方的开方DATA aaa; DO zs=125,200;DO repeat=1 TO 2; ; /*/*每种试验条件下有2次独立重复试验*/ do js=0.015,0.030,0.045; INPUT cl @@; OUTPUT ;END ;END ;END ; CARDS ;2.70 2.45 2.60 2.78 2.49 2.72 2.83 2.85 2.86 2.86 2.80 2.87 ; run ;PROC GLM ;CLASS zs js; MODEL cl=zs js zs*js / cl=zs js zs*js / SS3SS3; MEANS zs*js;LSMEANS zs*js / TDIFF PDIFF ; ; /*/*对 zs 和js 各水平组合而成的试验条件进行均数进行两两比较*/ RUN ;ODS HTML CLOSE ;练习一:2*2横断面研究列链表横断面研究列链表 方法:卡方方法:卡方 矫正卡方矫正卡方 FISHERDATA PGM19A;DO A=1 TO 2; DO B=1 TO 2;INPUT F @@;OUTPUT ;END ;END ;CARDS ; 2 26 8 21 ;run ;PROC FREQ ; WEIGHT F;TABLES A*B / A*B / CHISQ CHISQ ;RUN ;样本大小 = 57练习二:对裂列连表练习二:对裂列连表 结果变量结果变量 换和不换换和不换 三部曲三部曲 1横断面研究横断面研究 P 《0.05 RDATA PGM19B; DO A=1 TO 2; DO B=1 TO 2;INPUT F @@;OUTPUT ;END ;END ;CARDS ; 40 3414 1 19252 ; run ; ods html ;PROC FREQ ; WEIGHT F;TABLES A*B / A*B / CHISQCHISQ cmh ; RUN ;ods html close ;样本大小 = 57练习三:病例对照2*2 病例组中病例组中 有何没有那个基因有何没有那个基因 是正常的3.8倍,倍, 则有可能导致痴呆则有可能导致痴呆 要做前瞻性研究要做前瞻性研究 用对裂用对裂DATA PGM20;DO A=1 TO 2; DO B=1 TO 2;INPUT F @@;OUTPUT ;END ;END ;CARDS ; 240 60 360 340 ;run ; ods html ; PROC FREQ ; WEIGHT F;TABLES A*B / A*B / CHISQ CHISQcmh ; RUN ; ods html close ;总样本大小 = 1000 练习四:配对设计配对设计 隐含金标准2*2 MC 卡方卡方 检验检验 34和0在总体上在总体上((B+C 《40 用矫正卡方) 是否相等是否相等 则可得甲培养基优于乙培养基则可得甲培养基优于乙培养基 一般都用矫正一般都用矫正 因卡方为近似计算因卡方为近似计算DATA PGM19F; INPUT b c;chi=(ABS(b-c)-1)**2/(b+c);p=1-PROBCHI(chi,1);求概率 1减掉从左侧积分到卡方的值减掉从左侧积分到卡方的值 chi=ROUND(chi, 0.001);IF p>0.0001 THEN p=ROUND(p,0.0001);FILEPRINT ; PUT (打印在输出床口) #2 @10'Chisq' @30 'P value'(#表示行) #4 @10 chi @30 p; CARDS ; 34 0 ;run;ods html close;练习五:双向有序R*C列连表列连表用KPA data aaa;do a=1 to 3;do b=1 to 3;input f @@;output;end;end;cards ;58 2 31 42 78 9 17;run;ods html;*简单kappa检验;proc freq data=aaa;weight f;(频数)(频数)tables a*b;test kappa;run ;*加权kappa检验;proc freq;weight f;tables a*b;test wtkap;run ;ods html close;SAS 系统FREQ 过程频数 百分比 行百分比列百分比a *b 表a b 合计1 2 31 5839.4621.3632.046342.8692.06 86.57 3.173.774.7611.112 10.682.001.49 4228.5784.0079.2574.7614.0025.935034.013 85.4423.5311.94 96.1226.4716.981711.5650.0062.963423.13合计 6745.58 5336.052718.37147100.00a *b 表的统计量对称性检验统计量 (S) 2.8561自由度 3Pr > S 0.4144对称性检验指 总体上主对角线的上三角数相加是否与下三角三个数相加 对称性检验与KPA 检验是否一致 是否一个可以代替另一个检验 Pe理论观察一致率 独立假设性基础上计算的 相互独立简单 Kappa 系数Kappa 0.6809渐近标准误差 0.050095% 置信下限 0.583095% 置信上限 0.7788H0 检验: Kappa = 0总体的H0 下的渐近标准误差 0.0597Z 11.4112H0 检验: Kappa = 0单侧 Pr> Z <.0001双侧 Pr>|Z| <.0001总体的KPA是否为0 KPA大于0两种方法的一致性有统计学意义 小于0 不一致性有统计学意义加权的 Kappa 系数加权的 Kappa 0.6614渐近标准误差 0.056095% 置信下限 0.551695% 置信上限 0.7711置信区间不包括0 拒绝H0 按此计算结果可以用一种取代另一种方法 但要看专业要求达到多少才可以 观测一致率达到多少才可以代替样本大小 = 147FREQ 过程频数 百分比 行百分比列百分比a *b 表a b 合计1 2 31 5839.4692.0686.5721.363.173.7732.044.7611.116342.862 10.682.001.494228.5784.0079.2574.7614.0025.935034.013 85.4423.5311.9496.1226.4716.981711.5650.0062.963423.13合计 6745.58 5336.052718.37147100.00a *b 表的统计量对称性检验统计量 (S) 2.8561自由度 3Pr > S 0.4144简单 Kappa 系数Kappa 0.6809渐近标准误差 0.050095% 置信下限 0.583095% 置信上限 0.7788加权的 Kappa 系数加权的 Kappa 0.6614渐近标准误差 0.056095% 置信下限 0.551695% 置信上限 0.7711H0 检验: 加权的 Kappa = 0H0 下的渐近标准误差 0.0646Z 10.2406单侧 Pr> Z <.0001双侧 Pr>|Z| <.0001对加权的KPA 检验 与简单的(利用对角线上的数据分析)加权还要利用对角线以外的数据分析 样本大小 = 147练习六:双向无序R*C 列连表列连表 用卡方理论频数小于5没有超过五分之一,没有超过五分之一,一般用卡方一般用卡方一般用卡方 实在不行用FISHER 检验检验 超过用KPA 两种血型都是按小中大排列两种血型都是按小中大排列 相互不影响相互不影响 独立的独立的 接受H0 不一致不一致行与列变量相互不影响行与列变量相互不影响 DATA PGM20A; DO A=1 TO 4; DO B=1 TO 3;INPUT F @@;OUTPUT ;END ;END ;CARDS ;431 490 902 388 410 800 495 587 950 137 179 325 ; run ; ods html ; PROC FREQ ; WEIGHT F;TABLES A*B / A*B / CHISQCHISQ ;*exact; RUN ;ods html close ;样本大小 = 6094练习七:单向有序R*C 秩和检验秩和检验*方法1;(单因素非参数 HO 三个药物疗效相同 H1不完全相等)不完全相等) DATA PGM20C; DO A=1 TO 4; DO B=1 TO 3; INPUT F @@;OUTPUT ;END ;END ;CARDS ; 15 4 1 49 9 15 31 50 45 5 22 24 ; run ; ods html ;PROC NPAR1WAY WILCOXON ; FREQ FREQ F;CLASS B; VAR A; RUN ;*方法2;(FIQ CHIM ) proc freq data =PGM20C; weight f;tables b*a/ b*a/cmh cmhscores =rank; run ; ods html close ;总样本大小 = 270练习八:练习八: 双向有序双向有序 属性不同属性不同 R*C 4种目的4种方法种方法SPEARMAN 秩相关分析 DATA PGM20E; DO A=1 TO 3; DO B=1 TO 3;INPUT F @@;OUTPUT ;END ;END ;CARDS ; 215 131 148 67 101 128 44 63 132;run ; ods html ; PROC CORR SPEARMAN ;VAR A B; FREQ F; RUN ;ods html close ;统计分析与SAS 实现第1次上机实习题一、定量资料上机实习题要求:要求:(1) 先判断定量资料所对应的实验设计类型;(2) 假定资料满足参数检验的前提条件,请选用相应设计的定量资料的方差分析,并用SAS 软件实现统计计算;(3) 摘录主要计算结果并合理解释,给出统计学结论和专业结论。

SAS综合练习题的(答案)

SAS综合练习题的(答案)

SAS金融数据处理综合练习题1.创建一包含10000个变量(X1-X10000),100个观测值的SAS数据集。

分别用DATA步,DATA步数组语句和IML过程实现。

(1)用data步实现data test1a;informat x1-x10000 9.2; /*创建100个变量,规定输出格*/do i=1to100; /*做循环*/output;/*每一次循环,输出所有的变量,包括i*/drop i;/*去掉i*/end;run;或者data test1a;format x1-x10000 best12.; /*创建10000个变量x1-x10000,但未有初始化*/do i=1to100; /*创建100个观测*/output;/*且每一个观测都输出到数据集test1a*/end;drop i;run;(2)用data步数组语句实现data test1b;array t{10000} x1-x10000 ;/*创建数组变量*/do i =1to100;/*每个变量有100个观测*/output;/*每一次循环,输出所有的变量,包括i*/drop i;/*去掉i*/end;/*循环结束*/data test1c;array t{10000} x1-x10000;do j=1to100;/*100次观测的循环*/do i = 1to10000;t{i}=i;/*第i个变量等于i*/end;output;/*输出第i次观测的i个变量的值*/end;drop i j;/*去掉i和j*/run;或者data test1b;array t{10000} x1-x10000;do j=1to100;/*100次观测的循环*/do i = 1to10000;t{i}=i;/*第i个变量等于i*/end;output;/*输出第i次观测的i个变量的值*/end;drop i j;/*去掉i和j*/run;(3)用IML过程实现proc iml;/*启用iml环境*/x='x1':'x10000';/*定义数组x1-x10000*/t= j(100,10000,1) ;/*创建100行10000列的. 同元素矩阵*/print t x;/*打印两个矩阵察看*/create test1d from t[colname=x];/*创建数据集c,变量数为列数,观测数为行数,列名更改为变量名,默认逻辑库为临时*/append from t; /*将t中的值填充的数据集中*/show datasets;show contents;/*显示数据集的一些7788的属性*/close test1d;run;quit;或者proc iml;x='x1':'x10000';t= shape(1,100,10000) ;/*shape和j不太一样,顺序是元素,行,列,j的顺序为行,列,元素*/print t x;create test1d from t[colname=x];append from t;show datasets;show contents;close test1d;run;quit;(4)用宏实现%macro names(name,number,obs);data a;%do i=1%to &obs;%do n=1%to &number;&name&n=1;%end;output;%end;run;%mend names;%names(x, 10000,100);2.多种方法创建包含变量X的10000个观测值的SAS数据集。

SAS上机练习试题[全部,含参考答案解析]

SAS上机练习试题[全部,含参考答案解析]

重庆医科大学--卫生统计学统计软件包SAS上机练习题(一)1、SAS常用的窗口有哪三个?请在三个基本窗口之间切换并记住这些命令或功能键。

2、请在PGM窗口中输入如下几行程序,提交系统执行,并查看OUTPUT窗和LOG窗中内容,注意不同颜色的含义;并根据日志窗中的信息修改完善程序。

3、将第2题的程序、结果及日志保存到磁盘。

4、试根据如下例1的程序完成后面的问题:表1 某班16名学生3门功课成绩表如下问题:1)建立数据集;2)打印至少有1门功课不及格同学的信息;(提示,使用if语句)参考程序:data a;input id sh wl bl;cards;083 68 71 65084 74 61 68085 73 75 46086 79 80 79087 75 71 68084 85 85 87085 78 79 75086 80 76 79087 85 80 82088 77 71 75089 67 73 71080 75 81 70118 70 54 75083 70 66 84084 62 73 65099 82 70 79;run;data b;set a;if sh<60 or wl<60 or bl<60then output;run;proc print data=b;var id sh wl bl;run;5、根据下列数据建立数据集表2 销售数据开始时间终止时间费用2005/04/28 25MAY2009 $123,345,0002005 09 18 05OCT2009 $33,234,5002007/08/12 22SEP2009 $345,60020040508 30JUN2009 $432,334,500提示:(格式化输入;数据之间以空格分隔,数据对齐;注意格式后面的长度应以前一个位置结束开始计算,如果读入错误,可试着调整格式的宽度;显示日期需要使用输出格式)开始时间,输入格式yymmdd10.终止时间,输入格式date10.费用,输入格式dollar12.参考程序:data a;input x1 yymmdd10. x2 date10. x3 dollar13.;cards;2005/04/28 25MAY2009 $123,345,0002005 09 18 05OCT2009 $33,234,5002007/08/12 22SEP2009 $345,60020040508 30JUN2009 $432,334,500;run;proc print;run;proc print;format x1 yymmdd10. x2 date9. x3 dollar13.;run;6、手机号码一编码规则一般是:YYY-XXXX-ZZZZ,其YYY为号段;XXXX一般为所在地区编码;ZZZZ为对应的个人识别编号。

SAS认证220道_练习题及详细答案(10-9)

SAS认证220道_练习题及详细答案(10-9)

SAS Certificate Base Practice Questions and Detailed Answers Chapter 1: Basic ConceptsChapter 2: Referencing Files and Setting OptionsChapter 3: Editing and Debugging SAS ProgramsChapter 4: Creating List ReportsChapter 5: Creating SAS Data Sets from Raw DataChapter 6: Understanding DATA Step ProcessingChapter 7: Creating and Applying User-Defined FormatsChapter 8: Creating Enhanced List and Summary ReportsChapter 9: Producing Descriptive StatisticsChapter 10: Producing HTML OutputChapter 11: Creating and Managing VariablesChapter 12: Reading SAS Data SetsChapter 13: Combining SAS Data SetsChapter 14: Transforming Data with SAS FunctionsChapter 15: Generating Data with DO LoopsChapter 16: Processing Variables with ArraysChapter 17: Reading Raw Data in Fixed FieldsChapter 18: Reading Free-Format DataChapter 19: Reading Date and Time ValuesChapter 20: Creating a Single Observation from Multiple RecordsChapter 21: Creating Multiple Observations from a Single RecordChapter 22: Reading Hierarchical FilesChapter 1: Basic Concepts Answer Key1.How many observations and variables does the data set below contain?a. 3 observations, 4 variablesb. 3 observations, 3 variablesc. 4 observations, 3 variablesd.can't tell because some values are missingCorrect answer:cRows in the data set are called observations, and columns are called variables. Missing values don't affect the structure of the data set.2.How many program steps are executed when the program below is processed?data user.tables;infile jobs;input date name $ job $;run;proc sort data=user.tables;by name;run;proc print data=user.tables;run;a.threeb.fourc.fived.sixCorrect answer:aWhen it encounters a DATA, PROC, or RUN statement, SAS stops reading statements andexecutes the previous step in the program. The program above contains one DATA step and two PROC steps, for a total of three program steps.3.What type of variable is the variable AcctNum in the data set below?a.numericb.characterc.can be either character or numericd.can't tell from the data shownCorrect answer:bIt must be a character variable, because the values contain letters and underscores, which are not valid characters for numeric values.4.What type of variable is the variable Wear in the data set below?a.numericb.characterc.can be either character or numericd.can't tell from the data shownCorrect answer:aIt must be a numeric variable, because the missing value is indicated by a period rather than by a blank.5.Which of the following variable names is valid?a.4BirthDateb.$Costc._Items_d.Tax-RateCorrect answer:cVariable names follow the same rules as SAS data set names. They can be 1 to 32 characters long, must begin with a letter (A–Z, either uppercase or lowercase) or an underscore, and can continue with any combination of numbers, letters, or underscores.6.Which of the following files is a permanent SAS file?a.Sashelp.PrdSaleb.Sasuser.MySalesc.Profits.Quarter1d.all of the aboveCorrect answer:dTo store a file permanently in a SAS data library, you assign it a libref other than the default Work. For example, by assigning the libref Profits to a SAS data library, you specify that files within the library are to be stored until you delete them. Therefore, SAS files in the Sashelp and Sasuser libraries are permanent files.7.In a DATA step, how can you reference a temporary SAS data set named Forecast?a.Forecastb.Work.Forecastc.Sales.Forecast (after assigning the libref Sales)d.only a and b aboveCorrect answer:dTo reference a temporary SAS file in a DATA step or PROC step, you can specify the one-level name of the file (for example, Forecast) or the two-level name using the libref Work (for example, Work.Forecast).8.What is the default length for the numeric variable Balance?a. 5b. 6c.7d.8Correct answer:dThe numeric variable Balance has a default length of 8. Numeric values (no matter how many digits they contain) are stored in 8 bytes of storage unless you specify a different length.9.How many statements does the following SAS program contain?proc print data=new.prodsalelabel double;var state day price1 price2; where state='NC';label state='Name of State';run;a.threeb.fourc.fived.sixCorrect answer:cThe five statements are•PROC PRINT statement (two lines long)•VAR statement•WHERE statement (on the same line as the VAR statement)•LABEL statement•RUN statement (on the same line as the LABEL statement).10.What is a SAS data library?a. a collection of SAS files, such as SAS data sets and catalogsb.in some operating environments, a physical collection of SAS filesc.in some operating environments, a logically related collection of SAS filesd.all of the aboveCorrect answer:dEvery SAS file is stored in a SAS data library, which is a collection of SAS files, such as SAS data sets and catalogs. In some operating environments, a SAS data library is a physical collection of files. In others, the files are only logically related. In the Windows and UNIX environments, a SAS data library is typically a group of SAS files in the same folder or directory.Chapter 2: Referencing Files and Setting Options1.If you submit the following program, how does the output look?options pagesize=55 nonumber;proc tabulate data=clinic.admit;class actlevel;var age height weight;table actlevel,(age height weight)*mean;run;options linesize=80;proc means data=clinic.heart min max maxdec=1;var arterial heart cardiac urinary;class survive sex;run;a.The PROC MEANS output has a print line width of 80 characters, but the PROCTABULATE output has no print line width.b.The PROC TABULATE output has no page numbers, but the PROC MEANS outputhas page numbers.c.Each page of output from both PROC steps is 55 lines long and has no page numbers,and the PROC MEANS output has a print line width of 80 characters.d.The date does not appear on output from either PROC step.Correct: answer:cWhen you specify a system option, it remains in effect until you change the option or end your SAS session, so both PROC steps generate output that is printed 55 lines per page with no page numbers. If you don't specify a system option, SAS uses the default value for that system option.2.In order for the date values 05May1955 and 04Mar2046 to be read correctly, what value mustthe YEARCUTOFF= option have?a. a value between 1947 and 1954, inclusiveb.1955 or higherc.1946 or higherd.any valueCorrect answer:dAs long as you specify an informat with the correct field width for reading the entire date value, the YEARCUTOFF= option doesn't affect date values that have four-digit years.3.When you specify an engine for a library, you are always specifyinga.the file format for files that are stored in the library.b.the version of SAS that you are using.c.access to other software vendors' files.d.instructions for creating temporary SAS files.Correct answer:aA SAS engine is a set of internal instructions that SAS uses for writing to and reading from files in a SAS library. Each engine specifies the file format for files that are stored in the library, which in turn enables SAS to access files with a particular format. Some engines access SAS files, and other engines support access to other vendors' files.4.Which statement prints a summary of all the files stored in the library named Area51?a.proc contents data=area51._all_ nods;b.proc contents data=area51 _all_ nods;c.proc contents data=area51 _all_ noobs;d.proc contents data=area51 _all_.nods;Correct answer:aTo print a summary of library contents with the CONTENTS procedure, use a period to append the _ALL_ option to the libref. Adding the NODS option suppresses detailed information about the files.5.The following PROC PRINT output was created immediately after PROC TABULATEoutput. Which SAS system options were specified when the report was created?a.OBS=, DATE, and NONUMBERb.PAGENO=1, and DATEc.NUMBER and DATE onlyd.none of the aboveCorrect answer:bClearly, the DATE and PAGENO= options are specified. Because the page number on the output is 1, even though PROC TABULATE output was just produced. If you don't specify PAGENO=, all output in the Output window is numbered sequentially throughout your SAS session.6.Which of the following programs correctly references a SAS data set named SalesAnalysisthat is stored in a permanent SAS library?a.data saleslibrary.salesanalysis;set mydata.quarter1sales;if sales>100000;run;b.data mysales.totals;set sales_99.salesanalysis;if totalsales>50000;run;c.proc print data=salesanalysis.quarter1;var sales salesrep month;run;d.proc freq data=1999data.salesanalysis;tables quarter*sales; run;Correct answer:bLibrefs must be 1 to 8 characters long, must begin with a letter or underscore, and can contain only letters, numbers, or underscores. After you assign a libref, you specify it as the first element in the two-level name for a SAS file.7.Which time span is used to interpret two-digit year values if the YEARCUTOFF= option isset to 1950?a.1950-2049b.1950-2050c.1949-2050d.1950-2000Correct answer:aThe YEARCUTOFF= option specifies which 100-year span is used to interpret two-digit year values. The default value of YEARCUTOFF= is 1920. However, you can override the default and change the value of YEARCUTOFF= to the first year of another 100-year span. If you specify YEARCUTOFF=1950, then the 100-year span will be from 1950 to 2049.8.Asssuming you are using SAS code and not special SAS windows, which one of thefollowing statements is false?a.LIBNAME statements can be stored with a SAS program to reference the SAS libraryautomatically when you submit the program.b.When you delete a libref, SAS no longer has access to the files in the library.However, the contents of the library still exist on your operating system.c.Librefs can last from one SAS session to another.d.You can access files that were created with other vendors' software by submitting aLIBNAME statement.Correct answer:cThe LIBNAME statement is global, which means that librefs remain in effect until you modify them, cancel them, or end your SAS session. Therefore, the LIBNAME statement assigns the libref for the current SAS session only. You must assign a libref before accessingSAS files that are stored in a permanent SAS data library.9.What does the following statement do?libname osiris spss 'c:\myfiles\sasdata\data';a.defines a library called Spss using the OSIRIS engineb.defines a library called Osiris using the SPSS enginec.defines two libraries called Osiris and Spss using the default engined.defines the default library using the OSIRIS and SPSS enginesCorrect answer:bIn the LIBNAME statement, you specify the library name before the engine name. Both are followed by the path.10.What does the following OPTIONS statement do?options pagesize=15 nodate;a.suppresses the date and limits the page size of the logb.suppresses the date and limits the vertical page size for text outputc.suppresses the date and limits the vertical page size for text and HTML outputd.suppresses the date and limits the horizontal page size for text outputCorrect answer:bThese options affect the format of listing output only. NODATE suppresses the date and PAGESIZE= determines the number of rows to print on the page.Chapter 3: Editing and Debugging SAS Programs Answer Key1.As you write and edit SAS programs it's a good idea toa.begin DATA and PROC steps in column one.b.indent statements within a step.c.begin RUN statements in column one.d.all of the aboveCorrect answer:dAlthough you can write SAS statements in almost any format, a consistent layout enhances readability and enables you to understand the program's purpose. It's a good idea to begin DATA and PROC steps in column one, to indent statements within a step, to begin RUN statements in column one, and to include a RUN statement after every DATA step or PROC step.2.What usually happens when an error is detected?a.SAS continues processing the step.b.SAS continues to process the step, and the log displays messages about the error.c.SAS stops processing the step in which the error occurred, and the log displaysmessages about the error.d.SAS stops processing the step in which the error occurred, and the program outputdisplays messages about the error.Correct answer:cSyntax errors generally cause SAS to stop processing the step in which the error occurred. When a program that contains an error is submitted, messages regarding the problem also appear in the SAS log. When a syntax error is detected, the SAS log displays the word ERROR, identifies the possible location of the error, and gives an explanation of the error.3. A syntax error occurs whena.some data values are not appropriate for the SAS statements that are specified in aprogram.b.the form of the elements in a SAS statement is correct, but the elements are not validfor that usage.c.program statements do not conform to the rules of the SAS language.d.none of the aboveCorrect canswer:Syntax errors are common types of errors. Some SAS system options, features of the Editorwindow, and the DATA step debugger can help you identify syntax errors. Other types oferrors include data errors, semantic errors, and execution-time errors.4.How can you tell whether you have specified an invalid option in a SAS program?a. A log message indicates an error in a statement that seems to be valid.b. A log message indicates that an option is not valid or not recognized.c.The message "PROC running" or "DATA step running" appears at the top of theactive window.d.You can't tell until you view the output from the program.Correct answer:bWhen you submit a SAS statement that contains an invalid option, a log message notifies you that the option is not valid or not recognized. You should recall the program, remove or replace the invalid option, check your statement syntax as needed, and resubmit the corrected program.5.Which of the following programs contains a syntax error?Correct answer:bThe DATA step contains a misspelled keyword (dat instead of data). However, this is such a common (and easily interpretable) error that SAS produces only a warning message, not an error.6.What does the following log indicate about your program?proc print data=sasuser.cargo99var origin dest cargorev;2276ERROR 22-322: Syntax error, expecting one of the following:;, (, DATA, DOUBLE, HEADING, LABEL, N, NOOBS, OBS, ROUND, ROWS, SPLIT, STYLE,UNIFORM, WIDTH.ERROR 76-322: Syntax error, statement will be ignored.11 run;a.SAS identifies a syntax error at the position of the VAR statement.b.SAS is reading VAR as an option in the PROC PRINT statement.c.SAS has stopped processing the program because of errors.d.all of the aboveCorrect answer:dBecause there is a missing semicolon at the end of the PROC PRINT statement, SAS interprets VAR as an option in PROC PRINT and finds a syntax error at that location. SAS stops processing programs when it encounters a syntax error.Chapter 4: Creating List Reports Answer Key 1.Which PROC PRINT step below creates the following output?Correct answer:cThe DATA= option specifies the data set that you are listing, and the ID statement replaces the Obs column with the specified variable. The VAR statement specifies variables and controls the order in which they appear, and the WHERE statement selects rows based on a condition. The LABEL option in the PROC PRINT statement causes the labels that are specified in the LABEL statement to be displayed.2.Which of the following PROC PRINT steps is correct if labels are not stored with thedata set?Correct aanswer:You use the DATA= option to specify the data set to be printed. The LABEL optionspecifies that variable labels appear in output instead of variable names.3.Which of the following statements selects from a data set only those observations forwhich the value of the variable Style is RANCH, SPLIT, or TWOSTORY?Correct answer:dIn the WHERE statement, the IN operator enables you to select observations based on several values. You specify values in parentheses and separate them by spaces or commas. Character values must be enclosed in quotation marks and must be in the same case as in the data set.4.If you want to sort your data and create a temporary data set named Calc to store thesorted data, which of the following steps should you submit?Correct answer:cIn a PROC SORT step, you specify the DATA= option to specify the data set to sort. The OUT= option specifies an output data set. The required BY statement specifies the variable(s) to use in sorting the data.5.Which options are used to create the following PROC PRINT output?13:27 Monday, March 22, 1999 Patient Arterial Heart Cardiac Urinary203 88 95 66 11054 83 183 95 0664 72 111 332 12210 74 97 369 0101 80 130 291 0a.the DATE system option and the LABEL option in PROC PRINTb.the DATE and NONUMBER system options and the DOUBLE and NOOBSoptions in PROC PRINTc.the DATE and NONUMBER system options and the DOUBLE option inPROC PRINTd.the DATE and NONUMBER system options and the NOOBS option in PROCPRINTCorrect answer:bThe DATE and NONUMBER system options cause the output to appear with the date but without page numbers. In the PROC PRINT step, the DOUBLE option specifies double spacing, and the NOOBS option removes the default Obs column.6.Which of the following statements can you use in a PROC PRINT step to create thisoutput?Correct answer:dYou do not need to name the variables in a VAR statement if you specify them in the SUM statement, but you can. If you choose not to name the variables in the VAR statement as well, then the SUM statement determines the order of the variables in the output.7.What happens if you submit the following program?proc sort data=clinic.diabetes;run;proc print data=clinic.diabetes;var age height weight pulse;where sex='F';run;a.The PROC PRINT step runs successfully, printing observations in their sortedorder.b.The PROC SORT step permanently sorts the input data set.c.The PROC SORT step generates errors and stops processing, but the PROCPRINT step runs successfully, printing observations in their original (unsorted)order.d.The PROC SORT step runs successfully, but the PROC PRINT step generateserrors and stops processing.Correct answer:cThe BY statement is required in PROC SORT. Without it, the PROC SORT step fails. However, the PROC PRINT step prints the original data set as requested.8.If you submit the following program, which output does it create?proc sort data=finance.loans out=work.loans;by months amount;run;proc print data=work.loans noobs; var months;sum amount payment;where months<360;run;a.b.c.d.Correct answer:aColumn totals appear at the end of the report in the same format as the values of the variables, so b is incorrect. Work.Loans is sorted by Month and Amount, so c isincorrect. The program sums both Amount and Payment, so d is incorrect.9.Choose the statement below that selects rows which•the amount is less than or equal to $5000•the account is 101-1092 or the rate equals 0.095.Correct answer:cTo ensure that the compound expression is evaluated correctly, you can use parentheses to groupaccount='101-1092' or rate eq 0.095OBS Account Amount Rate MonthsPayment1 101-1092 $22,000 10.00%60 $467.432 101-1731 $114,0009.50% 360 $958.573 101-1289 $10,000 10.50%36 $325.024 101-3144 $3,500 10.50%12 $308.525 103-1135 $8,700 10.50%24 $403.476 103-1994 $18,500 10.00%60 $393.077 103-2335 $5,000 10.50%48 $128.028 103-3864 $87,500 9.50% 360 $735.759 103-3891 $30,000 9.75% 360 $257.75For example, from the data set above, a and b above select observations 2 and 8 (those that have a rate of 0.095); c selects no observations; and d selects observations 4 and 7 (those that have an amount less than or equal to 5000).10.What does PROC PRINT display by default?a.PROC PRINT does not create a default report; you must specify the rows andcolumns to be displayed.b.PROC PRINT displays all observations and variables in the data set. If youwant an additional column for observation numbers, you can request it.c.PROC PRINT displays columns in the following order: a column forobservation numbers, all character variables, and all numeric variables.d.PROC PRINT displays all observations and variables in the data set, a columnfor observation numbers on the far left, and variables in the order in which they occur in the data set.Correct answer:dYou can remove the column for observation numbers. You can also specify the variables you want, and you can select observations according to conditions.Chapter 5: Creating SAS Data Sets from Raw Data Answer Key1.Which SAS statement associates the fileref Crime with the raw data fileC:\States\Data\Crime?a.filename crime 'c:\states\data\crime';b.filename crime c:\states\data\crime;c.fileref crime 'c:\states\data\crime';d.filename 'c:\states\data\crime' crime; Correct aanswer:Before you can read your raw data, you must reference the raw data file by creating afileref. You assign a fileref by using a FILENAME statement in the same way thatyou assign a libref by using a LIBNAME statement.2.Filerefs remain in effect untila.you change them.b.you cancel them.c.you end your SAS session.d.all of the aboveCorrect answer:dLike LIBNAME statements, FILENAME statements are global; they remain in effect until you change them, cancel them, or end your SAS session.3.Which statement identifies the name of a raw data file to be read with the filerefProducts and specifies that the DATA step read only records 1-15?a.infile products obs 15;b.infile products obs=15;c.input products obs=15;d.input products 1-15;Correct answer:bYou use an INFILE statement to specify the raw data file to be read. You can specify a fileref or an actual filename (in quotation marks). The OBS= option in the INFILE statement enables you to process only records 1 through n.4.Which of the following programs correctly writes the observations from the data setbelow to a raw data file?Correct answer:dThe keyword _NULL_ in the DATA statement enables you to use the power of the DATA step without actually creating a SAS data set. You use the FILE and PUT statements to write out the observations from a SAS data set to a raw data file. The FILE statement specifies the raw data file and the PUT statement describes the lines towrite to the raw data file. The filename and location that are specified in the FILE statement must be enclosed in quotation marks.5.Which raw data file can be read using column input?a.b.c.d.all of the aboveCorrect answer:bColumn input is appropriate only in some situations. When you use column input, your data must be standard character or numeric values, and they must be in fixed fields. That is, values for a particular variable must be in the same location in all records.6.Which program creates the output shown below?Correct answer:aThe INPUT statement creates a variable using the name that you assign to each field. Therefore, when you write an INPUT statement, you need to specify the variable names exactly as you want them to appear in the SAS data set.7.Which statement correctly reads the fields in the following order: StockNumber,Price, Item, Finish, Style?Field Name Start Column End Column Data TypeStockNumber 1 3 characterFinish 5 9 characterStyle 11 18 characterItem 20 24 characterPrice 27 32 numericCorrec t answer:bYou can use column input to read fields in any order. You must specify the variable name to be created, identify character values with a $, and name the correct starting column and ending column for each field.8.Which statement correctly re-defines the values of the variable Income as 100percent higher?a.income=income*1.00;b.income=income+(income*2.00);c.income=income*2;d.income=*2;Correct answer:cTo re-define the values of the variable Income in an Assignment statement, you specify the variable name on the left side of the equal sign and an appropriate expression including the variable name on the right side of the equal sign.9.Which program correctly reads instream data?a.data finance.newloan;input datalines;if country='JAPAN';MonthAvg=amount/12;1998 US CARS 194324.121998 US TRUCKS 142290.301998 CANADA CARS 10483.441998 CANADA TRUCKS 93543.641998 MEXICO CARS 22500.571998 MEXICO TRUCKS 10098.881998 JAPAN CARS 15066.431998 JAPAN TRUCKS 40700.34;b.data finance.newloan;input Year 1-4 Country $ 6-11Vehicle $ 13-18 Amount 20-28;if country='JAPAN';MonthAvg=amount/12;datalines;run;c.data finance.newloan;input Year 1-4 Country 6-11Vehicle 13-18 Amount 20-28;if country='JAPAN';MonthAvg=amount/12;datalines;1998 US CARS 194324.121998 US TRUCKS 142290.301998 CANADA CARS 10483.441998 CANADA TRUCKS 93543.641998 MEXICO CARS 22500.571998 MEXICO TRUCKS 10098.881998 JAPAN CARS 15066.431998 JAPAN TRUCKS 40700.34;d.data finance.newloan;input Year 1-4 Country $ 6-11Vehicle $ 13-18 Amount 20-28;if country='JAPAN';MonthAvg=amount/12;datalines;1998 US CARS 194324.121998 US TRUCKS 142290.301998 CANADA CARS 10483.441998 CANADA TRUCKS 93543.641998 MEXICO CARS 22500.571998 MEXICO TRUCKS 10098.881998 JAPAN CARS 15066.431998 JAPAN TRUCKS 40700.34;Correct answer:dTo read instream data, you specify a DATALINES statement and data lines, followed by a null statement (single semicolon) to indicate the end of the input data. Program a contains no DATALINES statement, and the INPUT statement doesn't specify the fields to read. Program b contains no data lines, and the INPUT statement in program c doesn't specify the necessary dollar signs for the character variables Country and Vehicle.10.Which SAS statement subsets the raw data shown below so that only the observationsin which Sex (in the second field) has a value of F are processed?a.if sex=f;b.if sex=F;c.if sex='F';d. a or bCorrect answer:cTo subset data, you can use a subsetting IF statement in any DATA step to process only those observations that meet a specified condition. Because Sex is a character variable, the value F must be enclosed in quotation marks and must be in the same case as in the data set.Chapter 6: Understanding DATA Step Processing Answer Key1.Which of the following is not created during the compilation phase?。

SAS上机实习考试21

SAS上机实习考试21

1、为比较两种方法对乳酸饮料中脂肪含量测定结果是否不同,某人随机抽取了10份乳酸饮料制品,分别用脂肪酸水解法和哥特里-罗紫法测定其结果如表3-3第(1)~(3)栏。

问两法测定结果是否不同?表两种方法对乳酸饮料中脂肪含量的测定结果(%)编号(1) 哥特里-罗紫法(2)脂肪酸水解法(3)1 0.840 0.5802 0.591 0.5093 0.674 0.5004 0.632 0.3165 0.687 0.3376 0.978 0.5177 0.750 0.4548 0.730 0.5129 1.200 0.99710 0.870 0.5062、为研究国产四类新药阿卡波糖胶囊的降血糖效果,某医院用20名II型糖尿病病人进行同期随机对照试验。

试验者将这些病人随机等分到试验组(用阿卡波糖胶囊)和对照组(用拜唐苹胶囊),分别测得试验开始前和8周后的空腹血糖,算得空腹血糖下降值见表3-4,能否认为该国产四类新药阿卡波糖胶囊与拜唐苹胶囊对空腹血糖的降糖效果不同?表3-4 试验组和对照组空腹血糖下降值(mmol/L)试验组(n1=10)-0.70 -5.60 2.00 2.80 0.70 3.50 4.00 5.80 7.10 -0.50对照组(n2=10)3.70 6.50 5.00 5.20 0.80 0.20 0.60 3.40 6.60 -1.103. 两组肿瘤患者,单纯放疗组(A)13 例,口服平消胶囊+放疗组(B)12 例,接受放疗前后,血清Sil-2R水平(U/ml)如表所示。

试评价平消胶囊对接受放疗患者血清Sil-2R水平的影响?两组肿瘤患者的血清Sil-2R水平A组 No. 1 2 3 4 5 6 7治疗前 1183.03 822.52 1294.00 852.50 568.89 532.12 896.36治疗后 983.08 469.34 704.39 979.66 1040.33 895.93 612.27No. 8 9 10 11 12 13治疗前 530.46 808.22 375.44 1055.26 614.55 450.22治疗后 616.70 870.14 1245.54 1753.67 1850.56 538.45B组 No. 1 2 3 4 5 6 7治疗前 992.85 767.33 645.85 709.54 995.41 1043.40 1022.76治疗后 236.66 293.00 166.77 204.81 127.27 186.63 200.80No. 8 9 10 11 12治疗前 486.27 694.28 871.44 973.73 1063.76治疗后 151.47 254.49 178.09 147.19 111.224.大量研究显示汉族足月正常产男性新生儿临产前双顶径(BPD)均数为9.3cm。

SAS上机练习题(二)参考答案

SAS上机练习题(二)参考答案

6$6Ϟ 㒗д乬˄Ѡ˅㄀1乬data a;input x@@;cards;142.3 148.8 142.7 144.4 144.7 145.1 143.3 154.2 152.3 142.7 156.6 137.9 143.9 141.2 139.3 145.8 142.2 137.9 141.2 150.6 142.7 151.3 142.4 141.5 141.9 147.9 125.8 139.9 148.9 154.9 145.7 140.8 139.6 148.8 147.8 146.7 132.7 149.7 154.0 158.2 138.2 149.8 151.1 140.1 140.5 143.4 152.9 147.5 147.7 162.6 141.6 143.6 144.0 150.6 138.9 150.8 147.9 136.9 146.5 130.6 142.5 149.0 145.4 139.5 148.9 144.5 141.8 148.1 145.4 134.6 130.5 145.2 146.2 146.4 142.4 137.1 141.4 144.0 129.4 142.8 132.1 141.8 143.3 143.8 134.7 147.1 140.9 137.4 142.5 146.6 135.5 146.8 156.3 150.0 147.3 142.9 141.4 134.7 138.5 146.6 134.5 135.1 141.9 142.1 138.1 134.9 146.7 138.5 139.6 139.2 148.8 150.3 140.7 143.5 140.2 143.6 138.7 138.9 143.5 139.9 134.4 133.1 145.9 139.2 137.4 142.3 160.9 137.7 142.9 126.8;proc means data=a n mean median clm qrange std cv stderr maxdec=2;var x;proc univariate data=a normal;histogram x;var x;run;Џ㽕㒧The MEANS ProcedureAnalysis Variable : xN Mean Median Lower 95%CL for MeanUpper 95%CL for MeanQuartileRangeStdDevCoeff ofVariationStdError՟ Ёԡ 95%䯈ϟ䰤95%䯈Ϟ䰤ԡ 䯈䎱㋏ 䇃130 143.22142.75142.10144.337.80 6.43 4.490.56乥⿄㄀2乬data a2;do grp='⬆㒘','Э㒘';input id before after @@;cha=before-after;output;end;cards;1 6.11 6.00 1 6.90 6.932 6.81 6.83 2 6.40 6.353 6.48 4.49 3 6.48 6.414 7.59 7.28 4 7.00 7.105 6.42 6.30 5 6.53 6.416 6.94 6.64 6 6.70 6.687 9.17 8.42 7 9.10 9.058 7.33 7.00 8 7.31 6.839 6.94 6.58 9 6.96 6.9110 7.67 7.22 10 6.81 6.7311 8.15 6.57 11 8.16 7.6512 6.60 6.17 12 6.98 6.52;/* 䗄 㒳䅵*/proc means n mean std maxdec=2;class grp;var before after cha;run;proc ttest data=a2; /*ϸ㒘 䆩㗙䆩偠 㸔⏙㚚 䝛∈ Ⳍㄝ*/class grp;var before;proc ttest data=a2; /*⬆㒘䰡㚚 䝛 */paired before*after;where grp='⬆㒘'; /* ⬆㒘ⱘ ˈⳌ ѢDataℹЁⱘif䇁 */ run;proc ttest data=a2; /*Э㒘䰡㚚 䝛 */paired before*after;where grp='Э㒘';run;proc ttest data=a2; /*ϸ⾡䰡㚚 䝛 ⱘ Ⳍ ˈ⫼ */ class grp;var cha;run;Џ㽕㒧䗄 㒧grp N Obs V ariableN Mean Std Dev⬆㒘12 b efore after cha1212127.186.630.560.860.930.61 Э㒘12 b efore after cha1212127.116.960.150.780.750.21ϸ㒘 䆩㗙䆩偠 㸔⏙㚚 䝛∈ ⳌㄝT-TestsVariable Method Variances DF t ValuePr > |t|before PooledEqual220.220.8288beforeSatterthwaite Unequal21.80.220.8288唤 Ẕ偠Equality of VariancesVariable Method Num DFDen DFF ValuePr > F beforeFolded F11111.210.7525Equality of VariancesVariable Method Num DFDen DFF ValuePr > F chaFolded F11118.410.0014㄀3乬data a3;input x@@;if _n_<=11then grp='0 ';else if _n_<=20then grp='1 ';else grp='2 ';cards;8.0 9.0 5.8 6.3 5.4 8.5 5.6 5.4 5.5 7.2 5.6 8.5 4.3 11.0 9.0 6.7 9.0 10.5 7.7 7.711.3 7.0 9.5 8.5 9.6 10.8 9.0 12.6 13.9 6.5;/* 䗄 㒳䅵*/proc means n mean median std p25p75maxdec=2;class grp;var x;run;/*⾽ Ẕ偠ˈHẔ偠*/proc npar1way wilcoxon;class grp;var x;run;Kruskal-Wallis TestChi-Square 11.0991DF 2Pr > Chi-Square 0.0039㸼;; ⮒⮙ϡ 㸔⏙䪰㪱㲟ⱑ 䞣˄­mol/L˅՟ Ёԡ P25-p750 11 6.57 5.80 1.36 5.5-8.91 9 8.27 8.50 2.01 7.7-9.02 10 9.87 9.55 2.33 8.5-11.3Kruskal-Wallis Test˖H=11.0991ˈP=0.0039ㅔ㽕䇈䆹⮒⮙ ǃ ǃ 㸔⏙䪰㪱㲟ⱑ 䞣 ˄Ёԡ ˅ Ў˖ ˄ ˅ǃ ˄ ˅ǃ ˄ ˅ˈϡ ⏙䪰㪱㲟ⱑ 䞣ϡ ˄+ ˈ3 ˅ˈ 䞣䕗Ԣˈ 䞣䕗催DŽproc format ;value sexf 1='⬋'2=' ';value $ques1f 'A'=' ''B'='ϡ ''C'=' ';run ;data a;input id $ sex height weight money ques1$ ques2$;/*䅵ㅫBMI*/bmi=weight/((height/100)**2);/* ↡䕀 ↡*/ques1=upcase(ques1);/* A ǃB ǃC 䕀 ㄝ㑻 䞣ˈ ϔϾ 䞣Ёq Ё*/if ques1='A'then q=1;if ques1='B'then q=2;if ques1='C'then q=3;/* BMI ㄝ㑻 ˈ㒧 ϔϾ 䞣bmigrp Ё*/if bmi<18then bmigrp=" ⯺";else if bmi<25then bmigrp="ℷ ";else if bmi=<30then bmigrp="䍙䞡";else if bmi=<35then bmigrp="䕏 㙹㚪";else if bmi=<40then bmigrp="Ё 㙹㚪";else if bmi>40then bmigrp="䞡 㙹㚪";cards ;cnw1l01 1 179 70 5.7 a ABD EF cnw1l02 1 175 70 7.5 a ABE cnw1l03 2 157 47 4.5 a ABE cnw1l04 2 163 48 5 c AB DF cnw1l05 2 161 52 5 b ABF …………………………………………w7l03 1 175 66 10 A ABC EF cnw7l04 2 163 51 8 B AB D cnw7l05 2 165 57 4.9 A ABD cnw8l01 1 160 60 10 B ABE cnw8l02 2 154 50 4.3 A BE cnw8l03 2 160 60 7 A AB DEF ;run ;/*䅵ㅫ乥 ⱒ ↨*/proc freq data =a;tables sex ques1 bmigrp;format sex sexf. ques1 $ques1f.;run ;/*䅵ㅫϡ 㑻ⱘ ˄乥 ↨˅*/ proc freq data=a;tables sex*ques1;format sex sexf. ques1 $ques1f.;run;/* 䖯㸠⾽ Ẕ偠*/proc npar1way wilcoxon data =a;class sex;var q;format sex sexf.;run;/* 䗄⬋ ⫳ⱘBMI */proc means n mean std median p25p75maxdec=2;class sex;var bmi;format sex sexf.;run;/*↨䕗⬋ ⫳BMIⱘ */proc ttest;class sex;var bmi;format sex sexf.;run;Џ㽕㒧sex Frequency Percent CumulativeFrequencyCumulativePercent⬋ 5541.045541.047958.96134100.00Ϟ㸼 ⧚ 㒳䅵㸼( 乬⬹)՟ ⱒ ↨˄%˅⬋ 55 41.0479 58.96䅵 134 100.00ques1Frequency Percent CumulativeFrequencyCumulativePercent3425.373425.37ϡ 6145.529570.903929.10134100.00Ϟ㸼 ⧚ 㒳䅵㸼( 乬⬹)՟ ⱒ ↨˄%˅34 25.37ϡ 61 45.5239 29.10䅵 134 100.00bmigrp Frequency Percent CumulativeFrequencyCumulativePercent䍙䞡 10.7510.75⯺ 1511.191611.94ℷ 11888.06134100.00Ϟ㸼 ⧚ 㒳䅵㸼( 乬⬹)՟ ⱒ ↨˄%˅䍙䞡 1 0.75⯺ 15 11.19ℷ 118 88.06䅵 134 100.00FrequencyPercent Row Pct Col PctTable of sex by ques1ques1sex ϡ Total ⬋1611.9429.0947.062518.6645.4540.981410.4525.4535.905541.041813.4322.7852.943626.8745.5759.022518.6631.6564.107958.96Total3425.376145.523929.10134100.00⾽ Ẕ偠㒧Wilcoxon Scores (Rank Sums) for Variable qClassified by Variable sexsex N Sum ofScoresExpectedUnder H0Std DevUnder H0MeanScore⬋ 553515.03712.50205.59375063.909091795530.05332.50205.59375070.000000Wilcoxon Two-Sample TestStatistic 3515.0000Normal ApproximationZ -0.9582One-Sided Pr < Z 0.1690Two-Sided Pr > |Z| 0.3380t ApproximationOne-Sided Pr < Z 0.1699Two-Sided Pr > |Z| 0.3397Ϟ䴶ϝϾ㸼 ⧚ 㒳䅵㸼( 乬⬹)⚭ (%)ϡ (%) (%)刧⬋16(29.09) 25(45.45) 14(25.45) 5518(22.78) 36(45.57) 25(31.65) 79䅵34(25.37) 61(45.52) 39(29.10) 134Wilcoxon⾽ Ẕ偠: Z=0.9582ˈP=0.3380ㅔ㽕䇈 ˖29.09%ⱘ⬋⫳㸼⼎ д㣅䇁ⱘ⿃ Ӯ ˈ45.45%ⱘ㸼⼎ϡ ˈ25.45%ⱘ 㸼⼎⿃ Ӯ ˗㗠 ⫳ Ў˖ ˄22.78%˅ǃϡ ˄45.57%˅ǃ ˄31.65%˅DŽ⬋ ⫳ 㑻 䴽 д㣅䇁ⱘ⿃ ≵ ϡ ˄Z=0.9582ˈP=0.3380˅DŽ⬋ ⫳BMI↨䕗Analysis Variable : bmisex N Obs N Mean Std Dev Median25th Pctl75th Pctl⬋ 5555 21.01 2.0020.9619.8122.497979 19.77 1.5019.5618.8221.05 tẔ偠㒧T-TestsVariable Method Variances DF t Value Pr > |t|bmi Pooled Equal 132 4.09 <.0001bmi Satterthwaite Unequal 94.3 3.89 0.0002 唤 Ẕ偠Equality of VariancesVariable Method Num DF Den DF F Value Pr > Fbmi Folded F 5478 1.790.0186Ϟ䴶ϝϾ㸼 ⧚ 㒳䅵㸼( 乬⬹)Ёԡ P25-P75⯶⬋ 55 21.01 2.00 20.96 19.81-22.4979 19.77 1.50 19.56 18.82-21.05Satterthwaite t’Ẕ偠˖t’=3.89ˈP=0.0002ㅔ㽕䇈 ˖䇗 ⬋⫳55ҎˈBMI Ў21.01ˈЁԡ 20.96ˈ 2.00ˈ50%ⱘҎBMI䲚Ё 19.81-22.49П䯈˗䇗 ⫳79ҎˈBMI Ў19.77ˈЁԡ 19.57ˈ 1.50ˈ50%ⱘ ⫳BMI䲚Ё 18.82-21.05П䯈DŽ⬋ ⫳BMI ϡ ˈ⬋⫳BMI催Ѣ ⫳˄t’=3.89ˈP=0.0002˅DŽP132˖˄tẔ偠˅㄀2data a;input id control treat;cards;1 0.3550 0.27552 0.2000 0.25453 0.3130 0.18004 0.3630 0.18005 0.3544 0.31136 0.3450 0.29557 0.3050 0.2870;/* 䗄 㒳䅵*/proc means n mean std maxdec=4;var control treat;run;/*䜡 tẔ偠*/proc ttest;paired control*treat;run;Џ㽕㒧Variable N Mean Std Devcontrol treat 770.31930.25480.05710.0540 T-TestsDifference DF t Value Pr > |t|control - treat 6 2.200.0697⧚ 㒳䅵㸼㒘 ՟✻㒘 7 0.3193 0.0571䆩偠㒘7 0.25480.0540䜡 tẔ偠˖t=2.20ˈP=0.0697ㅔ㽕䇈 ˖㛥㔎⇻῵ 㒘˄䆩偠㒘˅㛥㒘㒛䩭⋉ⱘ 䞣 Ў0.2548ˈ ✻㒘 Ў0.3193ˈ 90%ⱘ ˄D=0.10˅䅸Ў㛥㔎⇻Ӯ䗴 㛥㒘㒛䩭⋉ 䞣䰡Ԣ˄t=2.20ˈP=0.0697˅DŽ(⊼ ˖ℸ㒧䆎 䖒 䗮 ⱘ95%ⱘ (D=0.05))P149㄀1乬data a;input grp$ @@;do i=1to4;input x@@;output;end;cards;0⬆17 16 16 151Э10 11 12 122ϭ11 9 8 9;/* 䗄 㒳䅵*/proc means n mean std maxdec=1;var x;class grp;run;/* */proc glm;class grp;model x=grp;means grp/snk hovtest;/*䗝乍hovtestˈ㽕∖䕧 Levene 唤 Ẕ偠㒧 */run; /* 唤 Ẕ偠Ⳃ 䩜 one-way ANOVA῵ */quit;Џ㽕㒧grp N Obs N Mean Std Dev0⬆ 4416.00.81Э 4411.3 1.02ϭ 449.3 1.3Source DF Type III SS Mean Square F Value Pr > Fgrp 296.1666666748.0833333345.55 <.0001Levene's Test for Homogeneity of x VarianceANOVA of Squared Deviations from Group Means Source DF Sum of Squares Mean Square F Value Pr > Fgrp2 1.01040.50520.540.5990Error98.37500.9306Levene 唤 Ẕ偠˖F=0.54ˈP=0.5990䇈 ϝ㒘䯈 ԧ 唤 DŽϸϸ↨䕗㒧Means with the same letterare not significantly different.SNK Grouping Mean NgrpA 16.000040⬆B 11.250041ЭC 9.250042ϭ⧚ 㒳䅵㸼㒘 ՟⬆ 4 16.0 0.8Э 4 11.3 1.0ϭ 4 9.3 1.3F=45.45ˈP<0.0001˗SNK-qẔ偠˖⬆Эϭϝ㒘ϸϸ↨䕗P<0.05ㅔ㽕䇈 ˖⬆ˈЭˈϭ3⾡ ⧚ 㑶㒚㚲≝䰡⥛ 㒳䅵 Н˄F=45.45ˈP<0.0001˅ˈSNK-q Ẕ偠 ⼎ϸϸП䯈 ϡⳌ ˄P<0.05˅ˈ⬆㒘 催˄16.0 mm/h˅ˈЭ㒘⃵П˄11.3 mm/h˅ˈϭ㒘 Ԣ˄9.3 mm/h˅DŽP149㄀3乬˄ 㒘 ˅data a;input block$ @@;do dose=0.2,0.4,0.8;input x@@;output;end;cards;1⬆ 106 116 1452Э42 68 1153ϭ 70 111 1334ϕ42 63 87;/*䅵ㅫ 䗄 㒳䅵䞣*/proc means n mean std;class dose;var x;run;/* 㒘䆒䅵ⱘ */proc glm;class block dose;model x=block dose;means dose/snk;run;quit;Џ㽕㒧 ˖dose N Obs N Mean Std Dev0.2 4465.030.40.4 4489.527.90.8 44120.025.2㒧Source DF Type III SS Mean Square F Value Pr > Fblock 36457.6666672152.55555623.77 0.0010dose 26074.0000003037.00000033.54 0.0006ϸϸ↨䕗㒧Means with the same letterare not significantly different.SNK Grouping Mean NdoseA 120.00040.8B 89.50040.4C 65.00040.2⧚ 㒳䅵㸼䲠▔㋴ 䞣՟0.2 4 65.0 30.40.4 4 89.5 27.90.8 4 120.0 25.2㒘 ˖F=33.54ˈP=0.0006˗ 䞣䯈ϸϸ↨䕗˖P<0.05ㅔ㽕䇈 ˖ϝ⾡䲠▔㋴ 䞣˄0.2ˈ0.4ˈ0.8˅ϟⱘXXX Ў65.0ǃ89.5ǃ120.0ˈ ℷ 哴 ㋏ⱘ ˄F=23.77ˈP=0.0010˅ ˈϝ⾡䲠▔㋴ϡ 䞣 XXX ˄F=33.54ˈP=0.0006˅ˈSNK-qẔ偠 ⼎ϸϸП䯈 㒳䅵 Н˄P<0.05˅ˈϨ䱣ⴔ 䞣ⱘ ˈ䆹 г DŽP149㄀4乬˄ ϕ 䆒䅵ⱘ ˅data a;do expdate=1to4;do no=1to4;input dose $ x@@;output;end;end;cards;C 32.7 A 11.2 B 23.2D 48.1B 26.2 D 31.8C 28.9 A 18.7A 14.0 C 14.0 D 27.5B 25.6D 33.2 B 16.5 A 21.2 C 40.2;/*䅵ㅫ 䗄 㒳䅵䞣*/proc means n mean std maxdec=1;class dose;var x;run;/* ϕ 䆒䅵ⱘ */proc glm;class expdate no dose;model x=expdate no dose;means dose/snk;run;quit;Џ㽕䕧 㒧dose N Obs N Mean Std DevA 4416.3 4.5B 4422.9 4.4C 4429.011.0D 4435.29.0㒧Source DF Type III SS Mean Square F Value Pr > Fexpdate 3175.142500058.3808333 3.17 0.1064no 3440.1525000146.71750007.98 0.0162dose 3786.5025000262.167500014.25 0.0039ϸϸ↨䕗㒧Means with the same letterare not significantly different.SNK Grouping Mean NdoseA 35.1504DB A 28.9504CB C 22.8754BC 16.2754A⧚ 㒳䅵㸼䞣⯶ ⯶A˖0.32 4 16.34.5B˖0.47 4 22.94.4C˖0.62 4 29.011.0D˖0.77 4 35.29.0˖F=14.25ˈP=0.0039ㅔ㽕䇈 ˖ 䆩偠ⷨお䞛⫼ ∈ ⱘ ϕ 䆒䅵ˈ䆩偠Ё 㗗 њ Ͼ䆩偠 ǃ ⾡㛄 ㋴ 䞣∈ ㄝϝϾ ㋴ˈ ϸϾ ㋴Ў䆩偠 ㋴DŽ㒣㒳䅵 ⼎ˈ њ䆩偠 ǃϡ 㒧 ⱘ ˈϡ 㛄 ㋴ 䞣∈ XXX 㒳䅵 Н˄㾕㸼XXˈF=14.25ˈP=0.0039˅ˈSNK-qẔ偠 䞡↨䕗 ⼎ˈA 䞣㒘˄0.32˅ϢD 䞣㒘˄0.77˅ǃC 䞣㒘˄0.62˅䯈 㒳䅵 Н˄P<0.05˅ˈB 䞣㒘˄0.47˅ϢD 䞣㒘˄0.77˅䯈 㒳䅵 Нˈ 䞣㒘䯈 㒳䅵 НDŽ⾽Ⳍ ˄ㄝ㑻Ⳍ ˅ ⼎ˈ䱣ⴔ㛄 ㋴ 䞣ⱘ ˈXXX ⱘ䍟 ˄s r=0.76ˈP=0.0006˅DŽif dose='A'then dose1=0.32;if dose='B'then dose1=0.47;if dose='C'then dose1=0.62;if dose='D'then dose1=0.77;proc corr spearman;var dose1 x;run;P168˖㄀1乬data a;do row=1to2;do col=1to2;input f@@; output;end;end;cards;25 629 3;proc freq;table row*col/chisq nopercent nocol; weight f;run;Џ㽕㒧 ˖Frequency Row PctTable of row by colcolrow 1 2Total 12580.65619.353122990.6339.3832 Total 54963 Statistics for Table of row by colStatistic DF Value ProbChi-Square 1 1.28070.2578Likelihood Ratio Chi-Square 1 1.30010.2542Continuity Adj. Chi-Square 10.59540.4403Mantel-Haenszel Chi-Square 1 1.26040.2616Phi Coefficient-0.1426 Contingency Coefficient0.1412Cramer's V-0.1426 WARNING: 50% of the cells have expected counts lessthan 5. Chi-Square may not be a valid test.Fisher's Exact TestCell (1,1) Frequency (F) 25Left-sided Pr <= F 0.2209Right-sided Pr >= F 0.9334Table Probability (P) 0.1543Two-sided Pr <= P 0.3020Sample Size = 63ㅔ㽕䇈 ˖⊼ Ϟ䴶ⱘ䄺 ĀWARNING: 50% of the cells have expected counts less than 5. Chi-Square may not be avalid test.āˈ䇈 Ẕ偠ϡ䗖⫼ˈℸ 䞛⫼Fisher㊒⹂Ẕ偠ˈFisher's Exact Test ջẔ偠˖P=0.3020ˈ䇈 䖬≵ 䎇 ⱘ⧚⬅䅸Ў⬆Эϸ⊩ⱘ ⥛ DŽP168˖㄀3乬data a;do row=1to2;do col=1to2;input f@@; output;end;end;cards;23 127 8;proc freq;table row*col/agree; /*䜡 */weight f;run;Џ㽕㒧 ˖McNemar's TestStatistic (S) 1.3158DF 1Pr > S 0.2513䇈 ˖䜡 Ẕ偠ˈ McNemar's Testˈ2F=1.3158ˈP=0.2513ˈ䖬ϡ㛑䅸Ў⬆Эϸ⾡ ⱘ DŽP184˖㄀2乬data a;input id before after;cha=before-after;cards;1 336 2582 371 2913 386 3004 364 2855 377 2986 292 3037 288 3128 304 2609 333 33910 302 290;proc means n mean std median clm maxdec=1; var before after cha;run;proc univariate;var cha;run;Џ㽕㒧 ˖Variable N Mean Std Dev Median Lower 95%CL for MeanUpper 95%CL for Meanbefore after cha101010335.3293.641.737.423.744.5334.5294.561.0308.5276.79.9362.1310.573.5Tests for Location: Mu0=0Test Statistic p ValueStudent's t t 2.966313Pr > |t| 0.0158Sign M 2Pr >= |M| 0.3438Signed Rank S 20.5Pr >= |S| 0.0352⧚ 㒳䅵㸼⒊㜆㜆 ԧ UU) ⱘ㊒ ˄10E9/L˅䞣՟ 95%CIUU 10 335.3 37.4 308.5-362.1UU 10 293.6 23.7 276.7-310.510 41.7 44.5 9.9-73.5䜡 ⾽ Ẕ偠˖S=20.5ˈP=0.0352ㅔ 䇈 ˖ ⒊㜆㜆 ԧ(UU) ⱘ㊒ Ў335.3ˈ Ў293.6ˈ ϟ䰡41.7(95%CI˖9.9-73.5)ˈ ㊒ 䰡Ԣ˄S=20.5ˈP=0.0352˅DŽP184˖㄀6乬data a;do row=0to3;do col=1to4;input f@@; output;end;end;cards;1 4 7 53 6 9 710 6 5 57 2 4 1;proc npar1way wilcoxon;class col;var row;freq f;run;Џ㽕㒧 ˖Wilcoxon Scores (Rank Sums) for Variable rowClassified by Variable colcol N Sum ofScoresExpectedUnder H0Std DevUnder H0MeanScore1 211182.50871.5090.58090056.3095242 18700.00747.0085.89903938.8888893 25912.501037.5095.53653836.5000004 18608.00747.0085.89903933.777778Average scores were used for ties.Kruskal-Wallis TestChi-Square 12.2366DF3Pr > Chi-Square 0.0066Kruskal-Wallis HẔ偠㒧 ˖2F=12.2366ˈP=0.0066ˈ䇈 4⾡⮒⮙ 㗙⯄⎆ 䝌 ㉦㒚㚲ⱘㄝ㑻 ϡ DŽ[ҢϞ䴶㸼Ёⱘ ⾽ ҹⳟ ˈ㄀ϔ⾡⮒⮙ 䝌 ㉦㒚㚲ⱘㄝ㑻Ⳍ Ѣ ϝ⾡ ˄䰇 ⿟ ˅DŽℸ䇈⊩ 㒳䅵 ]⊼ ˖ ⶹ䘧 ѯ⮒⮙П䯈ㄝ㑻 ϡ ˈ䳔㽕 ϸϸ↨䕗DŽ˄ ϸ㒘ⱘ ⾽ Ẕ偠ˈ ℷẔ偠∈ alpha˅。

SAS综合练习题的答案

SAS综合练习题的答案

S A S金融数据处理综合练习题1.创建一包含10000个变量X1-X10000,100个观测值的SAS数据集;分别用DATA步,DATA步数组语句和IML过程实现;1用data步实现data test1a;informat x1-x10000 9.2; /创建100个变量,规定输出格/do i=1to100; /做循环/output;/每一次循环,输出所有的变量,包括i/drop i;/去掉i/end;run;或者data test1a;format x1-x10000 best12.; /创建10000个变量x1-x10000,但未有初始化/do i=1to100; /创建100个观测/output;/且每一个观测都输出到数据集test1a/end;drop i;run;2用data步数组语句实现data test1b;array t{10000} x1-x10000 ;/创建数组变量/do i =1to100;/每个变量有100个观测/output;/每一次循环,输出所有的变量,包括i/drop i;/去掉i/end;/循环结束/data test1c;array t{10000} x1-x10000;do j=1to100;/100次观测的循环/do i = 1to10000;t{i}=i;/第i个变量等于i/end;output;/输出第i次观测的i个变量的值/end;drop i j;/去掉i和j/run;或者data test1b;array t{10000} x1-x10000;do j=1to100;/100次观测的循环/do i = 1to10000;t{i}=i;/第i个变量等于i/end;output;/输出第i次观测的i个变量的值/end;drop i j;/去掉i和j/run;3用IML过程实现proc iml;/启用iml环境/x='x1':'x10000';/定义数组x1-x10000/t= j100,10000,1 ;/创建100行10000列的. 同元素矩阵/print t x;/打印两个矩阵察看/create test1d from tcolname=x;/创建数据集c,变量数为列数 ,观测数为行数,列名更改为变量名,默认逻辑库为临时/append from t; /将t中的值填充的数据集中/show datasets;show contents;/显示数据集的一些7788的属性/close test1d;run;quit;或者proc iml;x='x1':'x10000';t= shape1,100,10000 ;/shape和j不太一样,顺序是元素,行,列,j的顺序为行,列,元素/print t x;create test1d from tcolname=x;append from t;show datasets;show contents;close test1d;run;quit;4用宏实现%macro namesname,number,obs;data a;%do i=1%to &obs;%do n=1%to &number;&name&n=1;%end;output;%end;run;%mend names;%names x, 10000,100;2.多种方法创建包含变量X的10000个观测值的SAS数据集;3.数据集A中日期变量DATE包含有缺失值,创建包含日期变量DATE的数据集B,并填充开始到结束日之间的所有日期值;proc iml;/启用iml环境/x= {'date' price};/注意所用的括号类型/t= {11112,23412,21323,12345,123456,34566,67534,23457,21349};print t;/构造9行2列的向量/t1,1=.;t2,1=.;t5,1=.;t9,1=.;/令某些date的观测成为缺失值,包括第一个观测值/create a from tcolname=x;/从矩阵构造数据集a,为变量命名date和price /append from t; /填充矩阵已有的观测值 /show datasets;show contents;/显示一些信息,可省略/close a;run;quit;/退出iml环境 /data a;set a;format date yymmdd8.2;/将数值型的改变为日期型的输出变量/run;data a1;set a ;n=_n_;/取出观测号,以方便进行排序 /format date yymmdd8.2;retain temp;/设定一个变量temp,规定如果没有新的观测读入,不清空原值,保留原来的观测值/if date^=.then temp=date;/如果读入的date的观测值不为空 /else date=temp;run;/至此数据集填充了后面的部分,最之前的缺失值未能填充,后面将数据集逆序排列进行填充/ data a2;n=_n_;/创建数据集c,取出c的观测号,以方便进行逆向排序/set a1;run;proc sort data=a2;by descending n;/将c逆向排序/run;data a3;/定义数据集d,填充数据集d的末尾的观测/set a2 ;drop n temp;run;data a4 ;set a3;retain temp;if date^=.then temp=date;else date=temp;run;data a4;n=_n_;set a4;run;proc sort data=a4 out=bdrop=n temp;by descending n;/定义数据集e,将d中的观测最一次逆序,得到原序/run;以下是助教的做法但是无法运行成功proc sort data=a;by date;data bdrop=date;set a end=end;by date;retain start;if _n_=1then start=date;if _n_=end then do;last=date;output;end;run;data bkeep=date;informat date yymmdd10.;format date yymmdd10.;set b;do date=start to last;output;end;run;4.创建包含日期变量DATE的SAS数据集,日期值从1900年1月1日到2000年1月1日;data test4a;informat date 9.2 x y;format date yymmdd10.2;/规定输出格式/x=mdy'1','1','1900';/返回sas日期值,即以1960/1/1为0的日期值/y=mdy'1','1','2000';do i= x to y;date=i;output;end;drop i x y;run;或者data test4b;do date='1jan1900'd to'1jan2000'd;output;end;format date yymmdd10.;run;5.利用随机数函数RANUNI对某数据集设计返回抽样方案;data sampledrop =samplesize n;samplesize=5; /样本容量为5/do n=1to samplesize; /从1到样本容量的循环/readit=ceilranuni0totobs;put readit=;set resdat.class point=readit nobs=totobs;output;end;stop;run;或者data dat1;set resdat.class;keep name;run;%macro samplei;data dat2;set dat1 nobs=nobs;ran=ceilnobsranuni&i;run;proc sort data=dat2;by ran;run;%mend samplei;%sample2;data dat3;set dat2;if _n_<=6;run;%sample3;data dat4;set dat2;if _n_<=6;run;%sample5;data dat5;set dat2;if _n_<=6;%sample30;data dat6;set dat2;if _n_<=6;run;data a;set dat3 dat4 dat5 dat6;run;或者data a;set resdat.class;keep name;run;data b;set a nobs=nobs;ran=ceilnobsranuni2007;run;proc sort data=b;by ran;data c;set b;if _n_<=5;run;6.利用随机数函数RANUNI对某数据集设计不返回抽样方案;data a;set resdat.class;keep name;run;data b;set a nobs=nobs;ran=ceilnobsranuni1;put ran=;run;proc sort data=b;by ran;data c;set b;if _n_<=15;run;或者data a;set resdat.class;keep name;run;data b;set a nobs=nobs;ran=ceilnobsranuni2007;run;proc sort data=b;by ran;data c;set b;if ran=lagran then delete;run;data d;set c;if _n_<=15;run;7.计算数据集A中变量X的累乘;proc iml;x='x';m=do1,10,0.5;t=tm;print m t;create a from tcolname=x ;append from t;quit; /用IML生成数据集a/data b;set a;retain y 1;y=yx;run;或者data a;input x;y=yx;retain y 1;cards;1234;run;8.如何改变一个SAS数据集的变量顺序data akeep=name bkeep=age ckeep=weight dkeep=height;set resdat.class;run;data test8a;merge b d c a;run;或者data test8b;format height weight age name;set resdat.class;run;9.数据集A和B包含同样两变量DATE和PRICE,以DATE为标识变量合并数据集A和B为C;合并时应该注意什么在合并前必须先排序,并且merge a b; by date;与merge b a; by date;结果不一样;proc sort data=a;by date;run;proc sort data=b;by date;run;data c;merge a b;by date;run;10.给下段程序的主要语句加注释;STOP语句能否删除为什么data a; /创建数据集a/do obsnum=1to last by20; /做循环,从第一个观测到最后一个观测数,间隔20/set ResDat.stk000001 point=obsnum nobs=last; /指针选项和观测总数选项/output;/强制输出当前值,否则只会在最后输出现值/end;/命令选换结束/stop;/强制结束数据步,因为set语句在数据步程序中会反复执行数据步的程序直到遇到文件结束最后一跳观测的标志,这里使用了指针选项可能碰不到这种标志,所以要用stop,否则就有可能无休止地执行下去/run;11.假设数据集A中的变量logdate为如下形式的字符格式:1998-12-21999-8-61999-8-10将其转换为日期格式变量date;如果字符格式的数据为:199812021999080619990810又怎样转换为日期格式变量;data a;input logdate $ 10.;cards;1998-12-21999-8-61999-8-10;run;data b;set arename=logdate=date;date=inputdate,yymmdd10.;label date= '日期';run;或者data a;input logdate $9.;cards;1998-12-21999-8-61999-8-10;run;data b;format date yymmdd10.; /规定输出格式/set a;date=inputlogdate,yymmdd10.; /转变格式/drop logdate;run;12.运行SAS程序过程中,SAS系统创建的自动变量是否包含在创建的数据集一般情况下,怎样查看系统自动变量的值自动变量是由数据步语句自动创建的,这些自动变量不输出到数据集中,在重复过程中被保留;data a;set resdat.class;put _n_ _error_;keep _numeric_;run;13.SAS系统显示表达式、函数、数据集、数组或矩阵的具体值时,常需要哪些语句和过程put; proc print ; print ;show ;list;14.写出下面各段程序创建数据集的所有观测值,并指出PUT语句分别在LOG窗口输出什么结果data a1;do n=1 to 5;end;put n=;run;数据集a1中有一个变量n,5个观测值为1-5,日志窗口输出n=6;data a1;do n=1 to 5;output;put n=;end;put n=;run;数据集中有一个变量n,5个观测为1-5,日志窗口输出n=1-n=6data a1;do n=1 to 5;put n=;end;put n=;run;数据集中有一个变量n,只有一个观测值6,日志窗口输出n=1-n=6data a1;do n=1 to 5;end;put n=;run;数据集中有一个变量n,只有一个观测值6,日志窗口输出n=6data a2;n=1;do untiln>=5;n+1;output;end;put n=;run;数据集中有一个变量,4个观测,n=2-n=5,日志窗口输出n=5 data a3; n=1; do whilen<5; n+1; output; end; put n=;run;同上一题一样的情况,数据集中有一个变量,4个观测,n=2-n=5,日志窗口输出n=5 data a4;n=7;do untiln>=5;n+1;output; end; put n=; run;数据集中有一个观测,n=8,日志窗口n=8;因为执行了一次数据步 data a5; n=7; do whilen<5; n+1; output; end; put n=; run;数据集中一个变量n,没有观测,日志窗口n=715. 数据集A 有一个变量n,5个观测值1,2,3,4,5;数据A1由下面程序2产生,同样有一个变量n,5个观测值1,2,3,4,5;试分析下面两段程序中,PUT 语句在Log 窗口输出结果的差异,为什么 程序1: Data a; Set a; Put n=; Run;在日志窗口中输出n=1-n=5 程序2: data a1; do n=1 to 5; output; end; put n=; run;在日志窗口中输出n=6理解了set 语句就不难得到这个结果;data a;do n=1 to 5; output ; end ; run ; Data a; Seta; Put n=; Run ; data a1; do n=1 to 5; output ; end ;put n=;run;16.试由以下的9种德国马克对美元汇率看跌期权和9种英镑对美元汇率的看跌期权产生81种组合;一年期,DM/USD汇率的9种不同看跌期权的执行价格和成本执行价格Kdm 成本Cdm0.66 0.0858550.65 0.0321910.64 0.0207950.63 0.0170010.62 0.0137110.61 0.0108510.60 0.0083880.59 0.0062910.55 0.001401一年期,BP/USD汇率的9种不同看跌期权的执行价格和成本执行价格Kbp 成本Cbp1.30 0.1372131.25 0.0826451.20 0.0450601.15 0.0283481.10 0.0161461.05 0.0078601.00 0.0032770.95 0.0011340.90 0.000245创建样本数据集:data dm;input Kdm Cdm;cards;0.66 0.0858550.65 0.0321910.64 0.0207950.63 0.0170010.62 0.0137110.61 0.0108510.60 0.0083880.59 0.0062910.55 0.001401;run;data bp;input Kbp Cbp;cards; 1.30 0.137213 1.25 0.082645 1.20 0.045060 1.15 0.028348 1.10 0.016146 1.05 0.007860 1.00 0.003277 0.95 0.001134 0.90 0.000245 ; run;解答:data test16a;set dm; /依次读入数据集dm 中的第1至9个观测/ do j=1 to 9 ; set bp point=j;/在读入dm 的第i 个观测后,依次读入bp 中的所有观测/output ;end ; run ;或者data test16b; do i=1 to 9;set dm point=i; /依次读入数据集dm 中的第1至9个观测/ do j=1 to 9 ; set bp point=j;/在读入dm 的第i 个观测后,依次读入bp 中的所有观测/output ;end ; end ; stop ; run ;17. 不用SAS 函数,用宏%an,p 计算二项分布的概率分布和累计概率k=1,2……,n;()(1)k n k n P X k p p k -⎛⎫==- ⎪⎝⎭;此处留有空白18. 创建组标识变量GROUP,将数据集A 中的观测等分为10组,观测值不能整除10时,前余数组各多加一个观测值; data a; n=_n_;retain groupid 0;set test nobs=totobs;/选项nobs 观测的总数,赋值给totobs/ x=modtotobs,10;/观测个数除以10的余数/ y=inttotobs/10;/观测个数除以10的整数/data a;set a nobs=totobs;if n>0 and n=<y+1x thengroupid= intn-1/y+1+1;/前x组的号码/elsegroupid= intn-x-1/y+1;/不多元素的组号/drop x y;run;19.现有一个数据流:a 2 b 3 c d 4 6,按下面要求创建SAS数据集;用语句input id $ no; 变量id取值上面数据流里的a,b,c,d,变量no取值2,3,4,6;但是这个数据流存在问题:如有的id没有no,有的no没有id;创建SAS数据集,删除只有id没有no或者只有no没有id的观测,即把上面的c和6去掉,最后得到三个观测,a 2, b 3与d 4;data b;input no $ ;id=lagno;cards;a 2b 3cd 4 6;run;data d;format id $8. no $8.;set b;if'a'<=no<='z' or '1'<=id<='9'then lostcard;run;或者data a;input t$; /指针/cards;a 2b 3cd 4 6;data a;set a;retain;if'a'<=lowcaset<='z'then id=t;/ 如果是字符串,则用专门的函数判断 /else do;no=inputt,8.;output;no=.;end;drop t;proc sort;by id ;data a;set a;if first.id;run;或者data a;input t$;cards;a 2b 3cd 4 6;data b;set a;id=lagt;no=t;if'a'<=id<='z' and '0'<=no<='9'then output;drop t;run;20.现有一个数据流:a23 223 bc4 36 3c5 11d 400 620,按下面要求创建SAS数据集;用语句input id $ no; 变量id取值上面数据流里的a23, bc4, 11d ,变量no取值233,36,400;但是这个数据流存在问题:如有的id没有no,有的no没有id;创建SAS数据集,删除只有id没有no或者只有no没有id 的观测,即把上面的3c5和620去掉,最后得到三个观测:a23 223bc4 3611d 400data a;input t$;cards;a23 223 bc4 36 3c5 11d 400 620;data b;set a;isno=1;do i=1to lengtht;if substrt,i,1<'0' or substrt,i,1>'9'then do;isno=0;return; /结束循环,返回数据步开始 /end;end;data c;set b;char=lagt;lag_isno=lagisno;number=t;if lag_isno=0 and isno=1then output;keep char number;run;或者/基本思路是先将原数据读入,然后重新按输出为一列,使用lostcard语句读取数据,思路更简洁//读入数据,重新输出为一列/data_null_;input t $ ;file'D:\a.txt';put t $;cards;a23 223 bc4 36 3c5 11d 400 620;run;/利用lostcard语句来选出正确的数据,其中no=. 说明将有非数字的字符的值读入数值变量,也就是连续的name的情况,舍去当前行,重新定位;如果idtest不为.说明读入的id是数值型的,就是连续id情况,舍去当前行,重新定位;这样就可以读出正确的数据了/data a drop=idtest;infile'D:\a.txt';input id $ / no;idtest=id+1;if no='.' or idtest ne '.'then lostcard;run;或者/方法一,基本思路:先将数据流都读入到一个字数变量中,判断如果其有字符出现,则赋值给name,否则转化为数值后赋值给id当name和id值同时不为空时认为找到了一线数据,输出对name,id都使用retain语句,输出后将前一步读入的数据清空./data a;informat temp $10.;attrib name informat=$10.format=$bel="Name";attrib id informat=best12.format=best12. lable="Id";retain name "";retain id .;/先将数据流都读入到变量temp中/input temp :$10.;/设计一个变量标记temp中的是否有字母,有值为1,否则为0,先设为零/ flg=0;/检验temp是否有字母/do i=65to90;if indexupcasetemp,bytei^=0then do;/如果发现一个字母,将flg变量值改为1,退出循环/flg=1;leave;end;end;/根据以上的判断,如果temp中有字母,将其赋值给name,如果name不为空,转换为数值型赋值给id,否则舍去/if flg=1then do;name=temp;end;else if name^=""then id=inputtemp,best12.;/如果name和id同时不为空时说明找到了一组配对的数据,输出到数据集中,清空原有的值/if name^="" and id^=.then do;output;name="";id=.;end;keep name id;cards;a23 223 bc4 36 3c5 11d 400 620;run;或者/在上述的方法中,对于连续出现的name自动用后一个覆盖前一个林而保留正确的数据,对于连续出现的数字, 通过判断是否有name与之配对而决定是否保留,从而选取出想要的数据.//上述方法可以进行两处修改和完善,一:上面的程序只是判断了字符串中是否有字母,如果有字母才认为是name但是如果字符串中有字母以外的非数字字符就会出错,比如将bc4 36 3c5 改为 bc4 3 5;此时如果将检验标准改为判断读入的字符串中是否有非数字以外的字符会更好,将:do i=65 to 90;if indexupcasetemp,bytei^=0 then do;改为:do i=1 to lengthtemp;if substrtemp,i,1<'0' or substrtemp,i,1>'9' then do;二:对于连续数字情况的去除也可以不在本步中进行,输出后name也不清空,即读入一个数据,如果是有非数字字符的就赋值给name,否则给id,如果name,id同时不为空则输出,输出后id清空,name不清空,再继续读入;对于连续的数字,就会用其前面最近出现name形成多条观测,最后再通过排序只保留每个name对应的第一个观测也可以,这种对应的程序如下:/data a;informat temp $10.;attrib name informat=$10.format=$bel="Name";attrib id informat=best12.format=best12. lable="Id";retain name "";/先将数据流都读入到变量temp中/input temp :$10.;/设计一个变量标记temp中的是否有字母,有值为1,否则为0,先设为零/ flg=0;/检验temp是否有字母/do i=65to90;if indexupcasetemp,bytei^=0then do;/如果发现一个字母,将flg变量值改为1,退出循环/flg=1;leave;end;end;/根据以上的判断,如果temp中有字母,将其赋值给name,如果name不为空,转换为数值型赋值给id/if flg=1then do;name=temp;end;else id=inputtemp,best12.;/如果name和id同时不为空时说明找到了一组配对的数据,输出到数据集中,清空原有的值/if name^="" and id^=.then do;output;id=.;end;keep name id;cards;a23 223 bc4 36 3c5 11d 400 620;run;proc sort;by name;data a;set a;by name;if ;run;或者data akeep=id no;input x $ ;id=lag1x;no=inputx,8.;/把变量x转换成数值,若遇非纯数字的值,则转成缺失值,同时日志窗口NOTE会提示转换无效,不必在意;如果数据很多,可以用系统选项把note去掉:options nonotes/y=lag1no;if y='.' and id^=' ' and no^='.';/选择观测,如果y是缺失值,但id和no不是缺失值,就是我们想要的观测/cards;a23 223 bc4 36 3c5 11d 400 620;run;21.用SAS软件作三维Hat图,x和y轴取值区间为-5,5,z = sinsqrtyy + xx;data a;do x=-5to5by0.5;do y=-5to5by0.5;z = sinsqrtyy + xx;output;end;end;run;proc g3d;plot yx=z;title'hat graph';run;鞍图形;提示:产生x, y和z的数据后,用下面的过程实现作图;proc g3d;plot yx=z;run;data a;p=20;q=1;do x=-9to9by0.1; /从-9到9每距离0.1取一个点/do y=-3to3by0.1;z=-x2/p+y2/q; /创建马鞍图的数学公式/output;end;end;drop p q;run;proc g3d; /用g3d作图/plot yx=z;run;23.数据集Calendar只有日期变量,test包含股票代码、日期与收盘价三个变量;合并两个数据集,用Calendar中的日期数据替代test数据集中每只股票的日期数据;创建样本数据集:data calendar;input Date yymmdd10.;format Date yymmdd10.;cards;2003-1-202003-1-212003-1-222003-1-232003-1-242003-1-272003-1-282003-1-292003-1-302003-1-312003-2-32003-2-42003-2-52003-2-62003-2-72003-2-8;run;data test;infile datalines missover ;informat Stkcd $6. Date yymmdd10. Clpr 8.2; input Stkcd $ Date Clpr;format Stkcd $6. Date yymmdd10. Clpr 8.2; cards;600000 2003-1-20 9.94600000 2003-1-22 9.66600000 2003-1-24 9.88600000 2003-1-27 10.07600000 2003-1-28 10.17600000 2003-1-29 10.31600000 2003-2-4 10.31600000 2003-2-5 10.13600001 2003-1-20 8.13600001 2003-1-21 8.14600001 2003-1-22 8.17600001 2003-1-23 8.40600001 2003-1-24 8.65600001 2003-1-31 8.93600001 2003-2-4 9.02600001 2003-2-5 8.63600002 2003-1-31 2.25600002 2003-2-3 2.26600002 2003-2-4 2.35600002 2003-2-6 2.55600002 2003-2-8 2.12;run;proc sort data=calendar;by date;run;proc sort data=test;by date;run;data a;merge test calendar;by date;run;24.当股票的分配事件分两次完成,且第一次分配在节假日或该股票的停牌日,第二次分配在下一个交易日时,一般的数据库会有如下表所示的观测值存贮方式;写程序将停牌日即没有收盘价的那个观测值中的分配事件合到下一个观测中;注:…表示有数据值,.表示缺失值;编程变量名参考:股票代码Stkcd日期Date收盘价Clpr送股比例Stkdrate转增比例Capissurate配股比例Rigoffrate配股价Rigoffpr增发比例Snirate增发价格Snipr现金红利Dividend创建样本数据集:data a;input Stkcd Date yymmdd8. Clpr Stkdrate Capissurate Rigoffrate Rigoffpr Snirate Snipr Dividend;format Date mmddyy8.;cards;600001 01-01-01 8 . . . . . . .600001 01-01-02 . 0.3 0.3 0 0 0 0 0600001 01-01-03 9 0 0 0.5 0.2 0 0 0.1600002 01-01-02 10 0 0 0 0 0 0 0600002 01-01-03 . 0.2 0.3 0.5 0 0 0.1 0.2600002 01-01-04 12 0 0 0 0.2 0.3 0.5 0.6;run;第一种做法中变量名成为旧名称,可改为题中设定的相应名称;data test;input hstkcd Dt yymmdd8.Closepr Stkdrate Capissurate Rigoffrate Rigoffpr Snirate Snipr Dividend;format Dt mmddyy8.;cards;600001 01-01-01 8 . . . . . . .600001 01-01-02 . 0.3 0.3 0 0 0 0 0600001 01-01-03 9 0 0 0.5 0.2 0 0 0.1600002 01-01-02 10 0 0 0 0 0 0 0600002 01-01-03 . 0.2 0.3 0.5 0 0 0.1 0.2600002 01-01-04 12 0 0 0 0.2 0.3 0.5 0.6;run;proc sort data=test;/排序原数据集/by hstkcd dt;run;data p17 keep=Hstkcd Dt Closepr Stkdrate Capissurate Rigoffrate Rigoffpr Snirate Snipr Dividend;/只保留原数据集中的变量/set test;array origin{0:7} closepr Stkdrate Capissurate Rigoffrate Rigoffpr Snirate Snipr Dividend;/为处理方便,创建数组/array lagn{0:7} lag0-lag7;/创建另一个数组/lagcd=lag1hstkcd;/为防止分配数据不全的情况,下面有检查是否同一股票的条件/do i=0to7;lagni=lag1origini;/后滞,用来下面判断/end;if lagcd=hstkcd and lag0='.'then do i=1to7;/必须满足是同一股票,且收盘价为缺失值/origini=origini+lagni;/分配数据加和/end;if closepr^='.';/删除收盘价是缺失值的观测/run;或者data a;input Stkcd Date yymmdd8. Clpr Stkdrate Capissurate Rigoffrate Rigoffpr Snirate Snipr Dividend;format Date mmddyy8.;cards;600001 01-01-01 8 . . . . . . .600001 01-01-02 . 0.3 0.3 0 0 0 0 0600001 01-01-03 9 0 0 0.5 0.2 0 0 0.1600002 01-01-02 10 0 0 0 0 0 0 0600002 01-01-03 . 0.2 0.3 0.5 0 0 0.1 0.2600002 01-01-04 12 0 0 0 0.2 0.3 0.5 0.6;run;data b;set a;temp_1=lagclpr;temp_2=lagstkdrate;temp_3=lagCapissurate;temp_4=lagRigoffrate;temp_5=lagRigoffpr;temp_6=lagSnirate;temp_7=lagSnipr;temp_8=lagDividend;if _n_=1then temp_1=1;run;data c;set b;array temp_i7 temp_2 temp_3 temp_4 temp_5 temp_6 temp_7 temp_8;array variables7 Stkdrate Capissurate Rigoffrate Rigoffpr Snirate Snipr Dividend;if temp_1=.then do;do i=1to7;variablesi=variablesi+temp_ii;end;end;else if clpr=.then do;do i= 1to7;variablesi=.;end;end;drop temp_1-temp_8 i;run;data d;set c;if clpr=.then delete;run;25.假设股票市场的股本数据如下表,对每支股票至少1000支股票,按如下要求设计填充总股本和流通股股本数据的SAS程序:以该股票前面的股本数据填充后面的缺失值,如果某支股票上市交易时就缺失股本数据,则用该股票上市后的第一个股本数据向前填充;注:…表示有数据值,.表示缺失值;编程变量名参考:股票代码Stkcd日期Date收盘价Clpr股本变动日CapchgDate总股本Fullshr流通股trdshr/ 创建样本数据集/data test;infile datalines missover ;informat Stkcd $6. Date yymmdd10. Clpr 8.2 capchgDate yymmdd10. fullshr Trdshr 20. ;input Stkcd $ Date Clpr capchgDate fullshr Trdshr;format Stkcd $6. Date yymmdd10. Clpr 8.2 capchgDate yymmdd10. fullshr Trdshr 20.;cards;600000 2003-1-21 9.68600000 2003-1-22 9.66600000 2003-1-23 9.6600000 2003-1-24 9.88600000 2003-1-27 10.07600000 2003-1-28 10.17600000 2003-1-29 10.31600000 2003-2-10 10.09600000 2003-2-11 10.2600000 2003-2-12 10.31600000 2003-2-13 10.13600001 2000-5-29 8.13 2000-5-29600001 2000-5-30 8.14600001 2000-5-31 8.65600001 2000-6-1 8.93600001 2000-6-2 9.11600001 2000-6-5 9.02600001 2000-6-6 8.63600001 2000-6-7 8.52600001 2000-6-8 8.55600001 2000-6-9 8.3600001 2000-6-12 8.34;Run;data test25a;infile datalines missover;informat Stkcd $6.Date yymmdd10.Clpr 8.2capchgDate yymmdd10.fullshr Trdshr20. ;input Stkcd $ Date Clpr capchgDate fullshr Trdshr;format Stkcd $6.Date yymmdd10.Clpr 8.2capchgDate yymmdd10.fullshr Trdshr 20.;cards;600000 2003-1-21 9.68600000 2003-1-22 9.66600000 2003-1-23 9.6600000 2003-1-24 9.88600000 2003-1-27 10.07600000 2003-2-12 10.31600000 2003-2-13 10.13600001 2000-5-29 8.13 2000-5-29600001 2000-5-30 8.14600001 2000-5-31 8.65600000 2003-1-28 10.17600000 2003-1-29 10.31600000 2003-2-10 10.09600000 2003-2-11 10.2600001 2000-6-1 8.93600001 2000-6-2 9.11600001 2000-6-5 9.02600001 2000-6-6 8.63600001 2000-6-7 8.52600001 2000-6-8 8.55600001 2000-6-9 8.3600001 2000-6-12 8.34;Run;data test25b;set test25a;n=_n_;run;proc sort data=test25b;by stkcd n;run;data test25c;set test25b;by stkcd n;retain tempf;if first.stkcd=1then tempf=.;if fullshr^=.then tempf=fullshr;else fullshr=tempf;drop tempf;run;proc sort data=test25c;by stkcd descending n;run;data test25d;set test25c;by stkcd descending n;retain tempf;if first.stkcd=1then tempf=.;if fullshr^=.then tempf=fullshr;else fullshr=tempf;drop tempf;run;proc sort data=test25d;by stkcd n;data test25e;set test25d;by stkcd n;retain tempt;if first.stkcd=1then tempt=.;if trdshr^=.then tempt=trdshr;else trdshr=tempt;drop tempt;run;proc sort data=test25e;by stkcd descending n;run;data test25f;set test25e;by stkcd descending n;retain tempt;if first.stkcd=1then tempt=.;if trdshr^=.then tempt=trdshr;else trdshr=tempt;drop tempt;run;proc sort data=test25f;by stkcd n;run;data test25;set test25fdrop=n;run;26.用线性插值法填充缺失数据;以下面的实际数据为基础,完成相关SAS程序的设计;银行间债券市场的回购行情如下表,对于一个月、二个月和三个月的回购利率,按如下要求设计填充回购利率的月底缺失数据;注:…表示有数据值,.表示缺失值;编程变量名参考:交易日期Date基准利率代码Code基准利率Ir一个月债券回购利率R1M二个月债券回购利率R2M三个月债券回购利率R3M/ 创建样本数据集/data test;informat Date yymmdd10. code$8. Ir; input Date: Code $ Ir;format Date yymmdd10. code $8. Ir; cards;2004-01-02 R1M 0.0252004-01-05 R1M 0.02552004-01-05 R2M 0.02442004-01-05 R3M 0.0272004-01-06 R1M 0.0242004-01-06 R2M 0.0252004-01-07 R1M 0.02412004-01-07 R2M 0.02452004-01-08 R1M 0.0232004-01-08 R2M 0.02452004-01-08 R3M 0.0232004-01-09 R1M 0.0232004-01-09 R2M 0.0232004-01-09 R3M 0.02482004-01-12 R1M 0.0252004-01-12 R2M 0.0242004-01-13 R2M 0.0237 2004-01-14 R1M 0.0248 2004-01-14 R2M 0.0248 2004-01-14 R3M 0.025 2004-01-15 R1M 0.0246 2004-01-15 R2M 0.025 2004-01-15 R3M 0.03 2004-01-16 R1M 0.0325 2004-01-16 R2M 0.026 2004-01-16 R3M 0.0265 2004-01-17 R1M 0.038 2004-01-17 R2M 0.0325 2004-01-18 R1M 0.035 2004-01-18 R2M 0.035 2004-01-18 R3M 0.0325 2004-01-19 R1M 0.0343 2004-01-19 R2M 0.033 2004-01-20 R1M 0.032 2004-01-20 R2M 0.032 2004-01-20 R3M 0.0325 2004-01-29 R1M 0.0288 2004-01-29 R2M 0.029 2004-01-29 R3M 0.0296 2004-01-30 R1M 0.029 2004-01-30 R2M 0.0297 2004-01-30 R3M 0.0296 2004-02-02 R2M 0.0305 2004-02-03 R1M 0.028 2004-02-03 R2M 0.028 2004-02-04 R2M 0.0251 2004-02-05 R1M 0.0248 2004-02-05 R2M 0.0254 2004-02-06 R1M 0.024 2004-02-06 R2M 0.0242 2004-02-09 R1M 0.024 2004-02-09 R2M 0.024 2004-02-09 R3M 0.0255 2004-02-10 R1M 0.0238 2004-02-10 R2M 0.0235 2004-02-11 R1M 0.0234 2004-02-11 R2M 0.0245 2004-02-11 R3M 0.025 2004-02-12 R1M 0.0232004-02-12 R3M 0.024 2004-02-13 R1M 0.0229 2004-02-13 R2M 0.0231 2004-02-13 R3M 0.0234 2004-02-16 R1M 0.0225 2004-02-16 R2M 0.0229 2004-02-16 R3M 0.0234 2004-02-17 R1M 0.0225 2004-02-17 R2M 0.0228 2004-02-17 R3M 0.024 2004-02-18 R1M 0.0225 2004-02-18 R2M 0.0224 2004-02-18 R3M 0.0232 2004-02-19 R1M 0.0223 2004-02-19 R2M 0.0227 2004-02-19 R3M 0.0231 2004-02-20 R1M 0.0222 2004-02-20 R2M 0.0222 2004-02-20 R3M 0.023 2004-02-23 R1M 0.0222 2004-02-23 R2M 0.0235 2004-02-23 R3M 0.0231 2004-02-24 R1M 0.0222 2004-02-24 R2M 0.0223 2004-02-24 R3M 0.024 2004-02-25 R1M 0.0218 2004-02-25 R2M 0.0213 2004-02-25 R3M 0.021 2004-02-26 R1M 0.0218 2004-02-26 R2M 0.0218 2004-02-26 R3M 0.0224 2004-02-27 R1M 0.0218 2004-02-27 R2M 0.0218 2004-02-27 R3M 0.0223 2004-03-01 R1M 0.0217 2004-03-01 R2M 0.0215 2004-03-01 R3M 0.022 2004-03-02 R1M 0.022 2004-03-02 R2M 0.0216 2004-03-02 R3M 0.0218 2004-03-03 R1M 0.0218 2004-03-03 R2M 0.0218 2004-03-03 R3M 0.0222004-03-04 R2M 0.022 2004-03-04 R3M 0.022 2004-03-05 R1M 0.0218 2004-03-05 R2M 0.0218 2004-03-05 R3M 0.022 2004-03-08 R1M 0.0211 2004-03-08 R3M 0.0227 2004-03-09 R1M 0.0212 2004-03-09 R3M 0.0225 2004-03-10 R1M 0.022 2004-03-10 R2M 0.0218 2004-03-10 R3M 0.0224 2004-03-11 R1M 0.0214 2004-03-11 R2M 0.0214 2004-03-11 R3M 0.0228 2004-03-12 R1M 0.0214 2004-03-12 R2M 0.0214 2004-03-12 R3M 0.0223 2004-03-15 R1M 0.021 2004-03-15 R2M 0.0216 2004-03-15 R3M 0.0225 2004-03-16 R1M 0.0213 2004-03-16 R3M 0.0223 2004-03-17 R1M 0.0211 2004-03-17 R2M 0.0222 2004-03-18 R1M 0.0216 2004-03-18 R2M 0.0222 2004-03-18 R3M 0.0228 2004-03-19 R1M 0.0216 2004-03-19 R2M 0.022 2004-03-19 R3M 0.023 2004-03-22 R1M 0.0215 2004-03-22 R2M 0.0228 2004-03-23 R1M 0.0216 2004-03-23 R2M 0.0228 2004-03-24 R1M 0.022 2004-03-24 R2M 0.024 2004-03-24 R3M 0.0248 2004-03-25 R1M 0.0231 2004-03-25 R3M 0.025 2004-03-26 R1M 0.023 2004-03-26 R2M 0.0233 2004-03-26 R3M 0.02452004-03-29 R2M 0.0233 2004-03-30 R1M 0.0208 2004-03-30 R2M 0.0233 2004-03-31 R1M 0.0229 2004-03-31 R2M 0.0235 2004-04-01 R1M 0.023 2004-04-01 R2M 0.024 2004-04-02 R1M 0.0232 2004-04-02 R2M 0.0235 2004-04-02 R3M 0.025 2004-04-05 R1M 0.0217 2004-04-05 R2M 0.0229 2004-04-05 R3M 0.0256 2004-04-06 R1M 0.0215 2004-04-06 R2M 0.024 2004-04-06 R3M 0.0249 2004-04-07 R1M 0.0213 2004-04-07 R2M 0.0232 2004-04-07 R3M 0.0249 2004-04-08 R1M 0.022 2004-04-08 R2M 0.023 2004-04-08 R3M 0.0251 2004-04-09 R1M 0.0218 2004-04-09 R2M 0.0214 2004-04-09 R3M 0.025 2004-04-12 R1M 0.0253 2004-04-12 R2M 0.024 2004-04-12 R3M 0.0278 2004-04-13 R1M 0.0265 2004-04-13 R2M 0.0275 2004-04-13 R3M 0.028 2004-04-14 R1M 0.0268 2004-04-14 R2M 0.0258 2004-04-14 R3M 0.0285 2004-04-15 R1M 0.027 2004-04-15 R2M 0.0275 2004-04-16 R1M 0.0271 2004-04-16 R2M 0.0283 2004-04-19 R1M 0.0287 2004-04-19 R2M 0.0283 2004-04-19 R3M 0.0287 2004-04-20 R1M 0.0285 2004-04-20 R2M 0.0292004-04-21 R2M 0.0287 2004-04-21 R3M 0.0315 2004-04-22 R1M 0.029 2004-04-22 R3M 0.0288 2004-04-22 R2M 0.0293 2004-04-23 R1M 0.0285 2004-04-23 R2M 0.0295 2004-04-26 R1M 0.025 2004-04-26 R2M 0.0288 2004-04-27 R1M 0.028 2004-04-27 R3M 0.029 2004-04-28 R1M 0.0279 2004-04-28 R2M 0.0285 2004-04-29 R1M 0.028 2004-04-29 R2M 0.028 2004-04-29 R3M 0.0286 2004-04-30 R1M 0.0265 2004-04-30 R2M 0.0279 2004-05-08 R1M 0.0265 2004-05-09 R1M 0.0264 2004-05-10 R1M 0.0264 2004-05-10 R2M 0.0264 2004-05-10 R3M 0.029 2004-05-11 R1M 0.0264 2004-05-11 R2M 0.0272 2004-05-12 R1M 0.026 2004-05-12 R2M 0.0268 2004-05-13 R1M 0.0255 2004-05-14 R1M 0.026 2004-05-14 R2M 0.0265 2004-05-17 R1M 0.0256 2004-05-17 R2M 0.0265 2004-05-18 R1M 0.0256 2004-05-18 R3M 0.0285 2004-05-19 R1M 0.0256 2004-05-19 R2M 0.026 2004-05-19 R3M 0.0285 2004-05-20 R1M 0.0265 2004-05-20 R2M 0.027 2004-05-20 R3M 0.0265 2004-05-21 R1M 0.026 2004-05-24 R1M 0.021 2004-05-24 R2M 0.0272004-05-25 R1M 0.02252004-05-25 R2M 0.0272004-05-26 R1M 0.02632004-05-26 R3M 0.02832004-05-27 R1M 0.0282004-05-27 R2M 0.0272004-05-27 R3M 0.02852004-05-28 R1M 0.02682004-05-31 R1M 0.02882004-05-31 R2M 0.0322004-06-01 R1M 0.0312004-06-01 R2M 0.03192004-06-01 R3M 0.0335;run;data test;informat Date yymmdd10. code$8. Ir;input Date: Code $ Ir;format Date yymmdd10. code $8. Ir;cards;2004-01-02 R1M 0.0252004-01-05 R1M 0.02552004-01-05 R2M 0.02442004-01-05 R3M 0.0272004-01-06 R1M 0.0242004-01-06 R2M 0.0252004-01-07 R1M 0.02412004-01-07 R2M 0.02452004-01-08 R1M 0.0232004-01-08 R2M 0.02452004-01-08 R3M 0.0232004-01-09 R1M 0.0232004-01-09 R2M 0.0232004-01-09 R3M 0.02482004-01-12 R1M 0.0252004-01-12 R2M 0.0242004-01-13 R1M 0.02352004-01-13 R2M 0.02372004-01-14 R1M 0.02482004-01-14 R2M 0.02482004-01-14 R3M 0.0252004-01-15 R1M 0.02462004-01-15 R2M 0.025。

sas上机考试

sas上机考试

用MEANS过程对频数表计算例数、均数、标准差、最小值和最大值data a; input x f @@; cards; proc means; freq f; var x; run; 用UNIVARIATE过程进行描述性统计proc univariate data=ex2_1; freq f;var x;run;作正态性检验、茎叶图、箱式图和正态概率图proc univariate Normal plot;var x;run;TTestdata a; input x c@@; cards; proc ttest; var x; class c; run; 方差分析data ex4_4; input x g b @@; cards;0.82 1 10.65 2 10.51 3 10.73 1 20.54 2 20.23 3 2;proc anova; class g b; model x=g b; means g/snk; run;卡方检验data ex7_8; input r c f @@; cards;1 1 4311 2 4902 1 3882 2 410;proc freq; weight f; tables r*c/chisq expected norow nocol nopercent; run;(Data a; do r=1 to 2;do c=1to 2;input freq@@; output; end; end;cards;) 非参配对data ex8_1; input x1 x2 @@; d=x1-x2; cards;proc univariate; var d;run;两独立样本data ex8_3; input x c @@; cards;proc npar1way wilcoxon; class c; var x; run;多组等级资料data a; input c g f; cards;1 1 01 2 21 3 92 1 32 2 52 3 53 1 53 2 73 3 3;proc npar1way wilcoxon; freq f; var g; class c; run;相关data ex9_1; input x y; cards;proc reg; model y=x;run;回归data ex9_5; input x y; cards;proc corr; var x y; run;多元回归data ex15_1; input x1-x4 y @@; cards;proc reg; model y=x1-x4; run;Logistic回归两变量data ex16_1; input y x1 x2 f @@; cards;(1阳性)1 0 0 631 0 1 631 1 0 441 1 1 265(0阴性)0 0 0 1360 0 1 1070 1 0 570 1 1 151;proc logistic descending; freq f; model y=x1 x2; run;多变量data ex16_2; input x1-x8 y @@; cards;proc logistic decending; model y=x1-x8/selection=stepwise sle=0.1 sls=0.1 sb; run;因子分析和主成分分析都是根据变量之间内部相关性来提取主要信息,获得新的变量(公因子变量和主成分变量),达到减少变量个数的目的。

SAS上机练习题及参考答案

SAS上机练习题及参考答案
重庆医科大学 卫生统计学统计软件包 SAS
上机实习指导 (含参考答案)
重庆医科大学统计学教研室 彭斌 编写 2010 年 12 月
SAS 上机练习题(一) 本 SAS 习题集由彭斌编写 2010.11.16
卫生统计学统计软件包习题
SAS 上机练习题(一)
1、SAS 常用的窗口有哪三个?请在三个基本窗口之间切换并记住这些命令或功能键。
2、请在 PGM 窗口中输入如下几行程序,提交系统执行,并查看 OUTPUT 窗和 LOG 窗中内容,注意不同 颜色的含义;并根据日志窗中的信息修改完善程序。
DATS EX0101;
INPUTT NAME $ AGE
CARDS;
XIAOMIN 19 1
LIDONG 20 1
NANA
18 2
;
PROD PRONT DATS=EX1;
140.5 143.4 152.9 147.5 147.7 162.6 141.6 143.6 144.0 150.6
150.8 147.9 136.9 146.5 130.6 142.5 149.0 145.4 139.5 148.9
141.8 148.1 145.4 134.6 130.5 145.2 146.2 146.4 142.4 137.1
SAS 上机练习题(一) 本 SAS 习题集由彭斌编写
表 3 某班同学几门功课的成绩
性别 高数 生理 人解 数理统计 形势(考查) (0=女,1=男)
1
73 73
64 74
75
1
90 79
71 85
78
1
97 87
89 91
80
1
40 60
61 65

SAS题目(含答案)

SAS题目(含答案)

1、某农村地区1999 年14 岁女孩的身高资料如下。

142.3 148.8 142.7 144.4 144.7 145.1 143.3 154.2 152.3 142.7 156.6137.9 143.9 141.2 139.3 145.8 142.2 137.9 141.2 150.6 142.7 151.3142.4 141.5 141.9 147.9 125.8 139.9 148.9 154.9 145.7 140.8 139.6148.8 147.8 146.7 132.7 149.7 154.0 158.2 138.2 149.8 151.1 140.1140.5 143.4 152.9 147.5 147.7 162.6 141.6 143.6 144.0 150.6 138.9150.8 147.9 136.9 146.5 130.6 142.5 149.0 145.4 139.5 148.9 144.5141.8 148.1 145.4 134.6 130.5 145.2 146.2 146.4 142.4 137.1 141.4144.0 129.4 142.8 132.1 141.8 143.3 143.8 134.7 147.1 140.9 137.4142.5 146.6 135.5 146.8 156.3 150.0 147.3 142.9 141.4 134.7 138.5146.6 134.5 135.1 141.9 142.1 138.1 134.9 146.7 138.5 139.6 139.2148.8 150.3 140.7 143.5 140.2 143.6 138.7 138.9 143.5 139.9 134.4133.1 145.9 139.2 137.4 142.3 160.9 137.7 142.9 126.8问题:(1)计算均数、中位数;计算均数的95%可信区间;(2)计算四分位间距、标准差、变异系数;计算标准误;\(3)请进行正态性检验;(4)观察频数分布情况(直方图);答:data a;input height@@;cards;142.3 148.8 142.7 144.4 144.7 145.1 143.3 154.2 152.3 142.7 156.6137.9 143.9 141.2 139.3 145.8 142.2 137.9 141.2 150.6 142.7 151.3142.4 141.5 141.9 147.9 125.8 139.9 148.9 154.9 145.7 140.8 139.6148.8 147.8 146.7 132.7 149.7 154.0 158.2 138.2 149.8 151.1 140.1140.5 143.4 152.9 147.5 147.7 162.6 141.6 143.6 144.0 150.6 138.9150.8 147.9 136.9 146.5 130.6 142.5 149.0 145.4 139.5 148.9 144.5141.8 148.1 145.4 134.6 130.5 145.2 146.2 146.4 142.4 137.1 141.4144.0 129.4 142.8 132.1 141.8 143.3 143.8 134.7 147.1 140.9 137.4142.5 146.6 135.5 146.8 156.3 150.0 147.3 142.9 141.4 134.7 138.5146.6 134.5 135.1 141.9 142.1 138.1 134.9 146.7 138.5 139.6 139.2148.8 150.3 140.7 143.5 140.2 143.6 138.7 138.9 143.5 139.9 134.4133.1 145.9 139.2 137.4 142.3 160.9 137.7 142.9 126.8;run;proc means mean median CLM qrange std cv stderr;var height;run;proc univariate normal;histogram height;(要先写univariate,再写histogram)var height;run;2.已知正常人某蛋白平均值为300。

SAS认证考试(官方练习题集和校正答案)

SAS认证考试(官方练习题集和校正答案)

1. A raw data file is listedbelow.The following program issubmitted using this file asinput:data work.family;infile 'file-specification';<insert INPUTstatement here>run;Which INPUT statementcorrectly reads the values forthe variable Birthdate asSAS date values?a.input relation$ first_name$ birthdate date9.;b.input relation$ first_name$ birthdatemmddyy8.;c.input relation$ first_name$ birthdate :date9.;d.input relation$ first_name$ birthdate :mmddyy8.;Correct answer: dAn informat is used to translate the calendar date to a SAS datevalue. The date values are in the form of two-digit values formonth-day-year, so the MMDDYY8. informat must be used.When using an informat with list input, the colon-formatmodifier is required to correctly associate the informat with thevariable name.You can learn about•informats in Reading Date and Time Values•the colon-format modifier in Reading Free-FormatData.2. A raw data file is listed below.1---+----10---+----20---+---Jose,47,210Sue,,108The following SAS program is submitted using the raw data fileabove as input:data employeestats;<insert INFILE statement here>input name $ age weight;run;The following output is desired:name age weightJose47210Sue.108Which of the following INFILE statements completes theprogram and accesses the data correctly?a.infile 'file-specification' pad;b.infile 'file-specification' dsd;c.infile 'file-specification' dlm=',';d.infile 'file-specification' missover;Correct answer: bThe PAD option specifies that SAS pad variable length recordswith blanks. The MISSOVER option prevents SAS fromreading past the end of the line when reading free formatteddata. The DLM= option specifies the comma as the delimiter;however, consecutive delimiters are treated as one by default.The DSD option correctly reads the data with commas asdelimiters and two consecutive commas indicating a missingvalue like those in this raw data file.You can learn about•the PAD option in Reading Raw Data in Fixed Fields•the MISSOVER option in Creating MultipleObservations from a Single Record•the DLM= option and the DSD option in Reading Free-Format Data.3. The following program is submitted:data numrecords;infile cards dlm=',';input agent1 $ agent2 $ agent3 $;cards;jones,,brownjones,spencer,brown;run;What is the value for the variable named Agent2 in the secondobservation?a.Brownb.Spencerc.' ' (missing character value)d.There is no value because only one observation iscreated.Correct answer: dThe CARDS statement enables you to read instream data. Anynumber of consecutive commas are considered to be a singledelimiter as a result of the DLM= option, and the length of eachvariable defaults to 8 bytes. Therefore, the values jones,brownjon, and spencer are assigned to Agent1, Agent2, andAgent3, respectively, for the first observation. The rest of thedata on the record is not read by the INPUT statement and is notoutput to the data set.You can learn about•the CARDS statement in Creating SAS Data Sets fromRaw Data•the default length of variables in Reading Free-FormatData.4. A raw data file is listed below.1---+----10---+----20---+----30---+----40---+----50TWOSTORY 1040 2 1SANDERS ROAD $55,850CONDO 2150 4 2.5JEANS AVENUE $127,150The following program is submitted using this file as input:data work.houses;infile 'file-specification';<insert INPUT statement here>run;Which one of the following INPUT statements reads the rawdata file correctly?a.input @1 style $8.+1 sqfeet 4.+1 bedrooms 1.@20 baths 3.street 16.@40 price dollar8;b.input @1 style $8+1 sqfeet 4.+1 bedrooms 1.@20 baths 3.street $16@40 price dollar8.;c.input @1 style $8.+1 sqfeet 4.+1 bedrooms 1.@20 baths 3.street $16.@40 price dollar8.;d.input @1 style $8.+1 sqfeet 4.+1 bedrooms 1.@20 baths 3street 16.@40 price dollar8.;Correct answer: cFormatted input requires periods as part of the informat name.The period is missing from the variables Style and Street inAnswer b, the variable Baths in Answer d, and the variablePrice in Answer a (which is also missing a dollar sign to readthe variable Street as a character value).You can learn about formatted input and informats in ReadingRaw Data in Fixed Fields.5. The following SAS program is submitted at the start of a newSAS session:libname sasdata 'SAS-data-library';data sasdata.sales;set sasdata.salesdata;profit=expenses-revenues;run;proc print data=sales;run;The SAS data set Sasdata.Salesdata has ten observations.Which one of the following explains why a report fails togenerate?a.The DATA step fails execution.b.The SAS data set Sales does not exist.c.The SAS data set Sales has no observations.d.The PRINT procedure contains a syntax error.Correct answer: bThe DATA step creates a permanent SAS data set,Sasdata.Salesdata. The PRINT procedure is printing atemporary SAS data set, Sales, that is stored in the Worklibrary. At the beginning of the SAS session, Work.Sales doesnot exist.You can learn about•creating permanent data sets with the DATA step inCreating SAS Data Sets from Raw Data•temporary data sets in Basic Concepts.6. Which action assigns a reference named SALES to a permanentSAS data library?a.Issuing the command:libref SALES 'SAS-data-library'b.Issuing the command:libname SALES 'SAS-data-library'c.Submitting the statement:libref SALES 'SAS-data-library';d.Submitting the statement:libname SALES 'SAS-data-library';Correct answer: dThe LIBNAME statement assigns a reference known as a librefto a permanent SAS data library. The LIBNAME commandopens the LIBNAME window.You can learn about the LIBNAME statement in ReferencingFiles and Setting Options.7. The following SAS program is submitted:data newstaff;set staff;<insert WHERE statement here>run;Which one of the following WHERE statements completes theprogram and selects only observations with a Hire_date ofFebruary 23, 2000?a.where hire_date='23feb2000'd;b.where hire_date='23feb2000';c.where hire_date='02/23/2000'd;d.where hire_date='02/23/2000';Correct answer: aA SAS date constant must take the form of one- or two-digitday, three-digit month, and two- or four-digit year, enclosed inquotation marks and followed by a d ('ddmmmyy<yy>'d).You can learn about SAS date constants in Creating SAS DataSets from Raw Data.8. Which one of the following SAS date formats displays the SASdate value for January 16, 2002 in the form of 16/01/2002?a.DATE10.b.DDMMYY10.c.WEEKDATE10.d.DDMMYYYY10.Correct answer: bThe requested output is in day-month-year order and is 10 byteslong, so DDMMYY10. is the correct format. AlthoughWEEKDATE10. is a valid SAS format, it does not display theSAS date value as shown in the question above.DDMMYYYY10. is not a valid SAS date format, and theDATE w. format cannot accept a length of 10.You can learn about•the DDMMYY10. format in Creating List Reports•the WEEKDATE10. format in Reading Date and TimeValues.9. Which one of the following displays the contents of an externalfile from within a SAS session?a.the LIST procedureb.the PRINT procedurec.the FSLIST procedured.the VIEWTABLE windowCorrect answer: cThe PRINT procedure and VIEWTABLE window display thevalues in SAS data sets. The FSLIST procedure displays thevalues in external files. There is no LIST procedure in SAS.You can learn about•the PRINT procedure in Creating List Reports•the VIEWTABLE window in Referencing Files andSetting Options.10. The SAS data set Sashelp.Prdsale contains the variablesRegion and Salary with 4 observations per Region.Sashelp.Prdsale is sorted primarily by Region and withinRegion by Salary in descending order.The following program is submitted:data one;set sashelp.prdsale;retain temp;by region descending salary;if first.region thendo;temp=salary;output;end;if last.region thendo;range=salary-temp;output;end;run;For each region, what is the number of observation(s) written tothe output data set?a.0b.1c. 2d.4Correct answer: cThe expression first.region is true once for each regiongroup. The expression last.region is true once for each regiongroup. Therefore, each OUTPUT statement executes once for atotal of 2 observations in the output data set.You can learn about the FIRST.variable expression and theOUTPUT 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 theCONTENTS procedure.Data Set Name SASUSER.HOUSES Observations15Member Type DATA Variables6Engine V9Indexes0Created Tuesday, April 22,2003 03:09:25 PMObservationLength56Last Modified Tuesday, April 22,2003 03:09:25 PMDeletedObservationsProtection Compressed NO Data Set Type Sorted NOLabel Residential housing for saleDataRepresentationWINDOWS_32Encoding wlatin1 Western (Windows)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: dThe exhibit above shows partial output from the CONTENTSprocedure, In the top right-hand column of the output, you seethat Indexes has a value of 0, which indicates that no indexesexist for this data set. Also, Sorted has a value of NO, whichindicates that the data is not sorted.You can learn about the CONTENTS procedure in ReferencingFiles 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 aresorted?a.The data set Work.Test is stored in ascending order byboth Fname and Salary values.b.The data set Work.Test is stored in descending order byboth Fname and Salary values.c.The data set Work.Test is stored in descending order byFname and ascending order by Salary values.d.The data set Work.Test is stored in ascending order byFname and in descending order by Salary values.Correct answer: dThe DESCENDING keyword is placed before the variable nameit modifies in the BY statement, so the correct description is indescending order by Salary value within ascending Fnamevalues.You can learn about the SORT procedure and theDESCENDING keyword in Creating List Reports.13. The following SAS program is submitted:data names;title='EDU';if title='EDU' thenDivision='Education';else if title='HR' thenDivision='Human Resources';else Division='Unknown';run;Which one of the following represents the value of the variableDivision in the output data set?catiocationc.Human Red.Human ResourcesCorrect answer: bThe length of the variable Division is set to 9 when the DATAstep compiles. Since the value of the variable Title is EDU, thefirst IF condition is true; therefore, the value of the variableDivision is Education.You can learn about•the length of a variable in Understanding DATA StepProcessing•IF-THEN statements in Creating and ManagingVariables.14. Which one of the following SAS programs creates a variablenamed City with a value of Chicago?a.data work.airports;AirportCode='ord';if AirportCode='ORD' City='Chicago';run;b.data work.airports;AirportCode='ORD';if AirportCode='ORD' City='Chicago';run;c.data work.airports;AirportCode='ORD';if AirportCode='ORD' then City='Chicago';run;d.data work.airports;AirportCode='ORD';if AirportCode='ORD';then City='Chicago';run;Correct answer: cThe correct syntax for an IF-THEN statement is: IF expressionTHEN statement;In this example, the variable City is assigned a value ofChicago only if the expression AirportCode='ORD' is true.You can learn about IF-THEN statements in Creating andManaging 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.6b.7c.10d.20Correct answer: aThe DATA step first goes through a compilation phase, then anexecution phase. The length of a variable is set during thecompilation phase and is based on the first time the variable isencountered. In this case, the variable code is set to the lengthof the text string DAL523 which is 6 characters long. The nextassignment statements are ignored during compilation. TheLENGTH statement is also ignored since the length has alreadybeen established, but a note will be written to the log.You can learn about•the compilation phase of the DATA step inUnderstanding DATA Step Processing•the LENGTH statement in Creating and ManagingVariables.16. Which of the following statements creates a numeric variablenamed IDnumber with a value of 4198?a.IDnumber=4198;b.IDnumber='4198';c.length IDnumber=8;d.length IDnumber $ 8;Correct answer: aThe first reference to the SAS variable in the DATA step setsthe name, type, and length of the variable in the program datavector (PDV) and in the output SAS data set. The assignmentstatement IDnumber=4198; is the first reference and creates anumeric variable named IDnumber with a default storage lengthof 8 bytes.You can learn about•creating variables in the DATA step in UnderstandingDATA Step Processing•numeric variables in Basic Concepts.17. The following program is submitted:data fltaten;input jobcode $ salary name $;cards;FLAT1 70000 BobFLAT2 60000 JoeFLAT3 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 thevalue for salary is 30000?a.Under 6b.Under 60c.Over 60d.' ' (missing character value)Correct answer: aThe variable description is being created by the IF-THEN/ELSE statement during compilation. The first occurrenceof the variable description is on the IF statement, and since itis assigned the value Over 60, the length of the variable is 7.Therefore, for the salary value of 30000, description has thevalue of Under 6 (the 0 is truncated.)You can learn about•the compilation phase of the DATA step inUnderstanding DATA Step Processing•IF-THEN/ELSE statements in Creating and ManagingVariables.18. A raw data file is listed below.1---+----10---+----20---+---102320The following program is submitted:data all_sales;infile 'file-specification';input receipts;<insert statement(s) here>run;Which statement(s) complete(s) the program and produce(s) arunning total of the Receipts variable?a.total+receipts;b.total 0;sum total;c.total=total+receipts;d.total=sum(total,receipts);Correct answer: aThe SUM function and the assignment statement do not retainvalues across iterations of the DATA step. The sum statementtotal+receipts; initializes total to 0, ignores missing valuesof receipt, retains the value of total from one iteration to thenext, and adds the value of receipts to total.You can learn about the sum statement in Creating andManaging Variables.19. A raw data file is listed below.1---+----10---+----20---+---1901 21905 11910 61925 11941 1The following SAS program is submitted and references the rawdata file above:data money;infile 'file-specification';input year quantity;total=total+quantity;What is the value of total when the data step finishesexecuting?a.0b.1c.11d. . (missing numeric value)Correct answer: dThe variable Total is assigned a missing value during thecompilation phase of the DATA step. When the first record isread in, SAS processes: total=.+2; which results in a missingvalue. Therefore the variable Total remains missing for allobservations.You can learn about•the compilation phase of the DATA step inUnderstanding DATA Step Processing•using missing values with arithmetic operators inCreating SAS Data Sets from Raw Data.20. The following program is submitted:data test;average=mean(6,4,.,2);run;What is the value of average?a.0b.3c.4d. . (missing numeric value)Correct answer: cThe MEAN function adds all of the non-missing values anddivides by the number of non-missing values. In this case, 6 + 4+ 2 divided by 3 is 4.You can learn about the MEAN function in Transforming Datawith SAS Functions.21. The following SAS program is submitted:data work.AreaCodes;Phonenumber=3125551212;Code='('!!substr(Phonenumber,1,3)!!')';run;Which one of the following is the value of the variable Code inthe output data set?a.( 3)b.(312)c.3d.312Correct answer: aAn automatic data conversion is performed whenever a numericvariable is used where SAS expects a character value. Thenumeric variable is written with the BEST12. format and theresulting character value is right-aligned when the conversionoccurs. In this example, the value of Phonenumber is convertedto character and right-aligned before the SUBSTR function isperformed. Since there are only 10 digits in the value ofPhonenumber, the right-aligned value begins with two blanks.Therefore the SUBSTR function picks up two blanks and a 3,and uses the BEST12. format to assign that value to Code. Then,the parentheses are concatenated before and after the two blanksand a 3.You can learn about automatic data conversion and theSUBSTR function in Transforming Data with SAS Functions.22. The following SAS program is submitted:data work.inventory;products=7;do until (products gt 6);products+1;end;run;Which one of the following is the value of the variableproducts in the output data set?a.5b.6c.7d.8Correct answer: dA DO UNTIL loop always executes at least once because thecondition is not evaluated until the bottom of the loop. In theSAS program above, the value of Products is incremented from7 to 8 on the first iteration of the DO UNTIL loop, before thecondition is checked. Therefore the value of Products is 8.You can learn about DO UNTIL loops in Generating Datawith DO Loops.23. The following program is submitted:data work.test;set work.staff (keep=salary1 salary2 salary3);<insert ARRAY statement here>run;Which ARRAY statement completes the program and createsnew variables?a.array salary{3};b.array new_salary{3};c.array salary{3} salary1-salary3;d.array new_salary{3} salary1-salary3;Correct answer: bAlthough each of the ARRAY statements listed above is a validstatement, only Answer B creates new variables namednew_salary1, new_salary2 and new_salary3. Answer C andAnswer D both create an array that groups the existing data setvariables salary1, salary2, and salary3. Since the array inAnswer A is named salary, it also uses the existing data setvariables.You can learn about creating new variables in an ARRAYstatement in Processing Variables with Arrays.24. Which of the following permanently associates a format with avariable?a.the FORMAT procedureb.a FORMAT statement in a DATA stepc.an INPUT function with format modifiersd.an INPUT statement with formatted style inputCorrect answer: bTo permanently associate a format with a variable, you use theFORMAT statement in a DATA step. You can use theFORMAT procedure to create a user-defined format. You usethe INPUT function to convert character data values to numericvalues with an informat. You use the INPUT statement to readdata into a data set with an informat.You can learn about•permanently assigning a format to a variable in Creatingand Managing Variables•the FORMAT statement in Creating List Reports•the FORMAT procedure in Creating and ApplyingUser-Defined Formats•the INPUT function in Transforming Data with SASFunctions•the INPUT statement in Reading Raw Data in FixedFields.25. The following report is generated:Which of the following steps created the report?a.proc freq data=sasuser.houses;tables style price /nocum;format price dollar10.;label style="Style of homes"price="Asking price";run;b.proc print data=sasuser.houses;class style;var price;table style,n price*mean*f=dollar10.;label style="Style of homes"price="Asking price";run;c.proc means data=sasuser.houses n mean;class style;var price;format price dollar10.;label style="Style of homes"price="Asking price";run;d.proc report data=sasuser.houses nowd headline;column style n price;define style / group "Style of homes";define price / mean format=dollar8."Asking price";run;Correct answer: dThe FREQ procedure cannot create the average asking price.The CLASS statement and the VAR statement are not valid foruse with the PRINT procedure. The MEANS procedure outputwould have both the N statistic and the N Obs statistic since aCLASS statement is used. The REPORT procedure producedYou can learn about•the FREQ procedure in Producing DescriptiveStatistics•the PRINT procedure in Creating List Reports•the MEANS procedure in Producing DescriptiveStatistics•the REPORT procedure in Creating Enhanced List andSummary Reports.26. A SAS report currently flows over two pages because it is toolong to fit within the specified display dimension. Which one ofthe following actions would change the display dimension sothat the report fits on one page?a.Increase the value of the LINENO option.b.Decrease the value of the PAGENO option.c.Decrease the value of the LINESIZE option.d.Increase the value of the PAGESIZE option.Correct answer: dThe PAGESIZE= SAS system option controls the number oflines that compose a page of SAS procedure output. Byincreasing the number of lines available per page, the reportmight fit on one page.You can learn about the PAGESIZE= option in ReferencingFiles and Setting Options.27. Which one of the following SAS REPORT procedure optionscontrols how column headings are displayed over multiplelines?a.SPACE=BEL=d.BREAK=Correct answer: bThe SPLIT= option specifies how to split column headings. TheSPACE=, LABEL= and BREAK= options are not valid optionsin PROC REPORT.You can learn about the SPLIT= option for the REPORTprocedure in Creating Enhanced List and Summary Reports.28. The following SAS program is submitted:ods html file='newfile.html';proc print data=sasuser.houses;run;proc means data=sasuser.houses;run;proc freq data=sasuser.shoes;run;ods html close;proc print data=sasuser.shoes;run;How many HTML files are created?a.1b.2c. 3d.4Correct answer: aBy default, one HTML file is created for each FILE= option orBODY= option in the ODS HTML statement. The ODS HTMLCLOSE statement closes the open HTML file and ends theoutput capture. The Newfile.html file contains the output fromthe PRINT, MEANS, and FREQ procedures.You can learn about the ODS HTML statement in ProducingHTML Output.29. A frequency report of the variable Jobcode in the Work.Actorsdata set is listed below.Jobcode Frequency Percent CumulativeFrequencyCumulativePercentActor I233.33233.33 Actor II233.33466.67 Actor III233.336100.00Frequency Missing = 1The following SAS program is submitted:data work.joblevels;set work.actors;if jobcode in ('Actor I', 'Actor II') thenjoblevel='Beginner';if jobcode='Actor III' thenjoblevel='Advanced';else joblevel='Unknown';run;Which of the following represents the possible values for the variable joblevel in the Work.Joblevels data set?a.Advanced and Unknown onlyb.Beginner and Advanced onlyc.Beginner, Advanced, and Unknownd.' ' (missing character value)Correct answer: aThe DATA step will continue to process those observations that satisfy the condition in the first IF statement Although Joblevel might be set to Beginner for one or more observations, the condition on the second IF statement willevaluate as false, and the ELSE statement will execute and overwrite the value of Joblevel as Unknown.You can learn about•the IF statement in Creating SAS Data Sets from RawData•the ELSE statement in Creating and ManagingVariables.30. The descriptor and data portions of the Work.Salaries data setare shown below.Variable Type Len Posname Char80salary Char816status Char88name status salaryLiz S15,600Herman S26,700Marty S35,000The following SAS program is submitted:proc print data=work.salaries;where salary<20000;run;What is displayed in the SAS log after the program is executed?a.A NOTE indicating that 1 observation is read.b.A NOTE indicating that 0 observations were read.c.A WARNING indicating that character values have beenconverted to numeric values.d.An ERROR indicating that the WHERE clause operatorrequires compatible variables.Correct answer: dSalary is defined as a character variable. Therefore, the valuein the WHERE statement must be the character value 20,000enclosed in quotation marks.You can learn about the WHERE statement in Creating ListReports.31. Which of the following statements is true when SAS encountersa syntax error in a DATA step?a.The SAS log contains an explanation of the error.b.The DATA step continues to execute and the resultingdata set is complete.c.The DATA step stops executing at the point of the errorand the resulting data set contains observations up to thatpoint.d.A note appears in the SAS log indicating that theincorrect statement was saved to a SAS data set forfurther examination.Correct answer: aSAS scans the DATA step for syntax errors during thecompilation phase. If there are syntax errors, those errors getwritten to the log. Most syntax errors prevent further processingof the DATA step.You can learn about how SAS handles syntax errors in theDATA step in Understanding DATA Step Processing.32. Which TITLE statement would display JANE'S DOG as the textof the title?a.title "JANE"S DOG";b.title 'JANE"S DOG';c.title "JANE'S DOG";d.title 'JANE' ' 'S DOG';Correct answer: c。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

重庆医科大学--卫生统计学统计软件包SAS上机练习题(一)1、SAS常用的窗口有哪三个?请在三个基本窗口之间切换并记住这些命令或功能键。

2、请在PGM窗口中输入如下几行程序,提交系统执行,并查看OUTPUT窗和LOG窗中内容,注意不同颜色的含义;并根据日志窗中的信息修改完善程序。

3、将第2题的程序、结果及日志保存到磁盘。

4、试根据如下例1的程序完成后面的问题:表1 某班16名学生3门功课成绩表如下问题:1)建立数据集;2)打印至少有1门功课不及格同学的信息;(提示,使用if语句)参考程序:data a;input id sh wl bl;cards;083 68 71 65084 74 61 68085 73 75 46086 79 80 79087 75 71 68084 85 85 87085 78 79 75086 80 76 79087 85 80 82088 77 71 75089 67 73 71080 75 81 70118 70 54 75083 70 66 84084 62 73 65099 82 70 79;run;data b;set a;if sh<60 or wl<60 or bl<60then output;run;proc print data=b;var id sh wl bl;run;5、根据下列数据建立数据集表2销售数据开始时间终止时间费用2005/04/28 25MAY2009 $123,345,0002005 09 18 05OCT2009 $33,234,5002007/08/12 22SEP2009 $345,600提示:(计算,如果读入错误,可试着调整格式的宽度;显示日期需要使用输出格式) 开始时间,输入格式yymmdd10.终止时间,输入格式date10.费用,输入格式dollar12.参考程序:data a;input x1 yymmdd10. x2 date10. x3 dollar13.;cards;2005/04/28 25MAY2009 $123,345,0002005 09 18 05OCT2009 $33,234,5002007/08/12 22SEP2009 $345,60020040508 30JUN2009 $432,334,500;run;proc print;run;proc print;format x1 yymmdd10. x2 date9. x3 dollar13.;run;6、手机号码一编码规则一般是:YYY-XXXX-ZZZZ,其YYY为号段;XXXX一般为所在地区编码;ZZZZ为对应的个人识别编号。

下面有一组电话号码(来源于网络,末位以X替换),请用程序完成下列要求:(1)分别列出属于联通、移动、电信的号码;(2)分别提取地区编号及个人识别编号。

(提示:列输入方式或者字符串操作)说明:移动:134-139、150、151、152、157、158、159、188联通:130、131、132、155、156电信:133、153、180、189参考程序:data a;input y 1-3 x $ 4-7 z $ 8-11;if134<=y<=139 or y in (150,151,152,157,158,159,188) then ygrp='移动';if y in (130,131,132,155,156) then ygrp='联通';if y in (133,153,180,189) then ygrp='电信';cards;1508320464X1510291126X1339644156X。

1513441713X1308279203X1897876466X;proc print;run;7、下表是某班学生几门功课的成绩,其中形势课是考查课,其它均为考试课。

请完成以下处理并且保存程序、结果和日志:(注意函数在DATA STEP中使用的位置)(1)用Mean()函数求出每位同学的平均分,将其保存在变量中;(2)用sum()函数或者表达式求出每位同学的总分,将其保存在变量中;(3)如果每门考试课权重是0.75,每门考查课权重为0.25,试求每位同学的加权平均分;(4)将数据集保存为永久数据集,保存位置为“D:\mydata\”;(5)调用上面的永久数据集,并将男、女生的成绩分别保存在数据集Dmale和Dfemale中。

参考程序:libname pb "D:\mydata\";data pb.score;input id$ xb gs sl rj sltj xs;mscore=mean(of gs sl rj sltj xs);tscore=sum(of gs sl rj sltj xs);wmscore= ((gs+sl+rj+sltj)*0.75+xs*0.25)/(0.75*4+0.25); cards;0083 1 73 73 64 74 750414 1 90 79 71 85 780564 1 97 87 89 91 800774 1 40 60 61 65 750873 1 68 65 60 76 750874 1 74 68 56 60 750875 1 73 46 65 66 870876 1 79 79 74 89 870877 1 75 68 55 60 700878 1 76 60 64 71 800880 1 81 73 60 75 820881 1 76 81 84 89 780883 1 77 60 60 66 750884 0 85 87 84 85 900885 0 78 75 62 66 800886 0 80 79 77 73 830887 0 85 82 81 84 800888 0 77 75 74 67 800889 0 67 71 71 69 900890 0 75 70 75 69 800891 0 69 76 76 79 900892 0 66 71 60 60 780893 1 70 84 75 80 850894 1 62 65 65 69 810895 1 91 78 61 66 780896 1 51 60 42 44 780898 1 67 73 67 73 850899 1 79 72 78 68 800900 1 76 68 63 84 900901 0 81 70 70 82 79;data dmale dfemale;set pb.score;if xb=1then output dmale;if xb=0then output dfemale;run;8、下面是3个大类疾病的ICD-10编码及对应的疾病名。

请完成以下任务:(1)建立数据集;(2)提取每种疾病的大类编码;(3)分别将3个大类的疾病存入3个数据集。

(提示:ICD10编码中小数点前面的三位表示大类;length语句定义字符变量长度;字符串取子串函数)表44类疾病的ICD10编码及对应疾病名ICD10 DiseaseA01.001 伤寒A01.002 伤寒杆菌性败血症A01.003+ 伤寒性脑膜炎A01.101 甲型副伤寒A01.201 乙型副伤寒A01.301 丙型副伤寒A01.401 副伤寒A02.001 B群沙门氏菌肠炎A02.002 C群沙门氏菌肠炎A02.004 沙门氏菌性肠炎A02.006 沙门氏菌胃肠炎A02.007 鼠伤寒沙门氏菌性肠炎A02.008 婴儿沙门氏菌肠炎A02.101 沙门氏菌败血症A02.201+ 沙门氏菌性肺炎A02.202+ 沙门氏菌性关节炎A02.203+ 沙门氏菌性脑膜炎A02.901 沙门氏菌感染A02.902 鼠伤寒沙门氏菌感染A02.903 沙门氏菌属食物中毒A03.001 什密氏志贺菌痢疾A03.101 弗氏志贺菌痢疾A03.201 鲍氏志贺菌痢疾A03.301 宋内氏志贺菌痢疾A03.802 菌痢混合感染A03.901 细菌性痢疾A03.902 慢性细菌性痢疾急性发作A03.903 慢性细菌性痢疾A03.905 慢性迁延型细菌性痢疾A03.906 中毒性痢疾参考程序:data a;input ICD10 $ Disease:$24.;cat=substr(ICD10,1,3);cards;A01.001 伤寒A01.002 伤寒杆菌性败血症A01.003+ 伤寒性脑膜炎A01.101 甲型副伤寒A01.201 乙型副伤寒A01.301 丙型副伤寒A01.401 副伤寒A02.001 B群沙门氏菌肠炎A02.002 C群沙门氏菌肠炎A02.004 沙门氏菌性肠炎A02.006 沙门氏菌胃肠炎A02.007 鼠伤寒沙门氏菌性肠炎A02.008 婴儿沙门氏菌肠炎A02.101 沙门氏菌败血症A02.201+ 沙门氏菌性肺炎A02.202+ 沙门氏菌性关节炎A02.203+ 沙门氏菌性脑膜炎A02.901 沙门氏菌感染A02.902 鼠伤寒沙门氏菌感染A02.903 沙门氏菌属食物中毒A03.001 什密氏志贺菌痢疾A03.101 弗氏志贺菌痢疾A03.201 鲍氏志贺菌痢疾A03.301 宋内氏志贺菌痢疾A03.802 菌痢混合感染A03.901 细菌性痢疾A03.902 慢性细菌性痢疾急性发作A03.903 慢性细菌性痢疾A03.905 慢性迁延型细菌性痢疾A03.906 中毒性痢疾;data cat01 cat02 cat03;set a;if cat='A01'then output cat01;if cat='A02'then output cat02;if cat='A03'then output cat03;run;9、现有两个文件,内容如下:要求:打印至少有一门功课不及格的同学的年龄、性别和班级。

参考程序:data fileA;input no$ tj ty age;cards;01 87 83 2302 56 96 2203 93 75 1904 77 84 2405 88 55 18;data fileB;input no$ sex$ bj;cards;01 男 102 女 103 男 304 男 205 女 208 女 3;proc sort data=fileA;by no;proc sort data=fileB;by no;data fileAB;merge fileA fileB;by no;if min(tj,ty)<60 and min(tj,ty) > . ;run;proc print;run;10、显示100到200以内的素数。

相关文档
最新文档