BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
learn_SAS_23
Quartz | Level 8

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 

Harigopalo_0-1633602160451.png

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 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

 

 

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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.

 

 

learn_SAS_23
Quartz | Level 8
Wow , Works as expected . Thanks a lot
learn_SAS_23
Quartz | Level 8

 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 ?

Kurt_Bremser
Super User

Maxim 1: Read the Documentation.

In this case, for the FILE Statement , where it says

LRECL=logical-record-length

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.

learn_SAS_23
Quartz | Level 8
Now it's more clear , thanks for quick help

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 924 views
  • 0 likes
  • 2 in conversation