十一月 12, 2008 · 统计计算

在说明fist.和last.变量之前,先介绍几个定义:

  • by-group processing,by分组方法:即用by 语句把观测按一个或多个变量进行分组和排序的方法,在数据步中应用最普遍。

  • by variable,by变量:即by variables中,指定的用于分组或排序变量;指定合并数据集时的依据变量。

  • by value,by变量值: 即 by variable的值

  • by group,by组:即具有相同by值的观测

  • first.和last.:SAS为每个by variable定义的变量。每个by变量定义了2个临时变量,用于识别每个by group的开始和结束。first.变量和last.变量不输出到数据集中。两个临时变量的值用于判断一个observation是否是:by group第一个值、或最后一个值、或两者都不是、或两者都是。SAS赋值原理:如果观测位于by group的首位,first.=1,last.=0,同理,位于尾部的first.=0,last.=1,其它观测的first.=0和last.=0。

  /**************************************************
  由于自动变量first.group and last.group不保存到数据
  集中,所以本例写入到数据集以显示其值。
  **************************************************/
  data new;
  set temp;
  by group;
  first=first.group;
  last=last.group;
  run;
  proc print;
  title 'Raw data along with first.group and last.group';
  run;


原来在使用by statement后,SAS系统自动生成first.和last.变量,用于识别观测分组后位于本组首位和尾部的观测。

本文代码取自:http://www.pauldickman.com/teaching/sas/set_by.php

标签:,

Rand Posts:

相关日志

Tags: ,
Written by agri520


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

苏ICP备08103697号
Agri521'Blog is prowdly powered by Wordpress · © 2009 · All rights reserved.
OrangeJuice theme by Theme Museum. 登录