Hi,
does anyone know how to preserve the page break when importing a Listing file into ODS?? I am using the following code -
ods pdf;
proc document name=import(write);
import textfile="odsglm.lst" to ^;
list/ details;
run;
ods pdf close;
Despite also using an LST file in the example, the example on the SAS website also does not preserve the page breaks -
I tried the code and see there may be a problem in the way ODS is reading text files using proc document import to statement - it doesn't recognize page breaks. You can see this if you use the list / levels=all details statement, which is supposed to show page breaks, if any, in the textfile being read.
To go around this issue, we can use multiple replay statements like this:
ods pdf file="out.pdf";
proc document name=import(write);
import textfile="odsglm.lst" to ^;
obpage \textfile / after; /*optional, seems to be working even without*/
replay textfile(where=(_obs_<14)); /*Inside Macro*/
replay textfile(where=(14<=_obs_<40)); /*Inside Macro*/
....etc... /*Inside Macro*/
run; quit;
ods pdf close;The lines above with the comment "Inside Macro" can be easily macrotized if you know the exact lines where the page-breaks (HEX code '0C'x) are. This can be done using a simple data step like:
data _null_ ;
retain i 0;
infile "odsglm.lst" truncover;
input first $;
if substr(first,1,1)='0C'x then do; /*If first character is page break, then create macro variable*/
i=i+1;
call symput("pos"||strip(put(i, best.)), _N_);
end;
run;
I tried the code and see there may be a problem in the way ODS is reading text files using proc document import to statement - it doesn't recognize page breaks. You can see this if you use the list / levels=all details statement, which is supposed to show page breaks, if any, in the textfile being read.
To go around this issue, we can use multiple replay statements like this:
ods pdf file="out.pdf";
proc document name=import(write);
import textfile="odsglm.lst" to ^;
obpage \textfile / after; /*optional, seems to be working even without*/
replay textfile(where=(_obs_<14)); /*Inside Macro*/
replay textfile(where=(14<=_obs_<40)); /*Inside Macro*/
....etc... /*Inside Macro*/
run; quit;
ods pdf close;The lines above with the comment "Inside Macro" can be easily macrotized if you know the exact lines where the page-breaks (HEX code '0C'x) are. This can be done using a simple data step like:
data _null_ ;
retain i 0;
infile "odsglm.lst" truncover;
input first $;
if substr(first,1,1)='0C'x then do; /*If first character is page break, then create macro variable*/
i=i+1;
call symput("pos"||strip(put(i, best.)), _N_);
end;
run;
aha...yes..it took me a while to understand your solution but now I get it. So the 'replay' statement is forcing a page break. Very nice. I will give this a try, many thank!!!
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.