【发布时间】:2019-02-05 12:26:49
【问题描述】:
假设我有以下 SAS 数据集:
Account Month Balance LastMonth MonthDate LastMonthDate
1 Jan 5 May 2012-01-01 2012-05-01
1 Feb 2 May 2012-02-01 2012-05-01
1 Mar 1 May 2012-03-01 2012-05-01
2 Feb 6 Apr 2012-02-01 2012-04-01
2 Mar 4 Apr 2012-03-01 2012-04-01
我需要创建以下内容:
Account Month Balance LastMonth MonthDate LastMonthDate
1 Jan 5 May 2012-01-01 2012-05-01
1 Feb 2 May 2012-02-01 2012-05-01
1 Mar 1 May 2012-03-01 2012-05-01
1 Apr 1 May 2012-04-01 2012-05-01
1 May 1 May 2012-05-01 2012-05-01
2 Feb 6 Apr 2012-02-01 2012-04-01
2 Mar 4 Apr 2012-03-01 2012-04-01
2 Apr 4 Apr 2012-04-01 2012-04-01
也就是说,我需要为每个帐户添加额外的行,以便每个帐户每个月都有一个条目,直到 'LastMonth' 列。对于不在原始数据集中的月份,余额必须与数据集中最后一个条目的余额保持一致。我的数据集已按“帐户”和“月份”排序。
请注意,这只是两个示例帐户,因为我的真实数据集有多个帐户,每个帐户都有不同的“LastMonth”列。我需要概括此过程,以便为每个帐户创建截至其“上个月”日期的缺失行数。
【问题讨论】:
-
是 month_date 和 lastMonth_date 字符还是日期变量?
-
@DomPazz - 它们是 SAS 日期格式 (yymmdd10.)
-
它们是存储为日期还是字符串?格式是告诉 SAS 如何显示数据的一种方式。
-
@DomPazz - 请查看编辑以获取列属性的屏幕截图 :)
-
为你更新了我的答案。