Sas 简明教程

SAS - ODS

SAS 程序的输出可以转换为用户更友好的形式,例如 .htmlPDF. 这是通过使用 SAS 中提供的 ODS 语句来完成的。ODS 代表 output delivery system. 它主要用于将 SAS 程序的输出数据格式化为美观的报告,这些报告易于查看和理解。这也帮助与其他平台和软件共享输出。它还可以将多个 PROC 语句的结果组合到一个文件中。

The output from a SAS program can be converted to more user friendly forms like .html or PDF. This is done by using the ODS statement available in SAS. ODS stands for output delivery system. It is mostly used to format the output data of a SAS program to nice reports which are good to look at and understand. That also helps sharing the output with other platforms and soft wares. It can also combine the results from multiple PROC statements in one single file.

Syntax

在 SAS 中使用 ODS 语句的基本语法是 −

The basic syntax for using the ODS statement in SAS is −

ODS outputtype
PATH path name
FILE = Filename and Path
STYLE = StyleName
;
PROC some proc
;
ODS outputtype CLOSE;

以下是所用参数的描述 -

Following is the description of the parameters used −

  1. PATH represents the statement used in case of HTML output. In other types of output we include the path in the filename.

  2. Style represents one of the in-built styles available in the SAS environment.

Creating HTML Output

我们使用 ODS HTML 语句创建 HTML 输出。在下面的示例中,我们在所需的路径中创建了一个 HTML 文件。我们应用样式库中可用的样式。我们可以看到指定路径中的输出文件,也可以下载此文件并将其保存在与 SAS 环境不同的环境中。请注意,我们有两个 proc SQL 语句,并且它们的输出都将被捕捉到一个文件中。

We create HTML output using the ODS HTML statement.In the below example we create a html file in our desired path. We apply a style available in the styles library. We can see the output file in the mentioned path and we can download it to save in an environment different from the SAS environment. Please note that we have two proc SQL statements and both their output is captured into a single file.

ODS HTML
   PATH = '/folders/myfolders/sasuser.v94/TutorialsPoint/'
   FILE = 'CARS2.html'
   STYLE = EGDefault;
proc SQL;
select make, model, invoice
from sashelp.cars
where make in ('Audi','BMW')
and type = 'Sports'
;
quit;

proc SQL;
select make,mean(horsepower)as meanhp
from sashelp.cars
where make in ('Audi','BMW')
group by make;
quit;

ODS HTML CLOSE;

在执行以上代码之后,我们将得到以下结果:

When the above code is executed we get the following result −

ods html output

Creating PDF Output

在下面的示例中,我们在所需的路径中创建了一个 PDF 文件。我们应用样式库中可用的样式。我们可以看到指定路径中的输出文件,也可以下载此文件并将其保存在与 SAS 环境不同的环境中。请注意,我们有两个 proc SQL 语句,并且它们的输出都将被捕捉到一个文件中。

In the below example we create a PDF file in our desired path. We apply a style available in the styles library. We can see the output file in the mentioned path and we can download it to save in an environment different from the SAS environment. Please note that we have two proc SQL statements and both their output is captured into a single file.

ODS PDF
   FILE = '/folders/myfolders/sasuser.v94/TutorialsPoint/CARS2.pdf'
   STYLE = EGDefault;
proc SQL;
select make, model, invoice
from sashelp.cars
where make in ('Audi','BMW')
and type = 'Sports'
;
quit;

proc SQL;
select make,mean(horsepower)as meanhp
from sashelp.cars
where make in ('Audi','BMW')
group by make;
quit;

ODS PDF CLOSE;

在执行以上代码之后,我们将得到以下结果:

When the above code is executed we get the following result −

ods pdf output

Creating TRF(Word) Output

在下面的示例中,我们在所需的路径中创建了一个 RTF 文件。我们应用样式库中可用的样式。我们可以看到指定路径中的输出文件,也可以下载此文件并将其保存在与 SAS 环境不同的环境中。请注意,我们有两个 proc SQL 语句,并且它们的输出都将被捕捉到一个文件中。

In the below example we create a RTF file in our desired path. We apply a style available in the styles library. We can see the output file in the mentioned path and we can download it to save in an environment different from the SAS environment. Please note that we have two proc SQL statements and both their output is captured into a single file.

ODS RTF
FILE = '/folders/myfolders/sasuser.v94/TutorialsPoint/CARS.rtf'
STYLE = EGDefault;
proc SQL;
select make, model, invoice
from sashelp.cars
where make in ('Audi','BMW')
and type = 'Sports'
;
quit;

proc SQL;
select make,mean(horsepower)as meanhp
from sashelp.cars
where make in ('Audi','BMW')
group by make;
quit;

ODS rtf CLOSE;

在执行以上代码之后,我们将得到以下结果:

When the above code is executed we get the following result −

ods rtf output