ODS and Base Reporting

Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1098 views
  • 0 likes
  • 2 in conversation