如何使用 SPSS 查找所有变量的最大值和最小值并显示在 table 中?

How to find max&min of all variables with SPSS and display in table?

我有一个 table,其中包含大约 500 个变量和 2000 个案例。这些变量的类型各不相同。我的主管要求我生成一个 table 列表,列出所有数字变量,以及它们的最大值和最小值。我应该使用 SPSS,因为 R 显然弄乱了值标签。

在此之前,我只在 SPSS 中做过一些非常基本的事情,比如查找单个变量的统计数据,但我不确定如何做。我想我应该做类似的事情:

*Create new table*
DATASET DECLARE maxAndMin.
*Loop through all variables: Use conditional statement to identify numeric variables*
DO REPEAT R=var1 TO varN.
FREQUENCIES VARIABLES /STATISTICS=MINIMUM
END REPEAT
*Find max and minimum*

虽然我不确定该怎么做。如有任何建议,我们将不胜感激。

下面的代码将首先列出数据集中的所有数值变量(并将其存储在一个名为 !nums 的宏中),然后 运行 对这些变量进行分析以告知你是每项的平均值、最大值和最小值:

SPSSINC SELECT VARIABLES MACRONAME="!nums" /PROPERTIES TYPE= NUMERIC.
DESCRIPTIVES !nums /STATISTICS=MEAN MIN MAX.

您可以使用以下代码创建一个小型数据集来测试上面的代码:

data list list/n1 (f1) t1(a1) n2(f1) t2(a1).
begin data
1 "a" 34 "b"
2 "a" 23 "b"
3 "a" 52 "b"
4 "a" 71 "b"
end data.

如果 SUMMARIZE 为您生成足够好的 table,这里是 "non-extension" 的实现方式。

file handle mydata /name="<whatever/wherever>".

data list free /x (f1) y (a5) z (F4.2).
begin data.
1 yes 45.67
2 no 32.00
3 maybe .
4 yes 22.02
5 no 12.79
end data.

oms select tables
 /destination format=sav outfile=mydata
 /if subtypes="Descriptive Statistics" /tag="x".
des var all.
omsend tag="x".

get file mydata.
summarize Var1 Mean Minimum Maximum /format list nocasenum nototal
 /cells none /statistics none /title "Numeric Variables Only".

或者如果您不需要磁盘上的文件,则使用 DATASET 命令代替文件句柄。