2571 3

[请教高手]如何按照不同的类别给变量标上序号 [推广有奖]

  • 0关注
  • 1粉丝

高中生

0%

还不是VIP/贵宾

-

威望
0
论坛币
23 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
197 点
帖子
23
精华
0
在线时间
4 小时
注册时间
2009-2-9
最后登录
2013-5-25

楼主
一个凯蒂0106 发表于 2009-3-27 15:54:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

请教大侠们,弱问,如何按照不同的类别给变量标上序号?

比如原来的数据集为:

year month

1998 9

1998 9

1998 10

1998 10

1999 5

1999 5

1999 5

1999 6

1999 6

想按照年份和月份给这些变量标上序号。即年份和月份相同的观测值的序号相同。目标数据集为:

year month id

1998 9 1

1998 9 1

1998 10 2

1998 10 2

1999 5 3

1999 5 3

1999 5 3

1999 6 4

1999 6 4

感觉上应该不是个很难的问题,但是本人真的不会,恳请大家帮忙,非常感谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:请教高手 month mont year 非常感谢 变量 高手 类别 序号

回帖推荐

xuwei2007 发表于3楼  查看完整内容

data ym;   input year moth @@;   cards;1998 91998 91998 101998 101999 51999 51999 5 1999 6 1999 6;proc sort data=ym;   by year month;   run;data want;  set ym;  by year month;  retain id o;  if  first.month  then do;  id+1;  end;run; [此贴子已经被作者于2009-3-27 18:59:58编辑过]

sushe1527 发表于2楼  查看完整内容

data raw;input year month;cards;1998 91998 91998 101998 101999 51999 51999 5 1999 6 1999 6;run;proc sort data=raw;by year month;run;data a;set raw;by year month;retain id;if  first.month then id=1;else id+1;run; data result;   set a;   retain type 0;   if id=1 then do;     type+1;  end;  else;  drop id;  rename type=id;run;

本帖被以下文库推荐

沙发
sushe1527 发表于 2009-3-27 18:49:00

data raw;
input year month;
cards;
1998 9
1998 9
1998 10
1998 10
1999 5
1999 5
1999 5
1999 6
1999 6
;
run;
proc sort data=raw;
by year month;
run;


data a;
set raw;
by year month;
retain id;
if  first.month then id=1;
else id+1;
run;

data result;
   set a;
   retain type 0;
   if id=1 then do;
     type+1;
  end;
  else;
  drop id;
  rename type=id;
run;

已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

藤椅
xuwei2007 发表于 2009-3-27 18:53:00
data ym;
   input year moth @@;
   cards;
1998 9
1998 9
1998 10
1998 10
1999 5
1999 5
1999 5
1999 6
1999 6
;
proc sort data=ym;
   by year month;
   run;
data want;
  set ym;
  by year month;
  retain id o;
  if  first.month  then do;
  id+1;
  end;
run;

[此贴子已经被作者于2009-3-27 18:59:58编辑过]

已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

板凳
一个凯蒂0106 发表于 2009-3-27 23:21:00

谢谢楼上的两位,我试了下,两种方法都可以!!

学习了!

谢谢!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 03:11