如何使用SAS数据线读取超过256个字符的记录长度?

时间:2015-10-29 11:13:31

标签: sas

我需要保留我试图在程序中创建的数据集的定义。但是,由于传入的记录长度可能超过256个字符,因此我将记录拆分为两个。如果我有外部文件,我可以使用infile lrecl=1000,但是datalines此选项不可用。有没有办法可以在使用datalines时增加记录长度?

data output;
  length value $500 ;
  infile datalines dlm='#';
  input id $ value $  ;
datalines ;
ID1#Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae risus nibh. Aliquam lacus sem, tempor sed scelerisque quis, blandit ut ante. Maecenas dapibus tellus dui, non congue risus auctor sit amet. Nulla fermentum ligula in leo vulputate accumsan. Ut aliquet vulputate nibh egestas faucibus. Donec elit mi, convallis sit amet interdum eu, tempus eu est. Donec elementum dapibus ipsum id bibendum. Phasellus in ex ut quam mollis congue. Nulla at augue facilisis, elementum felis euismod, accumsan arcu. Suspendisse lobortis iaculis odio, a suscipit quam.
;quit ;

然后将输出数据集拆分为:

ID          VALUE
------------------------------------
ID1         Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae risus nibh. Aliquam lacus sem, tempor sed scelerisque quis, blandit ut ante. Maecenas dapibus tellus dui, non congue risus auctor sit amet. Nulla fermentum ligula in leo vulputate accumsan.
Ut aliqu    arcu. Suspendisse lobortis iaculis odio, a suscipit quam.

3 个答案:

答案 0 :(得分:2)

SAS 9.4之前的默认LRECL为256.虽然在DM中这对CARDS / DATALINES语句的lrecl没有任何影响,这确实会影响批处理模式下的输入,这可能是你&#的方式39;重新提交代码。

您需要在系统启动之前更改LRECL才能使其正常工作。最好的办法是在配置文件中将LRECL设置为更长的时间,方法是添加到文件的顶部:

-LRECL 32767

(或者你喜欢的任何较短的长度。)

在配置中没有LRECL修改的情况下运行:

1          proc options option=lrecl;

    SAS (r) Proprietary Software Release 9.3  TS1M2

 LRECL=256         Default record length for external files
NOTE: PROCEDURE OPTIONS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2          data output;
3            length value $500 ;
4            infile datalines dlm='#';
5            input id $ value $  ;
6            length_value=length(value);
7            put value= length_value=;
8          datalines ;

WARNING: Truncated record.
value=Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae risus
 nibh. Aliquam lac
us sem, tempor sed scelerisque quis, blandit ut ante. Maecenas dapibus tellus du
i, non congue risu
s auctor sit amet. Nulla fermentum ligula in leo vulputate acc length_value=252
NOTE: The data set WORK.OUTPUT has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


10         ;
11         run;

在配置中将LRECL修改为1024后运行示例:

1          proc options option=lrecl;

    SAS (r) Proprietary Software Release 9.3  TS1M2

 LRECL=1024        Default record length for external files
NOTE: PROCEDURE OPTIONS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2          data output;
3            length value $500 ;
4            infile datalines dlm='#';
5            input id $ value $  ;
6            length_value=length(value);
7            put value= length_value=;
8          datalines ;

value=Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae risus
 nibh. Aliquam lac
us sem, tempor sed scelerisque quis, blandit ut ante. Maecenas dapibus tellus du
i, non congue risu
s auctor sit amet. Nulla fermentum ligula in leo vulputate accumsan. Ut aliquet
vulputate nibh ege
stas faucibus. Donec elit mi, convallis sit amet interdum eu, tempus eu est. Don
ec elementum dapib
us ipsum id bibendum. Phasellus in ex ut quam mollis congue. Nulla at augue faci
lisis, elementum f
elis euismod, ac length_value=500
NOTE: The data set WORK.OUTPUT has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


10         ;
11         run;

NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           0.36 seconds
      cpu time            0.40 seconds

答案 1 :(得分:1)

我无法重现您的结果请提供有关操作系统和BATCH与EG / DMS等的更多信息。您可能需要检查相关选项,如S

 S=0
Option Definition Information for SAS Option S
    Group= INPUTCONTROL
    Group Description: Data entry and processing settings
    Description: Length of source statements and data lines
    Type: The option value is of type LONG
          Range of Values: The minimum is 0 and the maximum is 9007199254740992
          Valid Syntax(any casing): MIN|MAX|n|nK|nM|nG|nT|hexadecimal
    Numeric Format: Usage of LOGNUMBERFORMAT does not impact the value format
    When Can Set: Startup or anytime during the SAS Session
    Restricted: Your Site Administrator can restrict modification of this option
    Optsave: PROC Optsave or command Dmoptsave will save this option

SAS支持另一种形式的流内数据,它写入PARMCARDS选项定义的文件,默认为fileref FT15F001。您可以尝试此版本的程序,看看它是否解决了问题。

filename FT15F001 temp lrecl=1024;
data output;
  length value $1024;
  infile FT15F001 dlm='#';
  input id $ value $;
parmcards;
ID1#Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae risus nibh. Aliquam lacus sem, tempor sed scelerisque quis, blandit ut ante. Maecenas dapibus tellus dui, non congue risus auctor sit amet. Nulla fermentum ligula in leo vulputate accumsan. Ut aliquet vulputate nibh egestas faucibus. Donec elit mi, convallis sit amet interdum eu, tempus eu est. Donec elementum dapibus ipsum id bibendum. Phasellus in ex ut quam mollis congue. Nulla at augue facilisis, elementum felis euismod, accumsan arcu. Suspendisse lobortis iaculis odio, a suscipit quam.
;;;;
   run;

enter image description here

答案 2 :(得分:-1)

infile选项可用。

Infile cards lrecl=500 truncover;

但问题可能是您的数据包含换行符。使用十六进制编辑器查看它以查看是否存在任何换行符。