【问题标题】:Data concatenation in SPSSSPSS中的数据连接
【发布时间】:2014-10-08 15:24:43
【问题描述】:

我在 SPSS 中有两个数据列

hhid = 1 2 3

carid = 26 27 28

我想创建一个连接 hhid 和 carid 的新列并给我一个输出

Newid = 1_26 2_27 3_28

我是 SPSS 新手,感谢您的帮助。

【问题讨论】:

    标签: spss


    【解决方案1】:

    以下代码假定您的 id 变量是数字的。否则,只需从 COMPUTE 命令中删除 STRING 函数即可。

    * generate a string variable of 17 characters. Adjust length as you wish.
    STRING Newid (A17).
    COMPUTE Newid = CONCAT(LTRIM(STRING(hhid,F8)), "_", LTRIM(STRING(carid,F8))).
    EXECUTE.
    

    解释:STRING(var,format) 函数将“var”的数值转换为给定格式的字符串。在上面的代码中,格式是一个没有任何小数的 8 位数字。此函数的输出是一个带有前导空格的 8 个字符长的字符串。为了删除前导空格,这个函数被包裹在LTRIM(string)函数中。

    【讨论】:

    • @user3637176 如果您找到正确且有用的答案,请考虑将其标记为“已接受的答案”。这将帮助其他用户将其识别为有用的答案。
    【解决方案2】:

    在 SPSS Modeler 中,您可以将派生节点附加到流中以创建新变量,即。你的连接变量。当您双击打开派生节点时,您可以输入自己的语法,即。

        hhid><"_"><cardid 
    

    you can click on the expression builder to help you through this. I've put a red circle around the expression builder in the image from this link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      相关资源
      最近更新 更多