SAS中文论坛

标题: 新手!sas programming by example 里面习题的问题? [打印本页]

作者: shiyiming    时间: 2005-10-25 21:28
标题: 新手!sas programming by example 里面习题的问题?
Write a sas progeam to read data from noth files and create a sas data set:
File one
cody  100
pass 98
File two
Frank  90
Beans 98
我是这么写的:
data file1;
input name $ 1-10  score 11-13;
datalines;
cody      100
pass       98
;
data file2;
input name $ 1-10  score 11-13;
datalines;
frenks     90
beans      98
;
Now I have two seperate file, then:
data twofiles;
if not lastrec1 then infile 'file1' end=lastrec1;
        else infile 'file2';
input name $1-10  score 11-13;
proc print;
run;
结果成了:
ERROR: Physical file does not exist, E:\WINNT\system32\file1.
ERROR: Physical file does not exist, E:\WINNT\system32\file2.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TWOFILES may be incomplete.  When this step was stopped there were 0
         observations and 2 variables.
WARNING: Data set WORK.TWOFILES was not replaced because this step was stopped.
可是我看答案&我写的没什么区别,问什么找不到文件呢,不都存在临时文件夹work里面的吗?
谢谢各位了! <!-- s:P --><img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Razz" /><!-- s:P -->  <!-- s:?: --><img src="{SMILIES_PATH}/icon_question.gif" alt=":?:" title="Question" /><!-- s:?: -->
作者: shiyiming    时间: 2005-10-26 11:38
标题: to liudreams
应该再加上两句吧
[code:c501f]filename file1 'E&#58;\WINNT\system32\file1'; /*指定file1的物理位置*/
filename file2 'E&#58;\WINNT\system32\file2'; /*指定file2的物理位置*/[/code:c501f]
作者: shiyiming    时间: 2005-10-26 14:43
标题: 谢谢,可是结果成这样了!
filename file1 'd:\sas\exercise\example\file1.sas7bdat';
filename file2 'd:\sas\exercise\example\file2.sas7bdat';
data twofiles;
     if not lastrec1 then infile file1 end=lastrec1;
     else infile file2;
   input name $1-10  score 11-13;
proc print;
run;
可是结果成这样了:
NOTE: 12 records were read from the infile FILE1.
      The minimum record length was 6.
      The maximum record length was 256.
      One or more lines were truncated.
NOTE: 4 records were read from the infile FILE2.
      The minimum record length was 6.
      The maximum record length was 256.
      One or more lines were truncated.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.TWOFILES has 14 observations and 2 variables.
NOTE: DATA statement used:
      real time           0.20 seconds
      cpu time            0.12 seconds

我得file1.file2都只有2个observation,怎么现在成这么多了,而且output是乱码了。晕了,还请大侠指教!谢谢!
作者: shiyiming    时间: 2005-10-26 15:37
标题: @
我觉得还是和infile的文件位置指定有关,

试试改动一下sas启动的时候work的位置。
作者: shiyiming    时间: 2005-10-27 00:58
标题: infile应该是用到外部文件
有人这么解释的:如果是在libarary里面的话就已经成了sas的文件,不算外部文件,所以如果txt的话就是可以的。
filename file1 'D:\sas\exercise\example\file1.TXT';
Data filea;
infile file1;
input NAME $ 1-10 @13 SCORE;
run;
proc print;
run;
filename file2 'D:\sas\exercise\example\file2.TXT';
Data fileb;
infile file2;
input NAME $ 1-10 @13 SCORE;
run;
proc print;
run;
data twofiles;
     if not lastrec1 then infile 'D:\sas\exercise\example\file1.TXT' end=lastrec1;
     else infile 'D:\sas\exercise\example\file2.TXT';
    INPUT NAME $ 1-10  @13 SCORE;
proc print;
run;
作者: shiyiming    时间: 2005-10-27 13:55
标题: to liudreams
是啊,infile是指向外部文件,如txt,楼上的是这确的。




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2