DATA Step, Macro, Functions and more

Macro to create scripts with linebreaks

Reply
N/A
Posts: 0

Macro to create scripts with linebreaks

Hi!

Is there a wrapper that takes a script as input and outputs the same script but with "smart" linebreaks?

I typically upload scripts to a MVS host and would like to have a fixed linesize, however not splitting SAS statements etc.

Thanks
Frequent Contributor
Posts: 102

Re: Macro to create scripts with linebreaks

Posted in reply to deleted_user
In what form are these scripts stored?
SAS Super FREQ
Posts: 8,868

Re: Macro to create scripts with linebreaks

Posted in reply to deleted_user
And...by "script" do you mean JavaScript? A scripting language like Perl?? Or??? Also, do your "scripts" contain a complete SAS program or SAS program code snippets???

cynthia
Super Contributor
Posts: 474

Re: Macro to create scripts with linebreaks

Posted in reply to deleted_user
By script, I'm assuming you are talking about a SAS program.

Anyway, the answer to your question, whatever your script maybe is no.
You'll have to code that yourself.

A macro with a more or less intelligent behavior could split the content of your files for the 80 char line limit, which exists on MVS.
The easiest way to do this would be to parse each line look for the nearest blank char ' ' under the 80 char limit, still this could produce some weird splits (say at the middle of constant value or expression).
Another way would be to parse to the nearest blank ' ', or ',' or ';', like the following code:

%let LIMIT=80;
%let INPUTF=c:\temp\myfile.sas;
%let OUTPUTF=c:\temp\myfile_&LIMIT..sas;

data _null_;
length INLINE $1024;
infile "&INPUTF";
file "&OUTPUTF";
input;
* under limit no line cut;
if length(_INFILE_) le &LIMIT then put _INFILE_;
else do; * try to cut the line;
INLINE=_INFILE_;
do while (length(INLINE) gt &LIMIT);
I=&LIMIT+1;
DLM='X';
do while (DLM not in (' ',',',';')); * line delimiters;
I=I-1;
if I = 0 then do;
put 'no valid delimiters where found, could not process line:';
put _INFILE_;
stop;
end;
* cut the line;
DLM=substr(INLINE,I,1);
INLINE=substr(INLINE,1,I);
end;
put INLINE;
INLINE=substr(INLINE,I+1);
end;
* check if the remaining is under limit;
if length(INLINE) le &LIMIT then do;
_INFILE_=INLINE;
output;
end;
end;
run;

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Valued Guide
Posts: 2,177

Re: Macro to create scripts with linebreaks

Posted in reply to DanielSantos
Dante

for example, see the SAS Sample 30649 last updated earlier this year, at http://support.sas.com/kb/30/649.html
Sample 30649: A SAS MACRO to Wrap Text

PeterC
N/A
Posts: 0

Re: Macro to create scripts with linebreaks

Thanks for your input.

By script I mean a SAS program just like someone mentioned. The link posted by Peter seems what I'm looking for.
Ask a Question
Discussion stats
  • 5 replies
  • 161 views
  • 0 likes
  • 5 in conversation