SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1140|回复: 5
打印 上一主题 下一主题

新手!sas programming by example 里面习题的问题?

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2005-10-25 21:28:06 | 只看该作者

新手!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:?: -->
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2005-10-26 11:38:25 | 只看该作者

to liudreams

应该再加上两句吧
[code:c501f]filename file1 'E&#58;\WINNT\system32\file1'; /*指定file1的物理位置*/
filename file2 'E&#58;\WINNT\system32\file2'; /*指定file2的物理位置*/[/code:c501f]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2005-10-26 14:43:30 | 只看该作者

谢谢,可是结果成这样了!

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是乱码了。晕了,还请大侠指教!谢谢!
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2005-10-26 15:37:57 | 只看该作者

@

我觉得还是和infile的文件位置指定有关,

试试改动一下sas启动的时候work的位置。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
5#
 楼主| 发表于 2005-10-27 00:58:12 | 只看该作者

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;
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
6#
 楼主| 发表于 2005-10-27 13:55:11 | 只看该作者

to liudreams

是啊,infile是指向外部文件,如txt,楼上的是这确的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-9 06:23 , Processed in 0.069995 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表