全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2010-11-11 20:47:29

跟crakman做sas base认证试题(3)

3.The Excel workbook REGIONS.XLS contains the following four worksheets:
     EAST
     WEST
     NORTH
     SOUTH

The 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

本文属于博客:http://crackman.net/ 版权归作者所有,欢迎转载!如有转载,请务必注明出处!未经本文作者同意不得用于商业应用。
其实这道题考察的是SAS读取非SAS数据源。
看看答案,四个答案里面差异在于符号$以及E和N的差别。

以下是SAS PAPER里面的解释:
我觉得最关键的就是SAS LIBNAME建立的是以XLS为数据源的逻辑库时,创建了两个数据源,一个是spreadsheet 另外一个是 named range(指定范围的数据)。
我们在输出整个数据时候,应该是spreadsheet,而不是相对指定的范围的数据。制定范围的数据,其实熟悉EXCEL应该知道,就是我们选择部分数据作为我们要分析的对象,用
鼠标拖动即可产生制定范围的数据。
Looking at SAS Explorer it may be surprising that each dataset written to
Excel appears twice, once with the expected name and once with a trailing
“$”.
Unlike a typical data source, data in an Excel spreadsheet need not be left
and top aligned. For this Excel has named ranges which allow data to be
placed anywhere inside a spreadsheet. By default SAS reads and writes
data from named ranges on spreadsheets, but will also read spreadsheet
data directly in the absence of a named range.
When a new SAS dataset is created in an Excel library, SAS creates both a
spreadsheet and a named range. Each is given the same name, with the
spreadsheet denoted by a trailing “$”.
In the example at right CLASS is the named range created by the Excel
engine and CLASS$ is the spreadsheet created by the Excel engine to hold
the named range. Within SAS, the named range is referred to as
Wrkbk.CLASS, and the spreadsheet is referenced using the name literal
Wrkbk.’CLASS$’n.
SAS name literals are name tokens written as strings within quotation
marks, followed by the letter n. Name literals allow the use of special
characters that are not otherwise allowed in SAS names , like the “$” used by
the Excel libname engine to distinguish worksheets from named ranges. For
more information see the Recommended Readings.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

3583 3
2010-11-11
2.Given the following raw data records in TEXTFILE.TXT:

----|----10---|----20---|----30
John,FEB,13,25,14,27,Final
John,MAR,26,17,29,11,23,Current
Tina,FEB,15,18,12,13,Final
Tina,MAR,29,14,19,27,20,Current

The following output is desired:

Obs Name Month Status    Week1   Week2   Week3   Week4   Week5

   1   John   FEB   Final       $13     $25     $14     $27       .
   2   John   MAR   Current     $26     $17     $29     $11     $23
   3   Tina   FEB   Final       $15     $18     $12     $13       .
   4   Tina   MAR   Current     $29     $14     $19     $27     $20

Which SAS program correctly produces the desired output?

        A.
data WORK.NUMBERS;
   length Name $ 4 Month $ 3 Status $ 7;
   infile 'TEXTFILE.TXT' 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 'TEXTFILE.TXT' 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 'TEXTFILE.TXT' 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 'TEXTFILE.TXT' 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

本文属于博客:http://crackman.net/ 版权归作者所有,欢迎转载!如有转载,请务必注明出处!未经本文作者同意不得用于商业应用。
这道题其实考察的是读入外部文本数据时几个知识点,1.INFILE语句读入外部数据时候,参数MISSOVER以及DSD DLM的参数意义;2.INPUT读入数据的指针;3.@符号对指针的影响。
下面逐个对着程序,来解剖一下执行过程。
A.DSD:规定若一个数据是由引号,那么SAS认为引号内的逗号也是属于字符数据;设定默认分隔符为逗号;连续两个分隔符之间的数据位缺失值;读入数据时去掉引号。
input语句在读入观测时,先从第一行“John,FEB,13,25,14,27,Final”读取数据“John,FEB”就转入到了第二行“John,MAR,26,17,29,11,23,Current”,那么因为month="FEB"是true
所以接着在第二行“John,MAR,26,17,29,11,23,Current”,读入week1 week2,但是john mar都是字符型,而week1 week2默认为数值型,所以就是缺失值。继续读入week3 week4也就是26 17
接着就是status 是29。读完之后回到infile,回到input,从第三行开始读"Tina,FEB,15,18,12,13,Final",读入name month之后,转达到第四行“Tina,MAR,29,14,19,27,20,Current”。
B.MISSOVER:组织INPUT从下一个数据行中读入数据,未赋值的变量就是缺失值。
其实从A看出,因为第一次INPUT只读入第一数据行两个值,指针转入到第二行了。那么MISSOVER是否可以阻止呢?肯定不能阻止,因为INPUT第一次就只读入两个数据,而且第一行的数据也是

大于2个的,所以根本就无需阻止。自己读完两个数据之后自动转向第二行。不能让第一次和第二次的input指针保留在同一行中。
C.正确答案。原因很简单,因为@符号,让第一个INPUT读完数据之后,指针依然留在第一个数据行,等待第二个INPUT来读入后续的数据。
D.不用解释。INFILE后面加一个@本身就是错误,编译错误
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-11-13 23:16:00
老大,这种东西还是放在你的博客里就行了,这么多内容,放在这里多占地方啊!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-11-17 11:09:23
还好还好了呵呵
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群