Sas 简明教程
SAS - Data Sets
可供 SAS 程序进行分析的数据称为 SAS 数据集。它使用 DATA 步骤创建。SAS 可以读取各种文件作为其数据源,如 CSV, Excel, Access, SPSS and also raw data 。它还有许多可供使用的内置数据源。
The data that is available to a SAS program for analysis is referred as a SAS Data Set. It is created using the DATA step.SAS can read a variety of files as its data sources like CSV, Excel, Access, SPSS and also raw data. It also has many in-built data sources available for use.
-
The Data Sets are called temporary Data Set if they are used by the SAS program and then discarded after the session is run.
-
But if it is stored permanently for future use then it is called a permanent Data set. All permanent Data Sets are stored under a specific library.
SAS 数据集以行和列的形式存储,也称为 SAS 数据表。以下我们看到永久数据集的示例,它们是内置的,也可以从外部源读取。
The SAS Data set is stored in form of rows and columns and also referred as SAS Data table.Below we see the examples of permanent Data sets which are in-built as well as red from external sources.
SAS Built-In Data Sets
这些数据集已经内置在已安装的 SAS 软件中。在制定数据分析的示例表达式时,可以探索和使用它们。要探索这些数据集,请转到 Libraries → My Libraries → SASHELP 。展开它后,我们会看到所有可用的内置数据集的名称列表。
These Data Sets are already available in the installed SAS software. They can be explored and used in formulating sample expressions for data analysis. To explore these data sets go to Libraries → My Libraries → SASHELP. On expanding it we see the list of names of all the built-in Data Sets available.
让我们向下滚动找到一个名为 CARS 的数据集。双击此数据集会在右侧窗口格中将其打开,在那里我们可以进一步探索它。我们还可以使用右侧窗口格下的最大化视图按钮来最小化左侧窗口格。
Lets scroll down to locate a Data Set named CARS.Double clicking on this Data Set opens it in the right window pane where we can explore it further.We can also minimize the left pane by using the maximize view button under the right pane.
我们可以使用底部的滚动条向右滚动以浏览表格中的所有列及其值。
We can scroll to the right using the scroll bar in the bottom to explore all the columns and theirs values in the table.
Importing External Data Sets
我们可以通过使用 SAS Studio 中提供的导入功能将我们自己的文件导出为数据集。但这些文件必须放在 SAS 服务器文件夹中。因此,我们必须使用 Server Files and Folders 下的上传选项将源数据文件上传到 SAS 文件夹。
We can export our own files as Data sets by using the import feature available in SAS Studio. But these files must be available in the SAS server folders. So we have to upload the source data files to SAS folder by using the upload option under the Server Files and Folders.
接下来,我们通过导入来在 SAS 程序中使用上述文件。为此,我们使用 任务 → 工具 → 导入数据 选项,如下所示。双击导入数据按钮,将在右侧打开一个窗口,用于选择该数据集的文件。
Next we use the above file in a SAS program by importing it. To do this we use the option *Tasks → Utilities → Import data * as shown below. Double click the Import Data button which opens up the window in the right to choose the file for the Data Set.
接下来,单击右侧导入数据程序下的 Select Files 按钮。以下是可以导入的文件类型列表。
Next Click on the Select Files button under the import data program in the right pane. The following are the list of the file types which can be imported.
我们选择存储在本地系统中的 "employee.txt" 文件,并将其导入,如下所示。
We choose the "employee.txt" file stored in the local system and get the file imported as shown below.