How can I check the measure (nominal/ordinal/scale) of a variable using syntax?

一世执手 提交于 2019-12-11 02:18:58

问题


I would like to find the measure of a variable using syntax and then use this in an If-statement. Is this possible using syntax?

For example, if I have two variables a (nominal) and b (ordinal):

DO IF (a is nominal?)
...
END IF

回答1:


You can create a list of all the nominal variables in your data. In the following example the list will be stored under the macro call !noms:

SPSSINC SELECT VARIABLES MACRONAME="!noms" /PROPERTIES LEVEL=NOMINAL.
* now, for example you can run frequencies on all nominal variables.
freq !noms.

If you want to transform all the nominal variables you can use do repeat. For example:

do repeat NomVrs=!noms.
recode NomVrs ("cat2"="persian").
end repeat.

If you want to test only one specific variable (in this example called AmInominal), you can use a macro this way:

define DoIfNom ()
    !do !vr !in (!eval(!noms))
        !if (!vr="AmInominal") !then
               variable label AmInominal "this variable is indeed nominal".
               recode AmInominal ("cat2"="persian").
               frequencies AmInominal.
        !ifend
    !doend
!enddefine.

DoIfNom.


来源:https://stackoverflow.com/questions/51033797/how-can-i-check-the-measure-nominal-ordinal-scale-of-a-variable-using-syntax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!