【问题标题】:SAS import - stripping out header rowsSAS 导入 - 去除标题行
【发布时间】:2015-09-07 22:18:51
【问题描述】:

试图从原本结构化的数据集中去除分页符标题标签。如果没有标题,以下内容将起作用:

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;

但是有标题是个问题。有没有一种方法可以在导入之前遍历文件并选择要导入的记录。如果它以标题标签 / 为空白开头,我可以排除。

谢谢!

【问题讨论】:

  • 您应该发布一些显示标题的示例数据。

标签: import sas


【解决方案1】:

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

例如

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

【讨论】:

    【解决方案2】:

    通常您输入该行的某些部分并从值中得知它是应该删除的标题。也不要使用 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多