【问题标题】:Input from File in Data Step without Left Trim在没有左修剪的数据步骤中从文件输入
【发布时间】:2014-03-28 13:20:08
【问题描述】:

我有一个可变长度、非常丑陋的报告文件,我正试图将其读入 SAS。读取文件记录时,我发现从文件左侧自动修剪空格。这使得将原始文件与我的数据步骤中的文件进行比较变得更加困难。如何在不进行自动修剪的情况下读取文件。

文件读取代码

Data Test;
  Infile myFile lrecl=200 firstobs=1 pad;
  length line $135;

  Input line $ 1 - 135;

Run;

示例文件,空格替换为 _ 以提高可见性

Num___Transaction__Comment________________________________
1_____Foo__________This_is_a_comment_about_a_transaction__
___________________foo._Line_breaks_are_fun.
2_____Bar__________Blagh_Blagh
3_____Bar__________Blagh_Blagh
4_____Foo__________Foo_transactions_have_more_comments_so
___________________they_are_harder_to_read.

输出数据集,空格替换为 _ 以提高可见性

line
-----
1_____Foo__________This_is_a_comment_about_a_transaction__
foo._Line_breaks_are_fun.
2_____Bar__________Blagh_Blagh
3_____Bar__________Blagh_Blagh
4_____Foo__________Foo_transactions_have_more_comments_so
they_are_harder_to_read.

【问题讨论】:

    标签: sas datastep


    【解决方案1】:

    您想使用 $CHARn. 信息来保留前导空格,因此:

    Data Test;
      Infile myFile lrecl=200 firstobs=1 pad;
      length line $135;
    
      Input line $char135.;
    
    Run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多