首页 > 解决方案 > 如何为每个新列值连续添加常量值?

问题描述

我的数据如下所示:

number    letter
1          a
1          b
1          c
2          d
2          e
3          f
3          g
3          h
3          i

我想在“数字”字段中的每个新值处插入 3 个新行(x、y、z),使其看起来像这样:

number    letter
1          a
1          b
1          c
1          x
1          y
1          z
2          d
2          e
2          x
2          y
2          z
3          f
3          g
3          h
3          i
3          x
3          y
3          z

帮助?

标签: sqlexcelsas

解决方案


在 SAS 中,您可以在数据步骤中添加一些 OUTPUT 语句。

data want ;
  set have ;
  by number;
  output;
  if last.number then do letter='x','y','z';
    output;
  end;
run;

推荐阅读