SAS统计软件试题
sas测试题及答案

sas测试题及答案1. SAS中,如何将一个数据集的所有变量的值增加10?A. data dataset; set dataset; +10; run;B. data dataset; set dataset; +10; quit;C. data dataset; set dataset; +10; run;D. data dataset; set dataset; +10;答案:C2. 在SAS中,如何创建一个新的数据集,并将原数据集中的变量`Var1`和`Var2`复制到新数据集中?A. data new_dataset; set old_dataset; Var1 =old_dataset.Var1; Var2 = old_dataset.Var2; run;B. data new_dataset; set old_dataset; Var1 = Var1; Var2 = Var2; run;C. data new_dataset / old_dataset; set old_dataset; Var1 = old_dataset.Var1; Var2 = old_dataset.Var2; run;D. data new_dataset; set old_dataset; Var1 = Var1; Var2 = Var2; quit;答案:A3. SAS中,如何使用`proc print`步骤打印数据集的前10行?A. proc print data=dataset firstobs=10;B. proc print data=dataset firstobs=1 obs=10;C. proc print data=dataset firstobs=10;D. proc print data=dataset firstobs=1 obs=10;答案:B4. 在SAS中,如何使用`if-then`语句来创建一个新的变量`NewVar`,当`Var1`大于10时,`NewVar`的值为`Var1`的两倍,否则为0?A. data dataset; set dataset; if Var1 > 10 then NewVar = 2 * Var1; else NewVar = 0; run;B. data dataset; set dataset; if Var1 > 10 then NewVar = 2 * Var1; NewVar = 0; run;C. data dataset; set dataset; if Var1 > 10 NewVar = 2 *Var1; else NewVar = 0; run;D. data dataset; set dataset; if Var1 > 10 then NewVar = 2 * Var1; else NewVar = 0; quit;答案:A5. SAS中,如何使用`proc means`步骤计算数据集中`Var1`的平均值?A. proc means data=dataset N mean of Var1;B. proc means data=dataset N mean Var1;C. proc means data=dataset N=mean Var1;D. proc means data=dataset N mean Var1;答案:D结束语:以上是SAS测试题及答案,希望能够帮助您更好地理解和掌握SAS编程的基础知识。
sas期末考试题

sas期末考试题一、选择题(每题3分,共30分)1. SAS系统中,用于读取数据集的语句是:A. proc print data=dataset;B. data=dataset;C. set dataset;D. read dataset;2. 在SAS中,以下哪个函数用于计算数据集的中位数?A. meanB. medianC. modeD. sum3. 如果需要在SAS中对数据进行排序,应该使用哪个过程?A. proc means;B. proc sort;C. proc print;D. proc univariate;4. 在SAS中,如何创建一个新的数据集?A. 使用proc step过程B. 使用data step过程C. 使用proc print过程D. 使用proc means过程5. SAS中,哪个语句用于将两个数据集合并?A. mergeB. appendC. combineD. join6. 在SAS中,如何将一个变量的值赋给另一个变量?A. setB. assignC. putD. set7. SAS中,哪个函数用于计算数据集的最大值?A. maxB. minC. rangeD. high8. 在SAS中,如何将一个数据集中的数据按特定变量分组?A. 使用by语句B. 使用where语句C. 使用if语句D. 使用select语句9. SAS中,哪个过程用于生成描述性统计量?A. proc means;B. proc print;C. proc univariate;D. proc sort;10. 在SAS中,如何将一个数据集的数据输出到一个新的文件中?A. 使用output out=语句B. 使用print to=语句C. 使用write to=语句D. 使用save to=语句二、简答题(每题5分,共20分)1. 描述SAS中数据步(data step)的主要功能,并给出一个简单的示例。
sas练习题(打印版)

sas练习题(打印版)### SAS练习题(打印版)#### 一、基础数据操作1. 数据导入- 题目:使用SAS导入一个CSV文件,并列出前5个观测值。
- 答案:使用`PROC IMPORT`过程导入数据,并用`PROC PRINT`展示前5个观测。
2. 数据筛选- 题目:筛选出某列数据大于50的所有观测。
- 答案:使用`WHERE`语句进行筛选。
3. 数据分组- 题目:根据某列数据对数据集进行分组,并计算每组的均值。
- 答案:使用`PROC MEANS`过程和`BY`语句进行分组和计算。
4. 数据排序- 题目:按照某列数据的升序或降序对数据集进行排序。
- 答案:使用`PROC SORT`过程进行排序。
#### 二、描述性统计分析1. 单变量分析- 题目:计算某列数据的均值、中位数、标准差等统计量。
- 答案:使用`PROC UNIVARIATE`过程进行单变量描述性统计分析。
2. 频率分布- 题目:计算某列数据的频数和频率分布。
- 答案:使用`PROC FREQ`过程进行频率分布分析。
3. 相关性分析- 题目:计算两列数据的相关系数。
- 答案:使用`PROC CORR`过程计算相关系数。
#### 三、假设检验1. t检验- 题目:对两组独立样本的均值进行t检验。
- 答案:使用`PROC TTEST`过程进行t检验。
2. 方差分析- 题目:对多个组别数据进行方差分析。
- 答案:使用`PROC ANOVA`过程进行方差分析。
3. 卡方检验- 题目:对分类变量进行卡方检验。
- 答案:使用`PROC FREQ`过程和`CHI2TEST`选项进行卡方检验。
#### 四、回归分析1. 简单线性回归- 题目:使用一个自变量和一个因变量进行简单线性回归分析。
- 答案:使用`PROC REG`过程进行简单线性回归。
2. 多元线性回归- 题目:使用多个自变量和一个因变量进行多元线性回归分析。
- 答案:同样使用`PROC REG`过程,但包括多个自变量。
SAS统计软件知识要点与试题库

SAS 统计软件知识要点与试题库1. 试述SAS系统中PGM、EDITOR、OUTPUT、EXPLORER、RESULT和LOG窗口的功能。
2. 窗口切换(移至前台并击活)可用以下任一种做法实现:(1)点击窗口本身;(2)由菜单项“窗口(W)”可切换到已打开的窗口,或由查看(View)加入新窗口;(3) Ctrl + T ab 依次切换;(4) 用设置的热键; (5) 发布命令;(6) 点击窗口条中某一窗口图标.3. 发布命令有四种方式:在命令框直接键入命令;使用下拉菜单(弹出菜单);使用工具条;按功能键(KEYS命令显示功能键所表示的命令).4. SAS数据集可以读取的数据类型:数据行直接输入、流行的数据库、其它文件格式5. SAS数据集的描述部分(创建与修改日期,引擎,变量名,类型,长度,标题,格式等)6. 字符型变量的缺失值用空格符表示数值型变量的缺失值用句号“ . ”表示7. SAS逻辑库包括临时库、永久库两种,区别?8. ViewT able窗口提供两种打开数据的方式:Browse模式和Edit模式,区别?9. SAS数据集的变量属性有6个,哪六个?(变量名及标签,类型,长度,输入输出格式).10. 在SAS系统中浏览和编辑SAS数据集一般必须先设定SAS逻辑库(文件库),然后将要浏览和编辑的数据集存放在已设定的SAS逻辑库(文件库)中.11. 多个SAS逻辑库可与同一个物理位置项连接;一个SAS逻辑库也可与多个物理位置相连接.12. 新建逻辑库(New Library)的方法:1. 按工具条上图标(New Library)可进入设定新的SAS逻辑库的N ew Library窗口;2. 资源管理器(浏览器)窗口击活时,在下拉菜单中选:文件(File) ⇒新建(New… )⇒逻辑库=>可进入设定新建逻辑库(New Library)窗口.3. 在“SAS 环境”(Environment)处击右键,在弹出的菜单中选新建(New …)=>逻辑库,也可进入新建逻辑库(New Library)窗口.13. 上机试题(1).用菜单方法建立新库(库标志名为dsta),此库包含本课程所使用的sas数据集; (2).用两种方法(菜单或命令)进入ViewT able窗口,并浏览数据集class;(3)先浏览class中SEX=…F‟的观测及AGE>=14的观测,然后浏览全部观测;(4)浏览数据集class的描述信息和数据内容;(5)浏览SAS永久库SASUSER的属性和内容,并浏览数据集AIR的描述信息和数据内容.14. 数据集名应由字母或下划线开始且不超过32个(V6为8) 个字节的字符、数字或下划线构成. 变量名,数组名,库名15. 上机(1). 用VT命令进入ViewT able窗口,直接输入数据并进行编辑修改后存为sas数据集; (2). 使用Import窗口菜单系统,将*.txt 转换为sas数据集;(3). 用数据步建立SAS数据集.16. SAS的Import/Export菜单界面提供一个使用菜单的图形界面:17. SAS语句书写的格式较为灵活:语句可以在某一行的任何位置开始和结束;词间可任意加入空格和换行;一个语句可以写成几行,只要语句中的单词不被断开就可以;多个语句可写在一行;SAS语句用大写字母、小写字母或两者混合书写均可以.18. 通常用DAT A步产生SAS数据集,而用PROC步对SAS数据集中的数据进行分析处理并输出结果. 一个SAS程序可由一个DAT A步或一个PROC步组成;或者由DAT A 步和PROC步两部分组成;也可由多个DAT A步和PROC步组成.19. SAS的字符型变量缺省的长度是8个字符,可以用LENGTH语句直接指定变量长度。
sas期末考试试题

sas期末考试试题SAS期末考试试题一、选择题(每题2分,共20分)1. 在SAS中,以下哪个命令用于创建数据集?A. PROC SORTB. DATASETSC. SETD. INPUT2. 下列哪个选项不是SAS数据集中的变量属性?A. 长度B. 格式C. 标签D. 颜色3. SAS中的PROC FREQ过程用于:A. 描述性统计分析B. 频率分布分析C. 回归分析D. 时间序列分析4. 以下哪个命令用于在SAS中生成随机数?A. RANDB. RANDOMC. RNDD. UNIVARIATE5. 在SAS中,如何使用PROC GPLOT创建图形?A. 使用PLOT语句B. 使用SGPLOT过程C. 使用GPLOT语句D. 使用GRAPH语句二、简答题(每题10分,共30分)1. 解释SAS中的宏语言及其用途。
2. 描述如何使用SAS进行数据清洗的基本步骤。
3. 简述SAS中PROC UNIVARIATE过程的功能和应用场景。
三、编程题(每题25分,共50分)1. 编写SAS程序,从一个名为“sales_data”的数据集中提取出所有销售额超过平均销售额的产品,并计算这些产品的总销售额。
```sasdata sales_data;set sales_data;if sales > mean(sales);run;proc means data=sales_data mean;var sales;output out=avg_sales mean=avg_sales;run;data top_sales;set sales_data;where sales > avg_sales.avg_sales;run;proc sql;select sum(sales) into: total_salesfrom top_sales;quit;```2. 编写SAS程序,使用PROC REG过程对一个名为“education_data”的数据集进行线性回归分析,预测学生的考试成绩(变量名为“score”)基于其学习时间(变量名为“study_hours”)。
sas 面试题

sas 面试题SAS面试题SAS(Statistical Analysis System)是一种广泛使用的统计分析软件,它提供了强大的数据分析和管理工具。
在求职过程中,面试官通常会提出各种关于SAS的问题,以评估面试者对该软件的熟悉程度和应用能力。
本文将介绍一些常见的SAS面试题,帮助读者更好地准备SAS相关的面试。
一、基础问题1. 什么是SAS?它有什么功能?SAS是一种基于GUI的统计分析软件,用于数据的管理、分析和预测。
它具有数据访问、数据转换、数据建模和数据可视化等功能。
2. 如何导入数据到SAS中?可以使用DATA步骤或者PROC IMPORT命令导入数据到SAS中。
DATA步骤适用于手动编写SAS代码导入数据,PROC IMPORT命令适用于自动从外部文件导入数据。
3. 如何选择变量?可以使用DATA步骤中的DROP和KEEP子语句来选择变量。
DROP子语句用于删除不需要的变量,KEEP子语句用于保留指定的变量。
4. 如何对数据进行排序?可以使用PROC SORT命令对数据进行排序。
可以通过指定BY子句来选择一个或多个变量作为排序依据。
二、高级问题1. 什么是宏变量?如何定义和使用宏变量?宏变量是一种可以在SAS程序中使用和定义的变量,它起到类似于替代符号的作用。
可以使用%LET语句来定义宏变量,并使用&符号来引用宏变量。
2. 如何创建SAS数据集?可以使用DATA步骤和SET语句来创建SAS数据集。
DATA步骤用于创建新的数据集,SET语句用于将已有数据集导入到当前数据集。
3. 如何进行数据转换?可以使用DATA步骤中的IF、WHERE、RENAME和FORMAT等语句来进行数据转换。
IF和WHERE语句用于筛选数据行,RENAME语句用于修改变量名,FORMAT语句用于改变变量的格式。
4. 如何进行数据合并?可以使用DATA步骤中的MERGE和JOIN语句来进行数据合并。
sas考试题库及答案

sas考试题库及答案1. 在SAS中,如何使用`proc print`步骤来输出数据集的前几行?A. 使用`proc print data=dataset;`命令B. 使用`proc print data=dataset firstobs=5;`命令C. 使用`proc print data=dataset first=5;`命令D. 使用`proc print data=dataset top;`命令正确答案是B。
2. 如果想要在SAS中创建一个数据集,并将某个变量的值替换为缺失值,应该如何操作?A. 使用`data`步骤和`if`语句B. 使用`data`步骤和`replace`函数C. 使用`proc sql`步骤D. 使用`proc means`步骤正确答案是A。
3. 在SAS中,如何将一个数据集的列名从`Var1`更改为`Variable1`?A. 使用`rename`语句:`rename Var1=Variable1;`B. 使用`rename`语句:`rename Variable1=Var1;`C. 使用`proc contents`步骤D. 使用`proc print`步骤正确答案是A。
4. 如何在SAS中使用`proc means`步骤来计算数据集的描述性统计量?A. 使用`proc means data=dataset;`命令B. 使用`proc means data=dataset N NMISS MEAN MEDIAN MAX MIN;`命令C. 使用`proc means data=dataset out=means;`命令D. 使用`proc means data=dataset out=means N NMISS MEAN MEDIAN MAX MIN;`命令正确答案是D。
5. 在SAS中,如何使用`proc sort`步骤对数据集进行排序?A. 使用`proc sort data=dataset;`命令B. 使用`proc sort data=dataset out=sorted_dataset;`命令C. 使用`proc sort data=dataset by variable;`命令D. 使用`proc sort data=dataset out=sorted_dataset by variable;`命令正确答案是D。
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、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SAS统计软件试题2008
一、SAS的逻辑库可分为永久库和临时库两种,请编写一段程序直接建立临时库中的下例
数据集,并按升序排序。
(10分)
数据名tong:20 13 20 16 23 19 19 16
答:data tong;
input x@@;
cards;
20 13 20 16 23 19 19 16
;
proc sort;
by descending x;
run;
二、请编写一段程序把数据2并列合并到数据1之后。
(20分)
数据1:
LiuWei M 21 175 65 A
ZhouLan F 20 160 46 O
DengXue F 22 158 45 B
ZhuJun M 23 177 68 O
HuangXiaoming M 19 173 65 O
数据2:
ChenQiong F 19 155 45 A
ZhaoFeng M 22 179 66 B
ZhangBin M 22 173 64 O
WeiLin F 20 162 46 A
ShiQiang M 21 180 70 B
答:data shuju1;
input name $ sex $ age hight weight type $;
cards;
LiuWei M 21 175 65 A
ZhouLan F 20 160 46 O
DengXue F 22 158 45 B
ZhuJun M 23 177 68 O
HuangXiaoming M 19 173 65 O
;
data shuju2;
input name $ sex $ age hight weight type $;
cards;
ChenQiong F 19 155 45 A
ZhaoFeng M 22 179 66 B
ZhangBin M 22 173 64 O
WeiLin F 20 162 46 A
ShiQiang M 21 180 70 B
;
data shuju;
set shuju1 shuju2; /*set表示纵向合并*/
run;
三、 1. 数据1( suju1.txt)和数据2( suju2.txt)为存放在E:\myfile中的两个文本文件,请编写一段程序读入外部数据,建立成SAS的临时库中的两个数据集。
(10分)
答:data suju1;
infile 'e:\myfile\suju1.txt';
input number doornum cardnum;
data suju2;
infile 'e:\myfile\suju2.txt';
input name$ sex$ age;
run;
2. 把数据1合并到数据2的尾部。
(10分)
数据1:suju1.txt
115031 201 2655020
105002 304 5641405
115005 313 2577845
115020 105 5650011
105011 413 5643257
数据2:suju2.txt
YangLan F 21
XuZhangxiang M 22
WangYu M 20
HouLin F 19
LiangTian M 21
答:data suju;
merge suju2 suju1;
run;
四、(20分) 对六种不同的农药在相同的条件下分别进行杀虫试验,试验结果如下表所示。
试检验农药(因素A)的品种对杀虫率是否有显著影响。
用SAS分析如下,请将空白处补充完整。
The ANOVA Procedure
Dependent Variable: a
Sum of
Source DF Squares Mean Square F Value Pr > F
Model 5 3794.5 758.9 51.16 <.0001
Error 12 178 14.83333
Corrected Total 17 3972.5
The ANOVA Procedure
Levene's Test for Homogeneity of a Variance ANOVA of Squared Deviations from Group Means
Sum of Mean
Source DF Squares Square F Value Pr > F b 3 83.9182 27.9727 0.32 0.8083 Error 10 864.0 86.4042
由第2个表,我们得出的结果是:
由第1水准上,拒绝0H ,接受1H ,认为农药种类对杀虫效果影响显著。
五、(20分) 为了考察化肥施用量
x 与水稻产量y
之间的关系,在土质、面
积、种子等相同条件下,由试验取得了如下的数据:
化肥用量x (kg) 15 20 25 30 35 40 45
水稻产量y
(kg) 330 345 365 405 445 490 455
1. 作出散点图,并分析x 与y 之间的关系。
用SAS 分析的结果如下,请将空白处补充完整。
Analysis of Variance
Sum of Mean
Source DF Squares Square F Value Pr > F
Model 1 Error 5 2327.67857 465.53571 Corrected Total 6 22150
Root MSE 21.57628 R-Square 0.8949 Dependent Mean 405.00000 Adj R-Sq 0.8739 Coeff Var 5.32748
Parameter Estimates
Parameter Standard Standardized
Variable DF Estimate Error t Value Pr > |t| Estimate
Analysis of Variance 表说明了: 直线回归模型线性显著。
Parameter Estimates
2.问:比较若分别建立直线、二次抛物线、立方抛物线方程,哪一个拟合的最好?
答:简单回归分析的3种模型的比较如下表:
通过上表可以看出,在 =0.05的水准上,都有显著意义。
立方抛物线方程的均方根最小,相关指数最大,表明立方抛物线方程拟合得最好。