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

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 - 

 

https://documentation.sas.com/?docsetId=odsproc&docsetTarget=n1m49jyc3pkuz6n1k4qrgo8hszn3.htm&docset...

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
vellad
Obsidian | Level 7

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;

vellad_0-1602312135447.png

 

View solution in original post

3 REPLIES 3
vellad
Obsidian | Level 7

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;

vellad_0-1602312135447.png

 

RichardP
Quartz | Level 8

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

 

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2648 views
  • 0 likes
  • 2 in conversation