在 SAS 中创建汇总变量的简单方法
我正在寻找一种在 SAS 中创建汇总变量的方法,该变量将自动添加每行观察值,直到满足条件。 如有必要,我需要能够启动、停止和重置此变量。
多谢。
I am looking for an way to create a summary variable in SAS that will automatically add each row observation until a condition is met. I would need to be able to start and stop and reset this variable if necessary.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用保留!
希望这是有道理的!
Use Retain!
Hope this makes sense!
如果您要使用
OR
之类的语句,那么您实际上不需要 RETAIN 语句。
另外,如果您在 DATA STEP 中使用 BY 语句,则可以访问变量 FIRST 和 LAST(数据必须按 BY 变量排序)。 FIRST 和 LAST 的值为 1 或 0。当 BY 变量位于第一个值 FIRST 时。 = 1 并且当它位于最后一个值 LAST 时。 = 1。当只有 1 条 byVariable 记录时,它们都可以等于 1;当 byVariable 记录多于 2 条时(当在中间记录时),它们都可以等于 0。
FIRST 和 LAST 可以帮助确定何时重置 RETAINed 变量。 (FIRST和LAST将在PDV中,但不会写入输出数据集,因此不需要DROP它们)。
示例
(此示例的结果可能是通过 PROC 完成的,但我希望这演示了如何使用 FIRST 和 LAST)
If you are going to use a statement like
OR
then you don't actually need a RETAIN statement.
Also, if you use the BY statement in your DATA STEP, you have access to variables FIRST and LAST (The data must be sorted by the BY variable). FIRST and LAST either have a value of 1 or 0. When the BY variable is on the first value FIRST. = 1 and when it is on the last value LAST. = 1. They can both be equal to 1 when there is only 1 byVariable record and they can both be equal to 0 when there is more than 2 byVariable records (when on the middle records).
FIRST and LAST can help determine when to reset your RETAINed variables. (FIRST and LAST will be in the PDV, but will not be written to the output data set, so there is no need to DROP them).
Example
(The result of this example would probably be done with a PROC, but I hope this demonstrates how FIRST and LAST can be used)