Google SAS Search

Add to Google

Thursday, May 17, 2007

LRECL

Here is a SAS trick that is especially useful for Windows users. By default, Windows creates files with a logical record length of 256. This means if you are creating a flat file with records (lines) longer than 256, the lines are going to wrap. You can tell Windows exactly how long to make the record length on the filename statement in SAS. The option is lrecl= (logical record length) and it looks like this:

filename myFile "c:\some directory\some file.txt" LRECL= 400;

Then you can write lines to that file that are up to 400 characters long without fear of the line wrapping.

6 comments:

  1. Stephen,

    I don't think this is a Windows issue but a SAS on Windows problem. I have never seen a cap on chars anywhere else except on SAS. It may predate modern Windows systems though. I thought v 6 of SAS was the first on Windows and that was a longgggg time ago.

    ReplyDelete
  2. Alan, I think you are right. For some reason I just assumed it was Windows creating the file with lrecl=256, but that doesn't really make sense. I create files all the time in other languages and don't run into that problem.

    I agree with you, it must be the way SAS is creating the file under Windows. As always, thanks for the informative comment!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi,

    Am using Base SAS V9.1.3 and executing on Mainframe environment. I have a problem in writing the procedure output (like proc print, proc report) to a physical sequential file using proc printto procedure in mainframe if the length of the record is morethan 256.

    I created the PS file with the required length i.e of 1500, but still the output of the proc gets wrapped to the next line after 256 characters. Please help. Below is the code for ur reference.

    //XXXXXXXX JOB (B12303156,34575PU),
    // 'NAME=XXXXXXXX',
    // CLASS=T,
    // MSGCLASS=A,NOTIFY=&SYSUID
    //***************************************************************
    //*
    //STEP1 EXEC DB2LSASB
    //SYSPRINT DD SYSOUT=*
    //SYSIN DD *

    FILENAME SAS3055 'RRSPQ.MIGRATED.PRODSAS(QUP3233)' DISP=SHR;

    %INCLUDE SAS3055;


    PROC PRINTTO PRINT = 'U19S.TEMP.OUT1';

    PROC PRINT DATA = &DSNAME; RUN;

    PROC PRINTTO PRINT = PRINT ; RUN;

    Regards,
    Narasimha Rao.

    ReplyDelete
  5. narasimha - I think you need a dd statement for the other files giving the lrecl. So long since I did that..

    The LRECL= option comes from SAS' origins on 360 Architecture machines incl DOS/360 & MVS. On these systems fils were the programmers' responsibility and they were expected to know how long records should be and how big files would be. So those things had to be declared and missing them was an error.

    Later systems like VMS, Unix, Mac & later Windows, regarded files as streams of bytes and the OS did not need to the file internals in order to set the buffer size.

    ReplyDelete