Hello.
I am trying to export a text file with specific position points for columns. I am having difficulty with removing the extra blank line after each row of data. This text file must have line record length of 455 and CRLF return but it seems like my file is producing CR after each row of data. This is the code I am using. Can anyone see what needs to be modified. Any help would be greatly appreciated. Thank you.
DATA _NULL_;
file 'D:\EF/VACHLINVARMv1.TXT' Ls= 445;
IF _N_ = 1 THEN DO;
SET E.tatehdr;
PUT
@1 FILE_TYPE
@51 TOTAL_RECORDS_IN_FILE
@61 FILE_NAME
@86 FILE_IDREC
@118 FILE_RPT_PERIOD ;
END;
SET E.slevel;
PUT @1 RECORD_NUM @11 FIPS @13 AGNCY_NUM @49 TABLE_NAME @69 WEA
@119 TYPE @169 FinalWea @184 TYPE2 @234 TOTAL_INDICATOR @435 COUNT @445 '0D'x;
RUN;
Your code with a few tweaks as below should return what you're after.
DATA _NULL_;
file 'D:\EF/VACHLINVARMv1.TXT' lrecl=455 pad termstr=crlf;
IF _N_ = 1 THEN
DO;
SET E.tatehdr;
PUT
@1 FILE_TYPE
@51 TOTAL_RECORDS_IN_FILE
@61 FILE_NAME
@86 FILE_IDREC
@118 FILE_RPT_PERIOD
;
END;
SET E.slevel;
PUT
@1 RECORD_NUM
@11 FIPS
@13 AGNCY_NUM
@49 TABLE_NAME
@69 WEA
@119 TYPE
@169 FinalWea
@184 TYPE2
@234 TOTAL_INDICATOR
@435 COUNT
;
RUN;
Why are you writing a CR at column 455 if you don't WANT a CR at column 455?
If you want to write fixed length records then change the settings in the FILE statement.
file 'myfile' lrecl=455 ;
If you don't want any end-of-line characters then use RECFM=F instead of the default RECFM=V.
If you want to make a variable length file, but have every line padded to the full LRECL then add the PAD option.
If you want to control what end-of-line characters written the use the TERMSTR= option of the FILE statement. You can choose to have CRLF ( a DOS aka Windows file), LF (a Unix file) or CR (the abandoned standard of the 1980's MacOS).
Hi. Do you mean something like this (see below)? Still did not work. My system tells me the line is incorrect as it found record length of 456 when the expected length must be 444-445.
DATA _NULL_;
file 'D:\EF/VACHLINVARMv1.TXT' pad termstr=crlf lrecl=445 ;
IF _N_ = 1 THEN
DO;
SET E.tatehdr;
PUT
@1 FILE_TYPE
@51 TOTAL_RECORDS_IN_FILE
@61 FILE_NAME
@86 FILE_IDREC
@118 FILE_RPT_PERIOD
;
END;
SET E.slevel;
PUT
@1 RECORD_NUM
@11 FIPS
@13 AGNCY_NUM
@49 TABLE_NAME
@69 WEA
@119 TYPE
@169 FinalWea
@184 TYPE2
@234 TOTAL_INDICATOR
@435 COUNT
;
RUN;
Read the file back in with SAS. The NOTEs will show you the min and max line length.
data _null_;
infile 'D:\EF/VACHLINVARMv1.TXT' ;
input;
run;
If that is showing 455 then the problem is with the other software. What software is it that is saying the lines have more than 455 characters?
Things to check.
You explicitly create the CR with this:
@445 '0D'x;
0D is the carriage return.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.