The SAS Output Delivery System and reporting techniques

Adding the syntax file itself at the end of ODS output

Reply
N/A
Posts: 0

Adding the syntax file itself at the end of ODS output

How can the syntax being used to generate ODS output be included in the output, preferrably at the end?
SAS Employee
Posts: 174

Re: Adding the syntax file itself at the end of ODS output

I'm not aware of a straightforward way to include SAS program source in ODS output in SAS 9.1 or earlier releases. In SAS 9.2, there is a preproduction feature in PROC DOCUMENT that will permit you to import and subsequently replay any text file, including a SAS program, to active destinations, e.g.:
[pre]
proc document name=mydoc;
import textfile="myjob.sas" to ^;
list/levels=all;
replay;
run;
quit;
[/pre]

-- David Kelley, SAS
SAS Super FREQ
Posts: 8,743

Re: Adding the syntax file itself at the end of ODS output

Hi:
The ODS DOCUMENT method sounds cool! The only way I've been able to include any ancillary information (like a TXT file or a SAS program) in ODS output is to code a DATA step program to read the program file. I use $VARYING in my INPUT statement and make a dataset with 2 variables: LINENUM and PGMLINE.

Then I use PROC REPORT with NOHEADERS and RULES=NONE to display the program data set. I do have an example of such a program, but it's old, so it's on a drive that I don't have attached at the moment. But you get the idea. My method is sort of a brute force method, but does get the SAS program at the end of the ODS output file.

cynthia
SAS Super FREQ
Posts: 8,743

Re: Adding the syntax file itself at the end of ODS output

Found it!

Assume that the folder c:\sas programs has a file called prtclass.sas which does a simple proc print of sashelp.class:
[pre]
proc print data=sashelp.class noobs;

title 'proc print';
run;
[/pre]

Next, the program shown below will first do a %include of the PRTCLASS.SAS program, which will cause the code of interest to be included, then compiled and executed. Finally, the DATA step reads in the program and displays the PRTCLASS.SAS program as output via the PROC REPORT step.

I like using PROC REPORT so I can use NOHEADERS on the column header and NOPRINT on the LINENUM. Note the blank line in the program and how I use linelength to preserve this white space (which would normally be ignored). I used RTF because the only students who've asked me about this have wanted RTF output.

Depending on your macro skills, you could further "macro-ize" the program, but like I said, this program is old and is "un-macro-ized" for simplicity.

cynthia

[pre]
options ls=256 nodate nonumber;
ods listing close;

ods rtf file='c:\temp\out_plus_pgm.rtf' style=sasweb;
%include "c:\sas programs\prtclass.sas";

data thepgm;
length linenum 8 pgmline $200;
infile "c:\sas programs\prtclass.sas" length=linelen lrecl=256 missover;
input @;
linenum = _n_;
if linelen = . then do;
** have a blank line and want to keep it in the output;
linelen=0;
pgmline = ' ';
end;
if linelen gt 0 then do;
** have a program line and want to read it;
input @1 pgmline $varying. linelen;
end;
keep linenum pgmline linelen;
run;

title j=c "Program: c:\sas programs\prtclass.sas";
proc report data=thepgm nowd noheader missing
style(report) ={font_face='Courier New' font_size=10pt rules=none frame=void
cellspacing=0 cellpadding=2 asis=on outputwidth=100%}
style(column) ={font_face='Courier New' font_size=10pt asis=on just=l} ;
column linenum pgmline;
define linenum / order noprint;
define pgmline / display;
run;

ods rtf close;
[/pre]
N/A
Posts: 0

Re: Adding the syntax file itself at the end of ODS output

Thanks for response.
The Document solution sounds interseting. I'll certaijnly try that out. We did manage to add syntax as Data, the way Cynthia describes, a bit less stylish though.
Valued Guide
Posts: 2,175

Re: Adding the syntax file itself at the end of ODS output

nice thing about proc report for program syntax is the text flow available.
There is something similar in proc sql, but report provides more support (I think)
$varying should be fairly irrelevant these days with truncover and _infile_ so much more manageable (After all, all sas data set string variables hold trailing spaces - when not filled)
Ask a Question
Discussion stats
  • 5 replies
  • 195 views
  • 0 likes
  • 4 in conversation