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

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 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

8 REPLIES 8
ChrisBrooks
Ammonite | Level 13

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;
TomKari
Onyx | Level 15

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

Hhh111
Calcite | Level 5

Thanks. I already add that in my code.

Hhh111
Calcite | Level 5

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!!

 

 

Kurt_Bremser
Super User

@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.

Hhh111
Calcite | Level 5

Thanks for the input sir. The output looking good now. 🙂

Tom
Super User Tom
Super User

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 1793 views
  • 0 likes
  • 5 in conversation