Sas 简明教程
SAS - Write Data Sets
与读取数据集类似,SAS 可以写入不同格式的数据集。它可以将来自 SAS 文件的数据写入普通文本文件。其他软件程序可以读取这些文件。SAS 使用 PROC EXPORT 来写入数据集。
Similar to reading datasets, SAS can write datasets in different formats. It can write data from SAS files to normal text file.These files can be read by other software programs. SAS uses PROC EXPORT to write data sets.
PROC EXPORT
这是一个内置的 SAS 过程,用于导出 SAS 数据集,以便将数据写入不同格式的文件中。
It is a SAS inbuilt procedure used to export the SAS data sets for writing the data into files of different formats.
Syntax
在 SAS 中编写过程的基本语法是 −
The basic syntax for writing the procedure in SAS is −
PROC EXPORT
DATA = libref.SAS data-set (SAS data-set-options)
OUTFILE = "filename"
DBMS = identifier LABEL(REPLACE);
以下是所用参数的描述 -
Following is the description of the parameters used −
-
SAS data-set is the data set name which is being exported. SAS can share the data sets from its environment with other applications by creating files which can be read by different operating systems. It uses the inbuilt EXPORT function to out the data set files in a variety of formats. In this chapter we will see the writing of SAS data sets using proc export along with the options dlm *and *dbms.
-
SAS data-set-options is used to specify a subset of columns to be exported.
-
filename is the name of the file to which the data is written into.
-
identifier is used to mention the delimiter that will be written into the file.
-
LABEL option is used to mention the name of the variables written to the file.
Example
我们将使用 SASHELP 库中提供的名为 cars 的 SAS 数据集。使用以下程序中显示的代码,我们将其导出为空格分隔的文本文件。
We will use the SAS data set named cars available in the SASHELP library. We export it as a space delimited text file with the code as shown in the following program.
proc export data = sashelp.cars
outfile = '/folders/myfolders/sasuser.v94/TutorialsPoint/car_data.txt'
dbms = dlm;
delimiter = ' ';
run;
执行上述代码后,我们可以看到输出为文本文件,并右键单击该文件查看其内容,如下所示。
On executing the above code we can see the output as a text file and right click on it to see its content as shown below.
Writing a CSV file
为了写入逗号分隔文件,我们可以将 dlm 选项的值设为 “csv”。以下代码编写文件 car_data.csv。
In order to write a comma delimited file we can use the dlm option with a value "csv". The following code writes the file car_data.csv.
proc export data = sashelp.cars
outfile = '/folders/myfolders/sasuser.v94/TutorialsPoint/car_data.csv'
dbms = csv;
run;
执行上述代码,我们得到以下输出。
On executing the above code we get the below output.
Writing a tab delimited file
为了写入制表符分隔的文件,我们可以使用“tab”值的 dlm 选项。以下代码编写了文件 car_tab.txt.
In order to write a tab delimited file we can use the dlm option with a value "tab". The following code writes the file car_tab.txt.
proc export data = sashelp.cars
outfile = '/folders/myfolders/sasuser.v94/TutorialsPoint/car_tab.txt'
dbms = csv;
run;
数据也可以写入 HTML 文件,我们将在输出交付系统章节中对此进行介绍。
Data can also be written as HTML file which we will see under the output delivery system chapter.