Hello All,
Am trying read a freeform text from one field in a website and store in a table and trying to printout to a .txt file
below text entered in the description field :
Testname Testname Ry text to test very long characters and pragaraph and sentences whether it fits to the website and table and more .
Testname Testname RY 11111111-1
FI96 1111 1111 1111 1111
Rita Zamamamam
ES54 1111 1111 1111 1111 1111, NTSBESM1
while writing to file out.txt it splits to random lines like below
Code used :
%let _INPUT_table= Test_table; %let form_attachment_path='\casedetails\casedescription.txt; data _null_; set &_INPUT_table. (obs=1 firstobs=1); file "&form_attachment_path" TERMSTR=CRLF lrecl=100; put 'Description of damagae: ' description; run;
Please help me to write data in expected format with out random line breaks
Works with a suitable LRECL:
data have;
infile datalines truncover;
input description $200.;
datalines;
Testname Testname Ry text to test very long characters and pragaraph and sentences whether it fits to the website and table and more .
Testname Testname RY 11111111-1
FI96 1111 1111 1111 1111
Rita Zamamamam
ES54 1111 1111 1111 1111 1111, NTSBESM1
;
data _null_;
set have;
file "~/test.txt" lrecl=200;
put description;
run;
Output file, when downloaded from ODA and opened with TextExit on the Mac:
Testname Testname Ry text to test very long characters and pragaraph and sentences whether it fits to the website and table and more .
Testname Testname RY 11111111-1
FI96 1111 1111 1111 1111
Rita Zamamamam
ES54 1111 1111 1111 1111 1111, NTSBESM1
Just set the LRECL high enough that the longest line is accommodated.
Works with a suitable LRECL:
data have;
infile datalines truncover;
input description $200.;
datalines;
Testname Testname Ry text to test very long characters and pragaraph and sentences whether it fits to the website and table and more .
Testname Testname RY 11111111-1
FI96 1111 1111 1111 1111
Rita Zamamamam
ES54 1111 1111 1111 1111 1111, NTSBESM1
;
data _null_;
set have;
file "~/test.txt" lrecl=200;
put description;
run;
Output file, when downloaded from ODA and opened with TextExit on the Mac:
Testname Testname Ry text to test very long characters and pragaraph and sentences whether it fits to the website and table and more .
Testname Testname RY 11111111-1
FI96 1111 1111 1111 1111
Rita Zamamamam
ES54 1111 1111 1111 1111 1111, NTSBESM1
Just set the LRECL high enough that the longest line is accommodated.
Some times it not working as expected for a very long data as in the attached file. The data splits in to multiple lines
with below option
file "&attachment_path" TERMSTR=CRLF lrecl=300;
Shall i increase the lrecl=2000 ? does it have any side effects ?
Maxim 1: Read the Documentation.
In this case, for the FILE Statement , where it says
specifies the logical record length of the output file.
Default | If you omit the LRECL= option, SAS chooses a value based on the operating environment's file characteristics. |
---|---|
Interaction | Alternatively, you can specify a global logical record length by using the LRECL system option. In SAS 9.4, the default value for the global LRECL system option is 32767. If you are using fixed-length records (RECFM=F), the default value for LRECL is 256. |
(emphasis by me)
So you should first try to work without a specific LRECL, and only set it when you get an overflow.
Note that, for the default RECFM=V, only the bytes needed will end up on each line, regardless of a larger LRECL.
PS on UNIX systems (see here), the maximum value for LRECL is 1GB, while the default is 32767.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.