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]