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.
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;