SAS导入 - 剥离标题行

时间:2015-09-07 22:18:52

标签: import sas

尝试从结构化数据集中删除分页符标题。没有标题,以下内容将起作用:

data uk;
infile "/folders/myfolders/import/withheader.txt" truncover;
format promocode_order best10. date date9. time TIME8.  code $20. singlecode $20. name $50. order_spend best8. shipping_cost best8. country_code $2.;
informat date DDMMYY10. time TIME8. ;
input @1 promocode_order @12 date @23 time @32 order_spend @45 shipping_cost @59 code /
name 1-50 /
@1 country_code;
country_code="UK";
run;

但是有标题是一个问题。有没有办法可以在导入之前迭代文件并选择要导入的记录。我可以排除它是否以标题标签/空白开始。

谢谢!

2 个答案:

答案 0 :(得分:0)

在数据步骤中添加dummy输入语句,保留另一行输入语句的行,并检查自动变量_INFILE_是否包含标题行。如果它没有继续正常的input声明。

E.g。

input @;
if _INFILE_ ne "header row string" then <original input statement>;

答案 1 :(得分:0)

通常你输入行的某些部分并从值中告诉它是应该删除的标题。也不要使用FORMAT语句来执行LENGTH或ATTRIB语句的工作。因此,如果您的标题行看起来像变量名称,那么它可能就像消除以'PROMOCODE'开头的行一样简单。

data uk;
  infile "/folders/myfolders/import/withheader.txt" truncover;
  length promocode_order date time 8 code singlecode $20
         name $50 order_spend shipping_cost 8 country_code $2
  ;
  format date date9. time TIME8. ;
  informat date DDMMYY10. time TIME8. ;
  input @ ;
  if infile=:'PROMOCODE' or _infile_=' ' then delete ;
  input @1 promocode_order @12 date @23 time @32 order_spend @45 shipping_cost @59 code
      / @1  name 1-50
      / @1 country_code
  ;
run;