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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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

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
  • 3 replies
  • 723 views
  • 0 likes
  • 2 in conversation