【问题标题】:Reading Messy SAS Data读取凌乱的 SAS 数据
【发布时间】:2017-12-07 13:59:30
【问题描述】:

我怎样才能读到这个 ​​-

    C 303 102 140 B 293 C 399 B 450 233 456
450 A 289 282 555

像这样 -

Group Score
    C 303 
    C 102 
    C 140 
    B 293 
    C 399 
    B 450 
    B 233 
    B 456
    B 450 
    A 289 
    A 282 
    A 555

在 SAS 中?我已经尝试过 @'character' 列指针,但我似乎无法正确。这是到目前为止的代码:( -

data OUTCOMES;
infile 'testscores.txt';
input @'C' SCORES; Run;

【问题讨论】:

  • 能否请您添加生成这些数据的代码?

标签: sas


【解决方案1】:

咕哝:

用于保持输入的双与号 (@@) 运算符看起来不错 [双关语] 用于跨行边界扫描输入。

构造一个示例外部数据文件:

filename haveFile temp;

data _null_;
  file haveFile;
  put "    C 303 102 140 B 293 C 399 B 450 233 456";
  put "450 A 289 282 555";
run;

从文件中读取,一次一个令牌。

data have ;
  attrib
    token group length=$10
    score length=8
  ;

  retain group;

  infile haveFile ;

  input token @@;
  score = input (token, ?? 12.);  * check if token can be interpreted as a number, the ?? modifier prevents errors and notes in the log;

  if missing (score) and token ne '.' then 
    group = token;
  else
    output;
run;

【讨论】:

  • 完美,谢谢!这是一个陡峭的学习曲线,这肯定有助于克服它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-14
  • 2016-10-09
  • 2016-12-22
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多