从多行读入单行,直到遇到定界符

Read from multiple lines into single row until delimiter is encountered

我一直在尝试从一个文本文件中读取,该文件具有如下所示的行且分隔符为分号:

Sun rises
 in the east
  and;
sets in the 
west
;

我正在尝试在单个单独的记录中从定界符到定界符读取数据,如下所示 variable_name

1 Sun rises in the east and
2 sets in the west

我已经尝试了几乎所有可用的选项 infile 选项都无济于事。是否可以像上面那样阅读?怎么做?任何 clue/help 将不胜感激。

逐字阅读并连接成更长的行。

data want ;
  infile mydat end=eof  ;
  length word 0 line 00 ;
  drop word;
  do while (^eof and ^index(word,';'));
    input word @ ;
    line = catx(' ',line,compress(word,';'));
  end;
  if _n_ > 1 or line ne ' ' then output;
run;

recfm=n 是告诉 SAS 没有 'line breaks' 的方法。所以:

data want;
  infile "c:\temp\test.txt" recfm=n dsd dlm=';';
  length text 24;
  input text $;
run;

请注意,换行符将被读取为另外两个字符,因此如果您想删除这些字符,您可以使用 compressc 选项来删除控制字符(包括 LF/FF).