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

I would like to write the source code to a pdf, before displaying the results of the code.

 

I can use a series of ods pdf text=""; statements, and insert new lines and spacing as needed, but is there a way to put pre formatted text, like with an html <pre> tag so that I do not have to add all the escape characters with newline and nbspace to the source code?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

PROC REPORT seems to work better at preserving the leading spaces.

ods pdf file='c:\downloads\code.pdf';

proc report data=code ;
  column line code ;
  define line / order ;
  define code / style(column)=[font_face=courier asis=on];
run;

proc print data=code;
  id line;
  var code / style = [font_face=courier asis=on];
run;

ods pdf close;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Why not use PROC PRINT?

data code ;
  infile cards truncover ;
  line+1;
  input code $char80. ;
  format code $char80. ;
cards4;
proc print data=sashelp.class;
  var name age;
run;
;;;;

ods pdf file='c:\downloads\code.pdf';

proc print data=code ;
  id line;
  var code / style(data)=[font_face=courier];
run;

ods pdf close;
Tom
Super User Tom
Super User

PROC REPORT seems to work better at preserving the leading spaces.

ods pdf file='c:\downloads\code.pdf';

proc report data=code ;
  column line code ;
  define line / order ;
  define code / style(column)=[font_face=courier asis=on];
run;

proc print data=code;
  id line;
  var code / style = [font_face=courier asis=on];
run;

ods pdf close;
jtcowder
Fluorite | Level 6

That was very helpful, thank you.  

I tweaked the report a bit to get the output from this :

 

jtcowder_0-1621283967793.png

 

to this:

 

jtcowder_1-1621283986811.png

proc report data=code style=blockprint;
column line code ;
define line / '' order noprint;
define code / '' style(column)=[asis=on];
run;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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