【问题标题】:First. and Last . in sas第一的。最后一个。在sas中
【发布时间】:2015-05-31 10:22:31
【问题描述】:

我的数据表如下:

Name Amount Status
a 5000 Debit
a 2000 Credit
a 1000 Credit
b 2000 Debit
b 1000 Debit
b 1000 Credit

我希望我的输出是:

Name net_amount status
a 2000 Debit
b 2000 Debit

如何使用first.last. 变量来实现它? 提前致谢

【问题讨论】:

  • 建议您展示到目前为止您尝试过的代码。
  • 根据您编写的原始数据,不可能获得该输出(显然只有一条语句)。与第一。或者最后,您将根据指定的 by 语句输出一个原始标记为系列的第一个或最后一个(确保事先对数据集进行排序。)。输出数据集中的第一行不包含在源数据集中。请务必发布您的尝试,即使很差。
  • 你用什么逻辑来选择上面示例输出中两行的内容?除非清楚明确地说明逻辑,否则您无法确定收到的任何答案在所有情况下都会按照您的预期表现。

标签: sas


【解决方案1】:
data a;
input Name $ Amount Status $;
cards;
a 5000 Debit
a 2000 Credit
a 1000 Credit
b 2000 Debit
b 1000 Debit
b 1000 Credit
;
run;

proc sort data=a; 
by name status amount; 
run;

data by_name_first_obs by_name_and_status_first_obs
     by_name_last_obs by_name_and_status_last_obs;
set a;
by name status;
if first.name then output by_name_first_obs;
if last.name then output by_name_last_obs;
if first.status then output by_name_and_status_first_obs;
if last.status then output by_name_and_status_last_obs;
run;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多