The DOCUMENT Procedure

Example 7: Importing LISTING Output and a SAS Program

Features:

PROC DOCUMENT statement option: NAME=

IMPORT statement option: TEXTFILE=

LIST statement

REPLAY statement

Procedure output :
PROC DOCUMENT
PROC GLM
ODS destinations: DOCUMENT

HTML

LISTING

Details

The following example uses the IMPORT TO statement to import two files into an ODS document. The first file contains LISTING output, and the second file contains a SAS program. The files are imported into an ODS document and then replayed to a PDF document. In this example, the SAS program that is imported is the entire example itself, which was saved as textfileExample.sas. Before you run this example, please save it as textfileExample.sas.

Program

options nodate nostimer LS=80 PS=60;

title1 'Importing a SAS Program and LISTING Output';
data one;
  do month = 1 to 12;
    age  = 2 + 0.3*rannor(345467);
    age2 = 3 + 0.3*rannor(345467);
    age3 = 4 + 0.4*rannor(345467);
    output;
    end;
run;

ods listing file="your-file-path/odsglm.lst";
   
proc glm;
  class month;
  model age age2 age3=month / nouni; manova h=month /printe;
run;
quit;

data plants;
   input type $ @;
   do block=1 to 3;
      input stemleng @;
      output;
      end;
datalines;
   clarion  32.7 32.3 31.5
   clinton  32.1 29.7 29.1
   knox     35.7 35.9 33.1
   o'neill  36.0 34.2 31.2
   compost  31.8 28.0 29.2
   wabash   38.2 37.8 31.9
   webster  32.5 31.1 29.7
;
proc glm order=data;
   class type block;
   model stemleng=type block;
   means type;
   contrast 'compost vs others'  type -1 -1 -1 -1  6 -1 -1;
   contrast 'river soils vs.non' type -1 -1 -1 -1  0  5 -1,
                                 type -1  4 -1 -1  0  0 -1;
   contrast 'glacial vs drift'   type -1  0  1  1  0  0 -1;
   contrast 'clarion vs webster' type -1  0  0  0  0  0  1;
   contrast 'knox vs oneill'     type  0  0  1 -1  0  0  0;
quit;
ods listing close;
ods listing;   

proc document name=import(write);
   import textfile="your-file-path\odsglm.lst" to ^;
   import textfile="your-file-path\textfileExample.sas" to ^;
   list/details; 
run;
ods pdf file="out.pdf";
   replay;
run;
quit;
ods pdf close;

Program Description

Set the SAS system options and add a title. The OPTIONS statement specifies the SAS system options and the TITLE statement specifies a title.
options nodate nostimer LS=80 PS=60;

title1 'Importing a SAS Program and LISTING Output';
Create the ONE data set.
data one;
  do month = 1 to 12;
    age  = 2 + 0.3*rannor(345467);
    age2 = 3 + 0.3*rannor(345467);
    age3 = 4 + 0.4*rannor(345467);
    output;
    end;
run;

Create the listing file to be imported. The ODS LISTING statement creates the file Odsglm.lst, which contains the LISTING output.
ods listing file="your-file-path/odsglm.lst";
   
Run the GLM procedure.
proc glm;
  class month;
  model age age2 age3=month / nouni; manova h=month /printe;
run;
quit;

Create the Plants data set.
data plants;
   input type $ @;
   do block=1 to 3;
      input stemleng @;
      output;
      end;
datalines;
   clarion  32.7 32.3 31.5
   clinton  32.1 29.7 29.1
   knox     35.7 35.9 33.1
   o'neill  36.0 34.2 31.2
   compost  31.8 28.0 29.2
   wabash   38.2 37.8 31.9
   webster  32.5 31.1 29.7
;
Run the GLM procedure.
proc glm order=data;
   class type block;
   model stemleng=type block;
   means type;
   contrast 'compost vs others'  type -1 -1 -1 -1  6 -1 -1;
   contrast 'river soils vs.non' type -1 -1 -1 -1  0  5 -1,
                                 type -1  4 -1 -1  0  0 -1;
   contrast 'glacial vs drift'   type -1  0  1  1  0  0 -1;
   contrast 'clarion vs webster' type -1  0  0  0  0  0  1;
   contrast 'knox vs oneill'     type  0  0  1 -1  0  0  0;
quit;
ods listing close;
Run the DOCUMENT procedure.The PROC DOCUMENT statement names the document “Import” and opens it for Write access. The first IMPORT TO statement with the TEXTFILE= option specified statement imports the file Odsglm.lst to the ODS document in the current directory. The second IMPORT TO statement with the TEXTFILE= option specified statement imports the file textfileExample.sas to the ODS document in the current directory.
ods listing;   

proc document name=import(write);
   import textfile="your-file-path\odsglm.lst" to ^;
   import textfile="your-file-path\textfileExample.sas" to ^;
   list/details; 
run;
Replay the document to a PDF file. The REPLAY statement replays the document to the PDF file Out.pdf.
ods pdf file="out.pdf";
   replay;
run;
Terminate the DOCUMENT procedure and close the PDF destination. Specify the QUIT statement to terminate the DOCUMENT procedure. If you omit QUIT, then you will not be able to view DOCUMENT procedure output. The ODS PDF CLOSE statement closes the PDF destination.
quit;
ods pdf close;

Output

Imported LISTING Output
Imported LISTING Output
Imported SAS Program
Imported SAS Program