Desktop productivity for business analysts and programmers

Lrecl and Extra Pipeline in SAS output

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Lrecl and Extra Pipeline in SAS output

Hi All,

 

I have 2 questions from the code below. I am trying to produce output into textfile with pipeline delimeter. The output does not match with my expectation.

 

My sample code is as per below:

 

data &try;

set acc.&try nobs=j end=eod;

file "C:\TRY\&out_rpt..txt" lrecl=300 dlm='|';

if _n_ = 1 then

put @1 'VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|VAR1|system|VAR1';

put @1 VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

VAR1

;

if _n_=j then do;

put @1 'TOTAL ACCOUNT : | ' j '|';

end;

run;

 

I encounter 1 warning stating that

WARNING: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation

marks.

 

1)After I already specify LRECL = 300, why does the warning appear?

 

2) The output from above code shows that, there is extra pipeline after total obs.

 

Total Account : | 10 ||

 

Thanks in advance to whoever that willing to help Smiley Happy


Accepted Solutions
Solution
‎10-12-2017 10:34 PM
Super User
Super User
Posts: 7,154

Re: Lrecl and Extra Pipeline in SAS output

[ Edited ]

You can get PROC EXPORT to write the main file and just add the footer.

But that can be tricky if you wnat the variables in a different order than they exist in the dataset.

Why not let SAS write the variable names instead of putting them into a string?  Then you don't need to worry that it might be longer than 262 characters.  It is easy to use PROC TRANSPOSE to generate a dataset with one record per variable name.  Note that your list of variable names could even use SAS variable list features like VAR3-VAR5 as shorthand for VAR3 VAR4 VAR5.  Note that 300 seems like an pretty short length to set for your LRECL for outputting an unknown number of variables. Better to set it larger than you really need. 32K is reasonable default, but the FILE statement will support 1000000 or larger depending on your hardware.  Really not much penalty for setting it too large as SAS will only write the number of characters it needs.

 

%let varlist=VAR1 VAR3-VAR8 VAR234 ;
%let dsn=acc.&try ;

proc transpose data=&dsn (obs=0) out=names ;
  var &varlist;
run;

data _null_;
   set names ;
   file "C:\TRY\&out_rpt..txt" lrecl=32767 dlm='|' dsd ;
   put _name_ @ ;
run;
data _null_;
   set &dsn end=eof ;
   file "C:\TRY\&out_rpt..txt" lrecl=32767 dlm='|' dsd MOD ;
   put (&varlist) (+0) ;
   if eof then put 'TOTAL ACCOUNT : |' _n_ ;
run;

 

View solution in original post


All Replies
Super Contributor
Posts: 460

Re: Lrecl and Extra Pipeline in SAS output

To be honest I think you're just making life hard for yourself by using a data step here - Proc Export is much simpler

 

proc export data=sashelp.class
   outfile='/folders/myshortcuts/Dropbox/class.ppe'
   dbms=dlm; 
   delimiter='|';
run;
PROC Star
Posts: 1,177

Re: Lrecl and Extra Pipeline in SAS output

Posted in reply to ChrisBrooks

Although @ChrisBrooks gives you the solution, for your information here's a useful tip.

 

When SAS sees a very long character string, the possibility has arisen that you've forgotten an end "quote", so it throws that warning. It has nothing to do with your output file, it's just because of your long heading row string. You can get rid of it by surrounding your code with

 

options  noquotelenmax;
options  quotelenmax;

 

statements.

 

Tom

Contributor
Posts: 22

Re: Lrecl and Extra Pipeline in SAS output

Thanks. I already add that in my code.

Contributor
Posts: 22

Re: Lrecl and Extra Pipeline in SAS output

Posted in reply to ChrisBrooks

Yes, Proc export will be easier. However, because I have to hardcode things at the footer, so thats why I write the code that way.

 

Maybe I need to use proc export for the beginning part. And for the footer, I just write and use function MOD to append in the existing output. Is that possible?

 

Anyway, thanks for the suggestion!!

 

 

Super User
Posts: 8,055

Re: Lrecl and Extra Pipeline in SAS output


Hhh111 wrote:

Yes, Proc export will be easier. However, because I have to hardcode things at the footer, so thats why I write the code that way.

 

Maybe I need to use proc export for the beginning part. And for the footer, I just write and use function MOD to append in the existing output. Is that possible?

 


Yes. Create a file reference first, use that in proc export for the output file, and then use it in a data step with mod. Text from the data step will be appended. After all, we're dealing with a plain text file here, so appending is no problem.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 22

Re: Lrecl and Extra Pipeline in SAS output

Posted in reply to KurtBremser

Thanks for the input sir. The output looking good now. Smiley Happy

Super User
Posts: 8,055

Re: Lrecl and Extra Pipeline in SAS output

For question 2: SAS automatically adds a delimiter after a variable in the put list, so you get an extra delimiter.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎10-12-2017 10:34 PM
Super User
Super User
Posts: 7,154

Re: Lrecl and Extra Pipeline in SAS output

[ Edited ]

You can get PROC EXPORT to write the main file and just add the footer.

But that can be tricky if you wnat the variables in a different order than they exist in the dataset.

Why not let SAS write the variable names instead of putting them into a string?  Then you don't need to worry that it might be longer than 262 characters.  It is easy to use PROC TRANSPOSE to generate a dataset with one record per variable name.  Note that your list of variable names could even use SAS variable list features like VAR3-VAR5 as shorthand for VAR3 VAR4 VAR5.  Note that 300 seems like an pretty short length to set for your LRECL for outputting an unknown number of variables. Better to set it larger than you really need. 32K is reasonable default, but the FILE statement will support 1000000 or larger depending on your hardware.  Really not much penalty for setting it too large as SAS will only write the number of characters it needs.

 

%let varlist=VAR1 VAR3-VAR8 VAR234 ;
%let dsn=acc.&try ;

proc transpose data=&dsn (obs=0) out=names ;
  var &varlist;
run;

data _null_;
   set names ;
   file "C:\TRY\&out_rpt..txt" lrecl=32767 dlm='|' dsd ;
   put _name_ @ ;
run;
data _null_;
   set &dsn end=eof ;
   file "C:\TRY\&out_rpt..txt" lrecl=32767 dlm='|' dsd MOD ;
   put (&varlist) (+0) ;
   if eof then put 'TOTAL ACCOUNT : |' _n_ ;
run;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 184 views
  • 0 likes
  • 5 in conversation