我的评估数据在特定基本项目下方和指定上限项目之后缺少数据。我尝试为基础项目下方的所有缺失数据填写值 1,并为上限项目之后的所有缺失数据填写值 0。数据如下:
您可以循环项目(例如使用
do repeat
)并将项目名称与 Basal 和 Ceiling 变量中的文本进行比较,但这里有一个更优雅的方法(无论如何),使用重组:
* turning the item numbers into real numbers.
if basal<>"" basalN=number(char.substr(basal,5),F2).
if ceiling<>"" ceilingN=number(char.substr(ceiling,5),F2).
* creating an id for later use in restructure.
compute id=$casenum.
* now we restructure to long format so we have the items in a column instead of a row, and a string index with item name.
varstocases make val from item1 to item10/index=item(val)/null=keep.
* now we can complete the missing items as requested.
if missing(val) and number(char.substr(item,5),F2)<basalN val=1.
if missing(val) and number(char.substr(item,5),F2)>ceilingN val=0.
* now we've completed the operation we can restructure to original form.
casestovars id=id/index=item/fix=basal ceiling basalN ceilingN/sep="".