Import SAS导入-剥离标题行

Import SAS导入-剥离标题行,import,sas,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_c

尝试从其他结构化数据集中剥离分页符标题标签。如果没有标题,以下内容将起作用:

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;
但是将标题放在中是一个问题。是否有一种方法可以在导入之前遍历文件并选择要导入的记录。如果它以标题标签开头/为空,我可以将其排除在外


谢谢

在数据步骤中添加一个
dummy
input语句,保留该行以获得进一步的输入语句,并检查自动变量
\u infle\u
是否包含标题行。如果它不能继续正常的
输入
语句

例如

input@;
如果填充“标题行字符串”,则;

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

您应该发布一些显示标题的示例数据。
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;