SAS 基础:KEEP 语句和 KEEP = 选项

问题描述 投票:0回答:1

您好,我是 SAS 新手,我发现了 SAS 基础编程参考表。在“数据步骤:控制变量输出”部分中,框中的示例代码让我感到困惑。

示例代码是否错误?因为 KEEP 语句中的 store_name 列从未被引用过,所以 SAS 应该无法执行 KEEP 语句。

我使用以下代码测试了代码并收到错误:


DATA work.cars (KEEP = Model Type);
    SET sashelp.cars (DROP = Invoice);
    KEEP MSRP drivetrain;
RUN;

错误消息显示 “警告:从未引用过 DROP、KEEP 或 RENAME 列表中的变量 Model。 警告:从未引用过 DROP、KEEP 或 RENAME 列表中的变量 Type。”

这是否意味着示例代码是错误的?

sas
1个回答
0
投票

OUTPUT 数据集上的 KEEP= 数据集选项将应用于 DATA 步骤定义的数据集。 因此,在这种情况下,数据步骤中的 KEEP 语句意味着仅输出 MSRP 和 DRIVETRAIN 变量。 因此,在 WORK.CARS 输出数据集名称的 KEEP= 数据集选项中引用任何其他变量都会发出您看到的警告。

请注意,您可以使用 DKROCOND(对于输入数据集,DKRICOND)系统选项控制 SAS 如何处理此类事物。

示例:

1    options dkrocond=nowarn;
2    DATA work.cars (KEEP = Model Type);
3        SET sashelp.cars (DROP = Invoice);
4        KEEP MSRP drivetrain;
5    RUN;

NOTE: There were 428 observations read from the data set SASHELP.CARS.
NOTE: The data set WORK.CARS has 428 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


6    options dkrocond=error;
7    DATA work.cars (KEEP = Model Type);
8        SET sashelp.cars (DROP = Invoice);
9        KEEP MSRP drivetrain;
10   RUN;

ERROR: The variable Model in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable Type in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CARS may be incomplete.  When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.CARS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
© www.soinside.com 2019 - 2024. All rights reserved.