简体   繁体   English

数一数。 来自元数据的 SAS 数据集的观察

[英]Count the no. of observations of SAS data set from metadata

code to count the no.计算编号的代码。 of observations of a data set:对数据集的观察:

data _NULL_;
 if 0 then set sashelp.cars nobs=n;
 put "no. of observations =" n;
 stop;
run;

What does if=0 means? if=0 是什么意思? how this is condition working?这是如何工作的?

zero is the intrinsic false value in SAS.零是 SAS 中的内在false值。 Therefore the Set Statement in the if 0 then set.. statement is never executed.因此if 0 then set..语句中的 Set 语句永远不会执行。 The nobs=n is set at compile time. nobs=n 在编译时设置。 Therefore, if your only goal is to find the number of observations in a SAS data set, there is no need to read any of the actual data.因此,如果您的唯一目标是查找 SAS 数据集中的观测数,则无需读取任何实际数据。

When evaluating boolean logic SAS will treat zero or missing values as FALSE and any other value as TRUE.在评估 boolean 逻辑时,SAS 会将零值或缺失值视为 FALSE,将任何其他值视为 TRUE。 So the IF 0 THEN allows you to have code that the data step compiler sees, but that never actually gets run.因此, IF 0 THEN允许您拥有数据步骤编译器看到的代码,但实际上从未运行过。 The variable created by the NOBS= option gets assigned a value before the data step starts running. NOBS= 选项创建的变量在数据步骤开始运行之前被赋值。

For this simple step you could get the same result by placing the SET statement after the STOP statement.对于这个简单的步骤,您可以通过将 SET 语句放在 STOP 语句之后来获得相同的结果。

data _null_;
  put "no. of observations =" n;
  stop;
  set sashelp.cars nobs=n;
run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM