在没有FIRSTOBS =

时间:2015-09-29 01:22:40

标签: sas

有没有办法在不使用FIRSTOBS =的情况下读取数据的特定部分?例如,我有5个不同的文件,所有文件都有几行不需要的字符。我希望我的数据从第一行数字开始读取。但是这5个文件中的每一个都有从不同行开始的第一个数字行。而不是进入每个文件以找到FIRSTOBS应该在哪里,有没有办法我可以检查这个?也许通过使用带有ANYDIGIT的IF语句?

3 个答案:

答案 0 :(得分:0)

您是否尝试过SAS文档中的类似内容? Example 5: Positioning the Pointer with a Numeric Variable

data office (drop=x);
    infile file-specification; 
    input x @;
    if 1<=x<=10 then
        input @x City $9.;
    else do;
        put 'Invalid input at line ' _n_;
       delete;
end;
run;

答案 1 :(得分:0)

这假设您不知道每个文件开头要跳过多少行。我的filerefs是UNIX,可以在另一个需要更改的操作系统上运行示例;

*Create two example input data files;
filename FT15F001 '~/file1.txt';
parmcards;
char
char and 103
10 10 10
10 10 10.1
;;;;
   run;
filename FT15F001 '~/file2.txt';
parmcards;
char
char and 103
char
char
char
10 10 10.5
10 10 10
;;;;
   run;
*Read them starting from the first line that has all numbers;
filename FT77F001 '~/file*.txt';
data both;
   infile FT77F001 eov=eov;
   input @;
   /*Reset the flag at the start of each new file*/
   if _n_ eq 1 or eov then do; 
      eov=0;
      flag=1;
      end;
   if flag then do;
      if anyalpha(_infile_) then delete;
      else flag=0;
      end;
   input v1-v3;
   drop flag;
   retain flag;
   run;
proc print;
   run;

答案 2 :(得分:0)

我最终做了:

INPUT City $@;
  StateAvg = input(substr(City,1,4),COMMA4.);

  IF 5000<= StateAvg <= 7000 THEN
   INPUT City 1-7 State ZIP;
  ELSE DO;
    Delete;
    END;

这很有效。感谢您的建议,我回过头来看看示例5,它有所帮助。

相关问题