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考试试卷(A)(答案)

暨 南 大 学 考 试 试 卷一、填空题(共10空,每空2分,共20分)1. 一个完整的SAS 程序由二部分组成: _数据 __步与_ 过程 __步.2. 多元统计分析中的判别分析与聚类分析的本质区别是: _类别是否已知,若已知,则为判别分析;否则为聚类分析 _.3. 进行数值资料的描述统计描述的两个基本SAS 过程是: _MEANS _过程与__ _UNIVARIATE _过程.4. 把多个SAS 数据集进行横向合并、纵向合并所用的语句分别是_MERGE _ 语句、__SET _语句.5. 进行分类资料的统计分析的两个基本SAS 过程是: _ LOGISTIC __过程与_ FREQ __过程.6. 进行数值资料的方差分析的两个基本SAS 过程是: _ ANOVA __过程与_ GLM __过程.7. 在SAS 中,可用于进行相关分析的过程常用的有:简单线性相关及等级相关的_ CORR _过程与典型相关的_ CANCORR _过程.8. 秩和检验的SAS 过程中最常用的有二种:一是用于配对设计数值变量资料符号秩和验的 UNIVARIATE _过程,另一是用于成组设计两样本比较及多个样本比较的秩和检验的 _ NPAR1WAY _过程.9. GLM 过程可用于:进行(1)非均衡设计资料的 方差分析 _、(2)协方差分析及建立(3)_ 多项式 _回归.10. 在SAS 中,可用于进行数值资料回归分析的过程常用的有:一元及多元线性回归的 REG _过程与非线性回归的_ NLIN _过程.(一)SAS 数据集E3是对20名25∽34岁的健康妇女进行体检取得的,现需要建立由头肌皮褶厚度(1X ,cm),大腿围(2X ,cm)及中臂围(3X ,cm)预测身体脂肪(Y ,cm)分布的方程. 运行SAS 某些过程,有以下SAS 运行结果:The REG ProcedureModel: M1Dependent Variable: yAnalysis of VarianceSum of MeanSource DF Squares Square F Value Pr > F Model 3 396.98461 132.32820 21.52 <.0001Error 16 98.40489 6.15031Corrected Total 19 495.38950Root MSE 2.47998 R-Square 0.8014Dependent Mean 20.19500 Adj R-Sq 0.7641Coeff Var 12.28017Parameter EstimatesParameter Standard Variance Variable DF Estimate Error t Value Pr > |t| Inflation Intercept 1 117.08469 99.78240 1.17 0.2578 0 x1 1 4.33409 3.01551 1.44 0.1699 708.84291 x2 1 -2.85685 2.58202 -1.11 0.2849 564.34339 x3 1 -2.18606 1.59550 -1.37 0.1896 104.60601The PRINCOMP ProcedureCorrelation Matrixx1 x2 x3x1 1.0000 0.9238 0.4578x2 0.9238 1.0000 0.0847x3 0.4578 0.0847 1.0000Eigenvalues of the Correlation MatrixEigenvalue Difference Proportion Cumulative1 2.06647268 1.13367198 0.6888 0.68882 0.93280070 0.93207408 0.3109 0.99983 0.00072662 0.0002 1.0000Eigenvectorsz1 z2 z3x1 0.694696 -.050106 -.717557x2 0.629428 -.440509 0.640135x3 0.348164 0.896349 0.274482The REG ProcedureModel: M2Dependent Variable: yAnalysis of VarianceSum of MeanSource DF Squares Square F Value Pr > FModel 3 396.98461 132.32820 21.52 <.0001Error 16 98.40489 6.15031Corrected Total 19 495.38950Root MSE 2.47998 R-Square 0.8014Dependent Mean 20.19500 Adj R-Sq 0.7641 Coeff Var 12.28017Parameter EstimatesParameter Standard Variance Variable DF Estimate Error t Value Pr > |t| Inflation Intercept 1 20.19500 0.55454 36.42 <.0001 0 z1 1 2.93576 0.39578 7.42 <.0001 1.00000 z2 1 -1.64976 0.58908 -2.80 0.0128 1.00000 z3 1 -27.38341 21.10659 -1.30 0.2129 1.000001.为建立Y 关于321,,X X X 的线性回归方程,需应用的SAS 过程为:A. LOGISTIC 过程B.NLIN 过程C.GLM 过程D.REG 过程 2.由所建立的线性回归方程可见: 用321,,X X X 来解释Y 的变动,只可以解释其中的( )%, 在0.05的显著性水平之下,有显著影响的因素有( )个, 而且三因素间( )共线性现象.A.80.14%, 0, 存在B. 80.14%, 0, 不存在C.76.41%, 0, 不存在D. 80.14%, 3, 存在3.根据对321,,X X X 所作的主成分分析,SAS 运行结果表明, 相关矩阵的最大特征值为( ),实际应用中(按80%的原则),需要选取的主成分为( )个. A. 2.06647268,1 B. 1.13367198,1 C. 2.06647268,2 D. 1.13367198,24.根据对321,,X X X 所作的主成分分析,SAS 运行结果表明,第一主成分为=1ZA. 3213481.06294.06947.0X X X ++B. 3212745.06401.07176.0X X X ++-C.3218963.04405.00501.0X X X +--D.以上结果都不对5. 根据SAS 运行结果,取Y 关于主成分321,,Z Z Z 的线性回归方程,能有效地消除多重共线性,所得的线性回归方程为 332211ˆˆˆ1950.20ˆZ Z Z Y βββ+++=,其中: =1ˆβA. 0.8014B. 2.93576C.0.39578D. 7.42(二)为110名7岁男童身高资料(SAS数据集名为P6),试编制频数表,计算描述性统计量并进行正态性检验. 运行SAS某些过程,有以下SAS运行结果:The UNIVARIATE ProcedureVariable: xMomentsN 110 Sum Weights 110Mean 119.727273 Sum Observations 13170Std Deviation 4.74132543 Variance 22.4801668Skewness 0.15461074 Kurtosis -0.0252871Uncorrected SS 1579258.52 Corrected SS 2450.33818Coeff Variation 3.96010476 Std Error Mean 0.45206764Basic Statistical MeasuresLocation VariabilityMean 119.7273 Std Deviation 4.74133Median 119.9000 Variance 22.48017Mode 114.3000 Range 24.30000Interquartile Range 6.40000NOTE: The mode displayed is the smallest of 5 modes with a count of 3.Tests for NormalityTest --Statistic--- -----p Value------Shapiro-Wilk W 0.993143 Pr < W 0.8623Kolmogorov-Smirnov D 0.055958 Pr > D >0.1500Cramer-von Mises W-Sq 0.036956 Pr > W-Sq >0.2500Anderson-Darling A-Sq 0.231585 Pr > A-Sq >0.2500回答以下问题:6.为编制频数表,所使用的SAS过程为:A. FREQ 过程B. MEANS 过程C. UNIVARIATE 过程D.TTEST 过程7.要计算诸如除均值,标准差,最值之外的统计量,还要计算众数,中位数,四分位间距等描述性统计量,需要使用的SAS过程为:A. FREQ 过程B. MEANS 过程C. UNIVARIATE 过程D.REG 过程8.为进行分布的正态性检验, 需在所使用的UNIVARIATE过程( )语句中加上NORMAL选项.A. VAR 语句B. PROC UNIVARIATE 语句C. MODEL 语句D.BY 语句9.根据SAS运行结果, 样本中位数为:A. 119.7273B. -0.0253C. 119.9000D. 114.300010.根据SAS运行结果, 可认为在显著性水平( )下所给的身高资料( )正态分布.A.0.05,服从B. 0.5, 服从C. 0.05,不服从D. 0.5 不服从调查1329名血中胆固醇(CHO)含量及成人血压(SBP)和冠心病(D)的关系,得到如下表所示的列联表:要求进行相应的统计分析. 运行SAS某些过程,有以下SAS运行结果:The FREQ ProcedureSummary Statistics for case by choCochran-Mantel-Haenszel Statistics (Based on Table Scores)Statistic Alternative Hypothesis DF Value Prob ---------------------------------------------------------------1 Nonzero Correlation 1 26.1475 <.00012 Row Mean Scores Differ 1 26.1475 <.00013 General Association 3 35.0021 <.0001The FREQ ProcedureSummary Statistics for case by sbpCochran-Mantel-Haenszel Statistics (Based on Table Scores)Statistic Alternative Hypothesis DF Value Prob ---------------------------------------------------------------1 Nonzero Correlation 1 21.9444 <.00012 Row Mean Scores Differ 1 21.9444 <.00013 General Association 3 28.9441 <.0001The LOGISTIC ProcedureModel InformationData Set WORK.EX_905Response Variable caseNumber of Response Levels 2Frequency Variable countModel binary logitOptimization Technique Fisher's scoringProbability modeled is case=1.NOTE: 1 observation having nonpositive frequency or weight was excluded since it does not contribute to the analysis.Model Convergence StatusConvergence criterion (GCONV=1E-8) satisfied.Deviance and Pearson Goodness-of-Fit StatisticsCriterion Value DF Value/DF Pr > ChiSqDeviance 14.8472 13 1.1421 0.3170Pearson 13.4287 13 1.0330 0.4153Model Fit StatisticsInterceptIntercept andCriterion Only CovariatesAIC 670.831 630.952SC 676.024 646.529-2 Log L 668.831 624.952Testing Global Null Hypothesis: BETA=0Test Chi-Square DF Pr > ChiSqLikelihood Ratio 43.8791 2 <.0001Score 43.3635 2 <.0001Wald 40.2202 2 <.0001The LOGISTIC ProcedureAnalysis of Maximum Likelihood EstimatesStandard WaldParameter DF Estimate Error Chi-Square Pr > ChiSqIntercept 1 -5.0916 0.4428 132.2333 <.0001cho 1 0.5300 0.1166 20.6717 <.0001 sbp 1 0.4405 0.1091 16.2992 <.0001Odds Ratio EstimatesPoint 95% WaldEffect Estimate Confidence Limits cho 1.699 1.352 2.135 sbp 1.553 1.254 1.924Association of Predicted Probabilities and Observed ResponsesPercent Concordant 66.3 Somers' D 0.393 Percent Discordant 26.9 Gamma 0.422 Percent Tied 6.8 Tau-a 0.051 Pairs 113804 c 0.6971.就所给的资料,为分析胆固醇(CHO)、收缩压(SBP)是否为冠心病(CASE)的危险因素,可考虑应用的SAS 过程有:A.CORR 过程B.GLM 过程C.FREQ 过程D.LOGISTIC 过程E.REG 过程2.根据SAS 运行结果,在0.05的显著性水平下,就胆固醇与冠心病的关系分析,正确的结论为:A. 胆固醇是冠心病的危险因素B. 胆固醇不是冠心病的危险因素C. 对应的CHM 检验的=2χ35.0021D. 对应的CHM 检验的=2χ26.1475E. 对应的CHM 检验的p 值<.00013.根据SAS 运行结果, 在0.05的显著性水平下,就收缩压与冠心病的关系分析,正确的结论为:A. 收缩压不是冠心病的危险因素B. 收缩压是冠心病的危险因素C. 对应的CHM 检验的=2χ21.9444D. 对应的CHM 检验的p 值<.0001E. 对应的CHM 检验的=2χ28.94414.根据SAS运行结果,以下结论错误的有:A.Pearson拟合优度为13.4287B.Pearson拟合优度为14.8472C.在0.05的显著性水平下,可认为胆固醇与收缩压中至少有一个是冠心病的危险因素D.在0.05的显著性水平下,可认为胆固醇与收缩压中没有一个是冠心病的危险因素E.带截距的模型拟合统计量AIC为670.8315. 根据SAS运行结果,以下正确的有:A.在0.05的显著性水平下,可认为胆固醇与收缩压都对冠心病有影响B.胆固醇与收缩压两因素中,最危险的因素是胆固醇C.胆固醇与收缩压两因素中,最危险的因素是收缩压D.胆固醇的比数比1.699指的是胆固醇每增加一个秩次,将平均使冠心病患病率上升1.699倍E.胆固醇的比数比1.699指的是胆固醇每增加一个秩次,将平均使冠心病患病率下降1.699倍四、分析计算题(共3题, 共45分)1.(15分)某个保健矿泉疗养地做了一个减肥计划的广告,10个人受广告吸引前去治疗,治疗前后每人的体重(为变量X与Y,kg)记录在SAS数据集EXER_05中.试以5%水平检验该治疗对减轻体重是否有效. 要求:(1)问可应用哪些SAS过程来实现相应的计算?(2)根据以下SAS运行结果,完成相应的SAS程序;(3)进行简要的分析说明.The UNIVARIATE ProcedureVariable: dMomentsN 10 Sum Weights 10Mean 1.33 Sum Observations 13.3Std Deviation 0.73794008 Variance 0.54455556 Skewness -0.435611 Kurtosis -0.5080605Uncorrected SS 22.59 Corrected SS 4.901 Coeff Variation 55.4842162 Std Error Mean 0.23335714Basic Statistical MeasuresLocation VariabilityMean 1.330000 Std Deviation 0.73794Median 1.400000 Variance 0.54456Mode . Range 2.30000Interquartile Range 0.90000Tests for Location: Mu0=0Test -Statistic- -----p Value------Student's t t 5.699418 Pr > |t| 0.0003Sign M 4.5 Pr >= |M| 0.0039Signed Rank S 22.5 Pr >= |S| 0.0039Tests for NormalityTest --Statistic--- -----p Value------ Shapiro-Wilk W 0.96075 Pr < W 0.7944Kolmogorov-Smirnov D 0.137908 Pr > D >0.1500Cramer-von Mises W-Sq 0.028982 Pr > W-Sq >0.2500Anderson-Darling A-Sq 0.19758 Pr > A-Sq >0.2500[解] (1)可以应用MEANS 过程、TTEST 过程、UNIVARIATE 过程来实现相应的计算。
SAS-base-考试必备-70真题(附答案)

1.The following SAS program is submitted:data WORK.TOTAL;set WORK.SALARY;by Department Gender;if First.<_insert_code_> then Payroll=0;Payroll+Wagerate;if Last.<_insert_code_>;run;The SAS data set WORK.SALARY is currently ordered by Gender within Department.Which inserted code will accumulate subtotals for each Gender within Department?A. GenderB. DepartmentC. Gender DepartmentD. Department GenderAnswer: A-------------------------------------2.Given the following raw data records in TEXT:----|----10---|----20---|----30John,FEB,13,25,14,27,FinalJohn,MAR,26,17,29,11,23,CurrentTina,FEB,15,18,12,13,FinalTina,MAR,29,14,19,27,20,CurrentThe following output is desired:Obs Name Month Status Week1 Week2 Week3 Week4 Week51 John FEB Final $13 $25 $14 $27 .2 John MAR Current $26 $17 $29 $11 $233 Tina FEB Final $15 $18 $12 $13 .4 Tina MAR Current $29 $14 $19 $27 $20 Which SAS program correctly produces the desired output?A.data WORK.NUMBERS;length Name $ 4 Month $ 3 Status $ 7;infile 'TEXT' dsd;input Name $ Month $;if Month='FEB' then input Week1 Week2 Week3 Week4 Status $;else if Month='MAR' then input Week1 Week2 Week3 Week4 Week5 Status $;format Week1-Week5 dollar6.;run;proc print data=WORK.NUMBERS;run;B.data WORK.NUMBERS;length Name $ 4 Month $ 3 Status $ 7;infile 'TEXT' dlm=',' missover;input Name $ Month $;if Month='FEB' then input Week1 Week2 Week3 Week4 Status $;else if Month='MAR' then input Week1 Week2 Week3 Week4 Week5 Status $;format Week1-Week5 dollar6.;run;proc print data=WORK.NUMBERS;run;C.data WORK.NUMBERS;length Name $ 4 Month $ 3 Status $ 7;infile 'TEXT' dlm=',';input Name $ Month $ @;if Month='FEB' then input Week1 Week2 Week3 Week4 Status $;else if Month='MAR' then input Week1 Week2 Week3 Week4 Week5 Status $;format Week1-Week5 dollar6.;run;proc print data=WORK.NUMBERS;run;D.data WORK.NUMBERS;length Name $ 4 Month $ 3 Status $ 7;infile 'TEXT' dsd @;input Name $ Month $;if Month='FEB' then input Week1 Week2 Week3 Week4 Status $;else if Month='MAR' then input Week1 Week2 Week3 Week4 Week5 Status $;format Week1-Week5 dollar6.;run;proc print data=WORK.NUMBERS;run;Answer: C-------------------------------------3.The Excel workbook REGIONS.XLS contains the following four worksheets:EASTWESTNORTHSOUTHThe following program is submitted:libname MYXLS 'regions.xls';Which PROC PRINT step correctly displays the NORTH worksheet?A. proc print data=MYXLS.NORTH;run;B. proc print data=MYXLS.NORTH$;run;C. proc print data=MYXLS.'NORTH'e;run;D. proc print data=MYXLS.'NORTH$'n;run;Answer: D-------------------------------------4.The following SAS program is submitted:data WORK.DATE_INFO;Day="01" ;Yr=1960 ;X=mdy(Day,01,Yr) ;run;What is the value of the variable X?A. the numeric value 0B. the character value "01011960"C. a missing value due to syntax errorsD. the step will not compile because of the character argument in the mdy function.Answer: A-------------------------------------5.Which statement specifies that records 1 through 10 are to be read from the raw data ?A. infile 'customer.txt' 1-10;B. input 'customer.txt' stop@10;C. infile 'customer.txt' obs=10;D. input 'customer.txt' stop=10;Answer: C-------------------------------------6.After a SAS program is submitted, the following is written to the SAS log:101 data WORK.JANUARY;102 set WORK.ALLYEAR(keep=product month num_Sold Cost);103 if Month='Jan' then output WORK.JANUARY;104 Sales=Cost * Num_Sold;105 keep=Product Sales;-----22ERROR 22-322: Syntax error, expecting one of the following: !,!!, &, *, **, +, -, , <=, <>, =, >, >=,AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG,NL,NOTIN, OR, ^=, |, ||, ~=.106 run;What changes should be made to the KEEP statement to correct the errors in the LOG?A. keep=(Product Sales);B. keep Product, Sales;C. keep=Product, Sales;D. keep Product Sales;Answer: D-------------------------------------7.Which of the following choices is an unacceptable ODS destination for producing output that can be viewed in Microsoft Excel?A. MSOFFICE2KB. EXCELXPC. CSVALLD. WINXPAnswer: D-------------------------------------8.The SAS data set named WORK.SALARY contains 10 observations for each department,and is currently ordered by Department. The following SAS program is submitted:data WORK.TOTAL;set WORK.SALARY(keep=Department MonthlyWageRate);by Department;if First.Department=1 then Payroll=0;Payroll+(MonthlyWageRate*12);if Last.Department=1;run;Which statement is true?A. The by statement in the DATA step causes a syntax error.B. The statement Payroll+(MonthlyWageRate*12); in the data step causes a syntax error.C. The values of the variable Payroll represent the monthly total for each department in the WORK.SALARY data set.D. The values of the variable Payroll represent a monthly total for all values of WAGERATE in the WORK.SALARY data set.Answer: C-------------------------------------10.The following SAS program is submitted:data WORK.RETAIL;Cost='$20,000';Discount=.10*Cost;run;What is the result?A. The value of the variable Discount in the output data set is 2000.No messages are written to the SAS log.B. The value of the variable Discount in the output data set is 2000.A note that conversion has taken place is written to the SAS log.C. The value of the variable Discount in the output data set is missing. A note in the SAS log refers to invalid numeric data.D. The variable Discount in the output data set is set to zero.No messages are written to the SAS log.Answer: C 因为有一个$符号-------------------------------------11.Given the existing SAS program:proc format;value agegrplow-12 ='Pre-Teen'13-high = 'Teen';run;proc means data=SASHELP.CLASS;var Height;class Sex Age;format Age agegrp.;run;Which statement in the proc means step needs to be modified or added to generate the following results:Analysis Variable : HeightNSex Age Obs Minimum MaximumMean------------------------------------------------------------------F Pre-Teen 3 51.3 59.8 55.8Teen 6 56.5 66.5 63.0 M Pre-Teen 4 57.3 64.8 59.7 Teen 6 62.5 72.0 66.8 --------------------------------------------------------------------A. var Height / nobs min max mean maxdec=1;B. proc means data=SASHELP.CLASS maxdec=1 ;C. proc means data=SASHELP.CLASS min max mean maxdec=1;D. output nobs min max mean maxdec=1;Answer: C-------------------------------------12.The Excel workbook QTR1.XLS contains the following three worksheets:JANFEBMARWhich statement correctly assigns a library reference to the Excel workbook?A. libname qtrdata 'qtr1.xls';B. libname 'qtr1.xls' sheets=3;C. libname jan feb mar 'qtr1.xls';D. libname mydata 'qtr1.xls' WORK.heets=(jan,feb,mar);Answer: A-------------------------------------13.The following SAS program is submitted:data WORK.TEST;set WORK.MEASLES(keep=Janpt Febpt Marpt);array Diff{3} Difcount1-Difcount3;array Patients{3} Janpt Febpt Marpt;run;What new variables are created?A. Difcount1, Difcount2 and Difcount3B. Diff1, Diff2 and Diff3C. Janpt, Febpt, and MarptD. Patients1, Patients2 and Patients3Answer: A-------------------------------------14.Which of the following programs correctly invokes the DATA Step Debugger:A.data WORK.TEST debug;set WORK.PILOTS;State=scan(cityState,2,' ');if State='NE' then description='Central';run;B.data WORK.TEST debugger;set WORK.PILOTS;State=scan(cityState,2,' ');if State='NE' then description='Central';run;C.data WORK.TEST / debug;set WORK.PILOTS;State=scan(cityState,2,' ');if State='NE' then description='Central';run;D.data WORK.TEST / debugger;set WORK.PILOTS;State=scan(cityState,2,' ');if State='NE' then description='Central';run;Answer: c-------------------------------------15.Which statement is true concerning the SAS automatic variable _ERROR_?A. It cannot be used in an if/then condition.B. It cannot be used in an assignment statement.C. It can be put into a keep statement or keep= option.D. It is automatically dropped.Answer: D-------------------------------------16.The following SAS program is submitted:data WORK.DATE_INFO;X='04jul2005'd;DayOfMonth=day(x);MonthOfYear=month(x);Year=year(x);run;What types of variables are DayOfMonth, MonthOfYear, and Year?A. DayOfMonth, Year, and MonthOfYear are character.B. DayOfMonth, Year, and MonthOfYear are numeric.C. DayOfMonth and Year are numeric. MonthOfYear is character.D. DayOfMonth, Year, and MonthOfYear are date values.Answer: B-------------------------------------17.Given the following data step:data WORK.GEO;input City $20.;if City='Tulsa' thenState='OK';Region='Central';if City='Los Angeles' thenState='CA';Region='Western';datalines;TulsaLos AngelesBangor;run;After data step execution, what will data set WORK.GEO contain?A.City State Region----------- ----- -------Tulsa OK WesternLos Angeles CA WesternBangor WesternB.City State Region----------- ----- -------Tulsa OK WesternLos Angeles CA WesternBangorC.City State Region----------- ----- -------Tulsa OK CentralLos Angeles CA WesternBangor WesternD.City State Region----------- ----- -------Tulsa OK CentralLos CA WesternAnswer: A-------------------------------------18.Which statement describes a characteristic of the SAS automatic variable_ERROR_?A. The _ERROR_ variable maintains a count of the number of data errors in a DATA step.B. The _ERROR_ variable is added to the program data vector and becomes part of the data set being created.C. The _ERROR_ variable can be used in expressions in the DATA step.D. The _ERROR_ variable contains the number of the observation that caused the data error.Answer: C-------------------------------------19.The SAS data set WORK.ONE contains a numeric variable named Num and a character variable named Char:WORK.ONENum Char--- ----1 233 231 77The following SAS program is submitted:proc print data=WORK.ONE;where Num='1';run;What is output?A.Num Char--- ----1 23B.Num Char--- ----1 231 77C.Num Char--- ----1 233 231 77D. No output is generated.Answer: D-------------------------------------20. The data set WORK.REALESTATE has the variable LocalFee with a format of 9. and a variable CountryFee with a format of 7.;The following SAS program is submitted:data WORK.FEE_STRUCTURE;format LocalFee CountryFee percent7.2;set WORK.REALESTAT;LocalFee=LocalFee/100;CountryFee=CountryFee/100;run;What are the formats of the variables LOCALFEE and COUNTRYFEE in the output dataset?A. LocalFee has format of 9. and CountryFee has a format of 7.B. LocalFee has format of 9. and CountryFee has a format of percent7.2C. Both LocalFee and CountryFee have a format of percent7.2D. The data step fails execution; there is no format for LocalFee.Answer: C-------------------------------------21.Given the SAS data set WORK.PRODUCTS:ProdId Price ProductType Sales Returns------ ----- ----------- ----- -------K12S 95.50 OUTDOOR 15 2B132S 2.99 CLOTHING 300 10R18KY2 51.99 EQUIPMENT 25 53KL8BY 6.39 OUTDOOR 125 15DY65DW 5.60 OUTDOOR 45 5DGTY23 34.55 EQUIPMENT 67 2The following SAS program is submitted:data WORK.OUTDOOR WORK.CLOTH WORK.EQUIP;set WORK.PRODUCTS;if Sales GT 30;if ProductType EQ 'OUTDOOR' then output WORK.OUTDOOR;else if ProductType EQ 'CLOTHING' then output WORK.CLOTH;else if ProductType EQ 'EQUIPMENT' then output WORK.EQUIP; run;How many observations does the WORK.OUTDOOR data set contain?A. 1B. 2C. 3D. 6Answer: B-------------------------------------22.Which step displays a listing of all the data sets in the WORK library?A. proc contents lib=WORK run;B. proc contents lib=WORK.all;run;C. proc contents data=WORK._all_; run;D. proc contents data=WORK _ALL_; run;Answer: c-------------------------------------23.Which is a valid LIBNAME statement?A. libname "_SAS_data_library_location_";B. sasdata libname "_SAS_data_library_location_";C. libname sasdata "_SAS_data_library_location_";D. libname sasdata sas "_SAS_data_library_location_";Answer: C-------------------------------------24.Given the following raw data records:----|----10---|----20---|----30Susan*12/29/1970*10Michael**6The following output is desired:Obs employee bdate years1 Susan 4015 102 Michael . 6Which SAS program correctly reads in the raw data?A.data employees;infile '' dlm='*';input employee $ bdate : mmddyy10. years;run;B.data employees;infile '' dsd='*';input employee $ bdate mmddyy10. years;run;C.data employees;infile '' dlm dsd;input employee $ bdate mmddyy10. years;run;D.data employees;infile '' dlm='*' dsd;input employee $ bdate : mmddyy10. years;run;Answer: D-------------------------------------25.Given the following code:proc print data=SASHELP.CLASS(firstobs=5 obs=15);where Sex='M';run;How many observations will be displayed?A. 11B. 15C. 10 or fewerD. 11 or fewerAnswer: D-------------------------------------26.Which step sorts the observations of a permanent SAS data set by two variables and stores the sorted observations in a temporary SAS data set?A.proc sort out=EMPLOYEES data=EMPSORT;by Lname and Fname;run;B.proc sort data=SASUSER.EMPLOYEES out=EMPSORT;by Lname Fname;run;C.proc sort out=SASUSER.EMPLOYEES data=WORK.EMPSORT;by Lname Fname;run;D.proc sort data=SASUSER.EMPLOYEES out=SASUSER.EMPSORT;by Lname and Fname;run;Answer: B-------------------------------------27.Given the SAS data set WORK.TEMPS:Day Month Temp--- ----- ----1 May 7515 May 7015 June 803 June 762 July 8514 July 89The following program is submitted: proc sort data=WORK.TEMPS;by descending Month Day; run;proc print data=WORK.TEMPS; run;Which output is correct?A.Obs Day Month Temp --- --- ----- ----1 2 July 852 14 July 893 3 June 764 15 June 805 1 May 756 15 May 7B.Obs Day Month Temp --- --- ----- ----1 1 May 752 2 July 853 3 June 764 14 July 895 15 May 706 15 June 80C.Obs Day Month Temp --- --- ----- ----1 1 May 752 15 May 703 3 June 764 15 June 805 2 July 856 14 July 89D.Obs Day Month Temp--- --- ----- ----1 15 May 702 1 May 753 15 June 804 3 June 765 14 July 896 2 July 85Answer: C-------------------------------------28.Given the SAS data set WORK.P2000:Location Pop2000-------- -------Alaska 626931Delaware 783595Vermont 608826Wyoming 493782and the SAS data set WORK.P2008:State Pop2008-------- -------Alaska 686293Delaware 873092Wyoming 532668The following output is desired:Obs State Pop2000 Pop2008 Difference1 Alaska 626931 686293 593622 Delaware 783595 873092 894973 Wyoming 493782 532668 38886 Which SAS program correctly combines the data?A.data compare;merge WORK.P2000(in=_a Location=State)WORK.P2008(in=_b);by State;if _a and _b;Difference=Pop2008-Pop2000;run;B.data compare;merge WORK.P2000(rename=(Location=State))WORK.P2008;by State;if _a and _b;Difference=Pop2008-Pop2000;run;C.data compare;merge WORK.P2000(in=_a rename=(Location=State)) WORK.P2008(in=_b);by State;if _a and _b;Difference=Pop2008-Pop2000;run;D.data compare;merge WORK.P2000(in=_a) (rename=(Location=State)) WORK.P2008(in=_b);by State;if _a and _b;Difference=Pop2008-Pop2000;run;Answer: C-------------------------------------29.The following SAS program is sumbitted:data ;infile 'DATA';input @1 Company $20. @25 State $2. @;if State=' ' then input @30 Year;else input @30 City Year;input NumEmployees;run;How many raw data records are read during each iteration of the DATA step?A. 1B. 2C. 3D. 4Answer: A-------------------------------------30.You're attempting to read a raw data you see the following messages displayed in the SAS Log:NOTE: Invalid data for Salary in line 4 15-23.RULE: ----+----1----+----2----+----3----+----4----+----5--4 120104 F 46#30 11MAY1954 33Employee_Id=120104 employee_gender=F Salary=. birth_date=-2061 _ERROR_=1 _N_=4NOTE: 20 records were read from the infile 'c:\employees.dat'.The minimum record length was 33.The maximum record length was 33.NOTE: The data set WORK.EMPLOYEES has 20 observations and 4 variables. What does it mean?A. A compiler error, triggered by an invalid character for the variable Salary.B. An execution error, triggered by an invalid character for the variable Salary.C. The 1st of potentially many errors, this one occurring on the 4th observation.D. An error on the INPUT statement specification for reading the variable Salary.Answer: B------------------------------------------------------------------31. Given the following raw data records in DATA:----|----10---|----20---|----30Kim,Basketball,Golf,TennisBill,FootballTracy,Soccer,TrackThe following program is submitted:data WORK.SPORTS_INFO;length Fname Sport1-Sport3 $ 10;infile 'DATA' dlm=',';input Fname $ Sport1 $ Sport2 $ Sport3 $;run;proc print data=WORK.SPORTS_INFO;run;Which output is correct based on the submitted program?A.Obs Fname Sport1 Sport2 Sport31 Kim Basketball Golf Tennis2 Bill Football3 Tracy Soccer TrackB.Obs Fname Sport1 Sport2 Sport31 Kim Basketball Golf Tennis2 Bill Football Football Football3 Tracy Soccer Track TrackC.Obs Fname Sport1 Sport2 Sport31 Kim Basketball Golf Tennis2 Bill Football Tracy SoccerD.Obs Fname Sport1 Sport2 Sport31 Kim Basketball Golf Tennis2 Bill FootballAnswer: C------------------------------------------------------------------32.Consider the following data step:data WORK.NEW;set WORK.OLD;Count+1;run;The variable Count is created using a sum statement. Which statement regarding this variable is true?A. It is assigned a value 0 when the data step begins execution.B. It is assigned a value of missing when the data step begins execution.C. It is assigned a value 0 at compile time.D. It is assigned a value of missing at compile time.Answer: C------------------------------------------------------------------33.The following SAS program is submitted:data WORK.TEST;set WORK.PILOTS;if Jobcode='Pilot2' then Description='Senior Pilot';else Description='Unknown';run;The value for the variable Jobcode is: PILOT2.What is the value of the variable Description?A. PILOT2B. UnknownC. Senior PilotD. ' ' (missing character value)Answer: B------------------------------------------------------------------34.A user-defined format has been created using the FORMAT procedure.How is it stored?A. in a SAS catalogB. in a memory resident lookup tableC. in a SAS dataset in the WORK libraryD. in a SAS dataset in a permanent SAS data libraryAnswer: AThese formats must be stored in the WORK.FORMATS or SASUSER.FORMATS catalog------------------------------------------------------------------35.given the SAS data set SASDATA.TWO:X Y-- --5 23 15 6The following SAS program is submitted:data SASUSER.ONE SASUSER.TWO OTHER;set SASDATA.TWO;if X eq 5 then output SASUSER.ONE;if Y lt 5 then output SASUSER.TWO;output;run;What is the result?A.data set SASUSER.ONE has 5 observationsdata set SASUSER.TWO has 5 observationsdata set WORK.OTHER has 3 observationsB.data set SASUSER.ONE has 2 observationsdata set SASUSER.TWO has 2 observationsdata set WORK.OTHER has 1 observationsC.data set SASUSER.ONE has 2 observationsdata set SASUSER.TWO has 2 observationsdata set WORK.OTHER has 5 observationsD. No data sets are output. The DATA step fails execution due to syntax errors. Answer: A------------------------------------------------------------------36.Given the contents of the raw data file 'EMPLOYEE.TXT':----+----10---+----20---+----30--Xing 2 19 2004 ACCTBob 5 22 2004 MKTGJorge 3 14 2004 EDUCThe following SAS program is submitted:data WORK.EMPLOYEE;infile 'EMPLOYEE.TXT';input@1 FirstName $@15 StartDate@25 Department $;run;Which SAS informat correctly completes the program?A. date9.B. mmddyy10.C. ddmmyy10.D. mondayyr10.Answer: B-------------------------------------------------------------37.The SAS data set Fed.Banks contains a variable Open_Date which hasbeen assigned a permanent label of "Open Date". Which SAS program temporarily replaces the label "Open Date" with the label "Starting Date" in the output?A.proc print data=SASUSER.HOUSES label;label Open_Date "Starting Date";run;B.proc print data=SASUSER.HOUSES label;label Open_Date="Starting Date";run;C.proc print data=SASUSER.HOUSES;label Open_Date="Starting Date";run;D.proc print data=SASUSER.HOUSES;Open_Date="Starting Date";run;Answer: B------------------------------------------------------------------ 38.Given the SAS data set WORK.ONE:X Y Z- - --1 A 271 A 331 B 452 A 522 B 693 B 704 A 824 C 91The following SAS program is submitted:data WORK.TWO;set WORK.ONE;by X Y;if First.Y;run;proc print data=WORK.TWO noobs;run;Which report is produced?A.X Y Z-- -- --1 B 452 A 522 B 693 B 704 A 824 C 91B.X Y Z-- -- --1 A 271 B 452 A 522 B 693 B 704 A 824 C 91C.X Y Z-- -- --1 A 331 B 452 A 522 B 693 B 704 A 824 C 91D. The PRINT procedure fails because the data set WORK.TWO is not created in the DATA step.Answer: B------------------------------------------------------------------39.The following SAS program is submitted:data WORK.AUTHORS;array Favorites{3} $ 8 ('Shakespeare','Hemingway','McCaffrey');run;What is the value of the second variable in the dataset WORK.AUTHORS?A. HemingwayB. HemingwaC. ' ' (a missing value)D. The program contains errors. No variables are created.Answer: B------------------------------------------------------------------40.The following SAS program is submitted:data WORK.PRODUCTS;Prod=1;do while(Prod LE 6);Prod + 1;end;run;What is the value of the variable Prod in the output data set?A. 6B. 7C. 8D. . (missing numeric)Answer: B------------------------------------------------------------------41.Given the raw data record in the :----|----10---|----20---|----30---|Stevens James SALES 304-923-3721 14The following SAS program is submitted:data WORK.PHONES;infile 'phone.txt';input EmpLName $ EmpFName $ Dept $ Phone $ Extension;<_insert_code_>run;Which SAS statement completes the program and results in a value of "James Stevens" for the variable FullName?A. FullName=CATX(' ',EmpFName,EmpLName);B. FullName=CAT(' ',EmpFName,EmpLName);C. FullName=EmpFName!!EmpLName;D. FullName=EmpFName + EmpLName;Answer: A------------------------------------------------------------------42.The following SAS program is submitted:data WORK.ONE;Text='Australia, US, Denmark';Pos=find(Text,'US','i',5);run;What value will SAS assign to Pos?A. 0B. 1C. 2D. 12Answer: D------------------------------------------------------------------43.Given the SAS data set WORK.ORDERS:WORK.ORDERSorder_id customer shipped-------- ------------ ---------9341 Josh Martin 02FEB20099874 Rachel Lords 14MAR200910233 Takashi Sato 07JUL2009The variable order_id is numeric; customer is character; and shipped is numeric, contains a SAS date value, and is shown with the DATE9. format.A programmer would like to create a new variable, ship_note, that shows a character value with the order_id,shipped date, and customer name.For example, given the first observation ship_note would have the value "Order 9341 shipped on 02FEB2009 to Josh Martin".Which of the following statement will correctly create the value and assign it to ship_note?A. ship_note=catx(' ','Order',order_id,'shippedon',input(shipped,date9.),'to',customer);B. ship_note=catx(' ','Order',order_id,'shippedon',char(shipped,date9.),'to',customer);C. ship_note=catx(' ','Order',order_id,'shippedon',transwrd(shipped,date9.),'to',customer);D. ship_note=catx(' ','Order',order_id,'shippedon',put(shipped,date9.),'to',customer);Answer: D------------------------------------------------------------------44.The following SAS program is submitted:data ONE TWO SASUSER.TWOset SASUSER.ONE;run;Assuming that SASUSER.ONE exists, how many temporary and permanent SAS data sets are created?A. 2 temporary and 1 permanent SAS data sets are createdB. 3 temporary and 2 permanent SAS data sets are createdC. 2 temporary and 2 permanent SAS data sets are createdD. there is an error and no new data sets are createdAnswer: D------------------------------------------------------------------45.The following SAS program is submitted:ods csvall file='c:\test.cvs';proc print data=WORK.ONE;var Name Score Grade;by IdNumber;run;ods csvall close;What is produced as output?A. A test.cvs that can only be opened in Excel.B. A text test.cvs that can be opened in Excel or in any text editor.C. A text test.cvs that can only be opened in a text editor.D. A test.cvs that can only be opened by SAS.Answer: C------------------------------------------------------------------46.Given the SAS data set WORK.ONE:Obs Revenue2008 Revenue2009 Revenue2010--- ----------- ----------- -----------1 1.2 1.6 2.0The following SAS program is submitted:。
SAS应用基础3-1

FORMAT过程选项 FORMAT过程选项
◎PROC FORMAT语句表示开始自定义变量的格式 FORMAT语句表示开始自定义变量的格式 常用选项有: 常用选项有:
CNTLIN=数据集 指定数据集保存输入格式的控制信息; CNTLIN=数据集 指定数据集保存输入格式的控制信息; CNTLOUT=数据集 指定数据集保存输出格式的控制信息; CNTLOUT=数据集 指定数据集保存输出格式的控制信息; LIBRARY=库标识 LIBRARY=库标识 设定存储输入输出格式控制的数据集 所在的SAS 数据库标识 数据库标识. 所在的 SAS数据库标识. 该选项用于建立永久性输入输 出格式, 使用前应先LIBNAME 语句将具体的文件夹和 出格式 , 使用前应先 LIBNAME语句将具体的文件夹和 数据库标识关联起来. 数据库标识关联起来. 注意: 注意:要确保顺利使用存储在某个库中的格式 ,应设置系 统选项FMTSEARCH FMTSEARCH: 统选项FMTSEARCH: OPTIONS FMTSEACH=(库名1 库名2 …); FMTSEACH=(库名 库名2 库名1
7
转置数据集示例
data score; score; name$ math@@; input name$ chinese english math@@; cards; cards; zhao 67 76 74 qian 89 78 92 sun 88 76 90 li 93 85 82 wang 78 64 72 xu 90 94 77 print; proc print; transpose; proc transpose; name; /*用姓名来作为新数据集的变量名 用姓名来作为新数据集的变量名* id name; /*用姓名来作为新数据集的变量名*/ print; proc print; run; run;
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试题A

考生注意:舞弊万莫做,那样要退学,自爱当守诺,最怕错上错,若真不及格,努力下次过。
开 试题成绩课程名称 应用统计软件(A ) 考试时间 年 11月19日8时 00分至10时 00分 教 研 室 统计 开卷 闭卷 适用专业班级 统计061 提前 期末 班 级 姓名 学号一、填空题(每空1分,共20分):1.SAS 的三个基本窗口是 , 及 。
2.SAS 程序每一数据步以 开始,而过程步以 开始,整个程序以 语句结束。
3.每个语句常以开始的关键词称呼,用 表示语句的结束。
4.运行存在错误的程序后,在 窗口中会出现红色错误提示;可通过按 键或在命令栏中发布 命令或从 菜单中选Recall Last Submit ,将程序重新调入PGM 窗口进行修改。
5.调用SAS/INSIGHT 可在命令行中键入命令 。
6.SAS/INSIGHT 的功能主要有:通过多窗口连动的图象和分析结果,对数据进行探索;分析 分布;用 和 研究多变量间的关系;用 和 说明、拟合变量间关系的模型。
7.调用分析员应用可在命令行中键入命令 。
8.分析员通过选择 的不同选项可完成各种基本分析功能和绘图功能;完成每项任务后,能立即显示相应的结果,而且保留相应的 ;在分析过程中可随时调出有关的图形和结果进行显示。
----------------------------------------------------------------------装--------------------订--------------------线-------------------------------------------------------------试 题 共 3 页 第 1 页run;A. d:\B. d:\sasdataC.c:\D.不确定 4.下列程序读入外部文件的模式是( )Data dst; Infile 'd:\lecsas\basev8\dst\imptdt01.dat' firstobs=2 obs=3; Input ID Age Actlevel $ Sex $; Run;A. 按列输入模式B.格式化输入模式C.列举输入模式D.其它模式 5.列举模式读入分隔符缺省为( )A.Tab 键B.逗号C.空格符D.任意符号都可以 6.提交下列SAS 程序,那种说法是正确的( )proc sort data = work.test; by fname descending salary; run;A. 数据集work.test 先按照fname 降序排列,再按照salary 降序排列B. 数据集work.test 先按照fname 升序排列,再按照salary 降序排列C. 数据集work.test 先按照salary 降序排列,再按照fname 降序排列D. 数据集work.test 先按照salary 降序排列,再按照fname 升序排列 7.提交下列程序,得到的回归方程为( ) data tem; set sasuser. admit; a2=age*age; a3=a2*age;a4=a3*age;run;proc glm data=tem;model fee=age a2 a3 a4/ss1; run;A .fee=age+b1*age 2+b2*age 3+b3*age 4命题负责人: 教研室主任:。
江西财经大学SAS软件技能测试试题二 (2)

江西财经大学SAS软件技能测试试题二一、填空题(每小题2分,共20分。
)1.在SAS程序中,每一个完整的SAS语句都是以()号结束的。
2.创建SAS数据集用()步。
3.SAS软件使用()窗口可以显示、修改、设置并存储SAS参数设置。
4.TITLES窗用以显示和让用户指定打印输出各页顶端的标题,共可以指定()个标题。
5.DATA步建立SAS数据集时,常使用INPUT语句指定将要输入的变量及其类型。
在指定将输入()型变量时,其后应用“$”符号。
6.SAS程序是由两种步骤(STEP)组成:它们是()步和()步。
7.在SAS程序中,经常要选择观测。
我们可以用选项()保留原数据集中的观测,用选项()删除原数据集中的观测。
8.INPUT语句中常用的数据读入的方式有四种。
其中有一方式是()方式,它可以使字符型变量值中含有空格。
二、简答题(每小题10分,共20分)1.SAS系统软件有哪三个基本窗口?各有什么功能?2.请回答PUT语句、OUT和OUTPUT语句的作用。
1.试列举几种用SAS系统可以制作的统计图形,并回答在编程时各自用什么语句(或过程)或选项?2.DATA步中的INPUT语句有哪四种输入格式?3.请回答FILE和INFILE语句的作用。
3.三、编程或写出程序的运行结果(共60分)1.(10分)试用DATA步编辑一SAS数据集mydir.hw。
数据库mydir对应的路径是“c:\”。
要求按照下面的结果输出。
说明该数据集中有4个变量名分别为SEX、JOBCODE、FLIGHTS和DATE,其中SEX和JOBCODE是字符型变量,DATE 为日期型变量。
THIS IS A SAS_DATASET ABOUT FLIGHTSSEX JOBCODE FLIGHTS 日期F FA3 32886 01MAR99M FA2 28572 01MAR99F FA3 33104 02MAR99M FA3 32217 01MAR99F FA3 33419 04MAR99F FA2 28888 05MAR99F FA2 27787 08MAR99F FA1 23177 09MAR99F FA1 22454 03MAR99M FA1 22268 06MAR99M FA2 27808 07MAR99M FA2 27265 04MAR992.(续第1题,按要求写出过程)(15分)试用SET语句调用第1题的数据集mydir.hw 。
sas复习题答案

sas复习题答案SAS复习题答案随着数据分析技术的快速发展,SAS(统计分析系统)成为了许多企业和研究机构中最受欢迎的数据分析工具之一。
SAS能够处理大规模数据集,进行数据清洗、统计分析、建模和预测等工作。
然而,要掌握SAS并不容易,需要不断的学习和实践。
在这篇文章中,我将为大家提供一些SAS复习题的答案,希望能够帮助大家更好地掌握这一强大的数据分析工具。
1. 什么是SAS?SAS是一种用于数据管理和分析的软件套件。
它提供了一系列功能强大的工具,包括数据清洗、统计分析、数据可视化和建模等。
SAS具有高度的灵活性和可扩展性,可以处理大规模的数据集,并提供高质量的分析结果。
2. 如何导入数据集?在SAS中,可以使用PROC IMPORT语句来导入数据集。
例如,要导入一个名为"data.csv"的CSV文件,可以使用以下代码:```PROC IMPORT DATAFILE='data.csv'OUT=work.dataDBMS=csvREPLACE;GETNAMES=YES;RUN;```这段代码将把"data.csv"文件导入到名为"work.data"的SAS数据集中。
3. 如何删除重复观测值?要删除SAS数据集中的重复观测值,可以使用PROC SORT和DATA步骤来完成。
以下是一个示例代码:```PROC SORT DATA=work.data NODUPKEY;BY var1 var2;RUN;```这段代码将根据"var1"和"var2"两个变量的值对数据集进行排序,并删除重复的观测值。
4. 如何计算变量的平均值?要计算SAS数据集中变量的平均值,可以使用MEANS过程。
以下是一个示例代码:```PROC MEANS DATA=work.data;VAR var1 var2 var3;OUTPUT OUT=work.mean_data MEAN=;RUN;```这段代码将计算"var1"、"var2"和"var3"三个变量的平均值,并将结果存储在名为"work.mean_data"的SAS数据集中。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《SAS软件应用基础》期中考试参考答案
【考前说明事项】
请按要求将答案、操作步骤、程序直接输入在本文件中指定位置处;考试结束时将名为“姓名@SAS”的文件上传到服务器上“temp”目录下,教师将从该目录中收集试卷。
另外,为防止意外,请随时保存文档!
【试题】
一.填充(20%)
1.一般SAS程序的运行信息将在LOG窗口显示;而程序的的运行结果,若有文本信息输出的话,将在OUTPUT窗口显示。
2.要运行已编辑好的SAS程序,可以点击RUN->SUBMIT菜单;一般有关统计分析的常用模块,SAS都组织在解决方案->分析菜单里。
3.SAS数据步程序一般都以关键字DATA开始,以关键字RUN;结尾。
4.SAS变量只有两种基本类型字符型和数值型;而日期型数据在存贮时将折算成与1960年1月1日的间隔天数。
5.SAS变量的属性有Name、Label、Format、Informat、Length 和Type六项。
6.SAS数据集sasuser.class位于SAS数据库sasuser中,它在WINDOWS下的物理文件名应该是class.7bdat。
7.SAS的临时数据库是指work库,在该库中的数据文件,在退出SAS后将丢失。
8.在SAS软件中单词USS表示加权平方和,Q1表示四分之一分位数。
9.在data等语句里,指定数据集时,数据集名后可跟多个数据集的选项,但所有数据集选项必须在圆括号内,用空格分隔。
10.在SAS中使用INPUT语句读入数据时,有四种基本的输入模式,它们分别是“列模式”、“格式化模式”、“自由列表模式”和“命名模式。
二.纠错题(20%)
二.1.正确程序如下:
datatest;
inputcode price;
cards;
60038118
60026216
procprint;
run;
1.将有问题的语句涂上红色,并写出正确的程序。
data test
input code, price;
proc print;
cards;
600381 18
600262 16
run;
二.2.正确程序如下:
datatmp;
inputname$ @@;
cards;
张三李四王五徐六
run;
2.将有问题的语句涂上红色,并写出正确的程序。
datatmp;
input name;
cards;
张三李四王五徐六;
run;
三.程序阅读理解题(20%)
1.
proctranspose data=score out=ts;
id name;
run;
上述程序的主要功能是:
将score数据集的数值型变量s1-s3进行转置;
并用变量name的值作为转置后相应各列的变量名;
转置后的数据另寸为ts数据集。
2.
data tmp;
set tmp1 tmp2;
by a;
run;
上述程序的主要功能是:
将数据集tmp1,tmp2按照变量a值顺序进行拼接,形成四条记录存放进数据集tmp中。
四.操作题(20%)
1.试将EXECL电子表格文件qzks.xls导入为SAS数据集work.qz。
导入操作的等效程序粘贴如下:
PROC IMPORT OUT= WORK.qz
DATAFILE= "G:\SAS统计应用基础\sasqz\qzks.xls"
DBMS=EXCEL2000 REPLACE;
SHEET="stock";
GETNAMES=YES;
RUN;
2.试用SQL查询窗在数据集score中查询所有女生(sex='f'')的姓名name以及她三门课的平均成绩avg。
查询操作的等效程序粘贴如下:
PROC SQL;
Select
,
(SCORE.Math+SCORE.Chinese+SCORE.English)/3 as avg
from TMP.SCORE
whereSCORE.Sex EQ 'f'
;
五.编程题(20%)
1.试通过编程建立一个名为ks1的数据集,内含变量姓名、学号、生日、成绩,部分具体数据如下(注意,不允许改动原始数据的结构、顺序等。
):
xulili 001 82/04/21 89 zhangsanfeng 012 85/11/02 91
wanghu 101 84/03/14 76 guojianguang 115 83/09/18 80
完成上述任务的程序如下:
data ks1;
length name$ 12.;
input name$ num$ birthday yymmdd8.score@@;
cards;
xulili 001 82/04/21 89 zhangsanfeng 012 85/11/02 91
wanghu 101 84/03/14 76 guojianguang 115 83/09/18 80
run;
2.试用数据步编程将GPA数据集中变量GPA的值大于3但小于4的观测记录,以0.1的概率抽取出来,生成新的数据集tmp。
完成上述任务的程序如下:
data tmp;
set tmp.gpa;
if3<gpa<4;
if ranuni(0) le 0.1thenoutput;
run;。