楼主: robertmou05
3289 6

[原创博文] 排序赋值 [推广有奖]

  • 0关注
  • 0粉丝

大专生

46%

还不是VIP/贵宾

-

威望
0
论坛币
76 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2851 点
帖子
23
精华
0
在线时间
43 小时
注册时间
2009-8-7
最后登录
2023-12-13

楼主
robertmou05 发表于 2012-4-19 15:05:20 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
如果有一个数据集要根据a b c三个变量排序;然后如果a b c 有相同值的赋值flag:1、2、3这样依次排序下去。形式类似如下
a b c flag
1 1 1 1
1 1 1 2
1 1 1 3
1 1 2 1
1 1 2 2
1 1 2 3
1 2 2 1
1 2 2 2
1 2 2 3

请问该如何编程?
谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:Flag Fla lag 数据集 律师

沙发
mymine 发表于 2012-4-19 15:48:04
data temp1;
input a $1. b $1. c $1.;
cards;
111
111
111
112
112
112
122
122
122
;
run;
data temp1;
set temp1;
cls=compress(a||'*'||b||'*'||C);
run;
proc sort data=temp1;
by cls;
run;
data temp1;
set temp1;
by cls;
if first.cls then flag=1;
else flag+1;
run;

藤椅
chendonghui1987 发表于 2012-4-19 16:40:14
data work.a;
        input a b c;
        datalines;
1 1 1
1 1 1
1 2 3
1 2 3
1 3 4
1 1 1
1 1 2
1 1 2
1 1 2
1 2 2
1 3 4
1 2 2
1 2 2
;
run;

proc sort data = work.a;
        by a b c;
run;

data work.b;
        set work.a;
        by a b c ;
        if first.c then do;
                flag = 1;
        end;else do;
                flag +1 ;
        end;
run;

板凳
mymine 发表于 2012-4-19 21:08:34
楼上的
if first.c 不保险
举例如数据
111
111
111
121
121
122
122
123

报纸
jingju11 发表于 2012-4-19 21:32:28
mymine 发表于 2012-4-19 21:08
楼上的
if first.c 不保险
举例如数据
他的理解是对的。利用first.x是好的选择。京剧

地板
mymine 发表于 2012-4-20 07:56:48
jingju11 发表于 2012-4-19 21:32
他的理解是对的。利用first.x是好的选择。京剧
后来想想其实 if first.a=1 or first.b=1 or first.c=1 then flag=1; 更简洁

proc sort data=temp1;
by a b c;
run;

data temp1;
set temp1;
by a b c;
if first.a=1 or first.b=1 or first.c=1 then flag=1;
else flag+1;
run;

7
jingju11 发表于 2012-4-20 22:31:50
mymine 发表于 2012-4-20 07:56
后来想想其实 if first.a=1 or first.b=1 or first.c=1 then flag=1; 更简洁

proc sort data=temp1;
unfortunately I dont think you have completely understood the usuage of first. in data step. That is not an offence.
jingju

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

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