推 Suertue:感謝^^ 03/19 14:15
※ 引述《Suertue (Suertue)》之銘言:
: 請問熟悉SAS的大大們~~
: 要怎麼在一群已排序過的數值中,界定最大值與次大值
: (我是SAS超級新手>”<)
: 像原本資料是這樣:
: company money X Y
: 1101 10800000 1 0
: 1101 7500000 0 1
: 1101 7100000 0 0
: 1101 5680000 0 0
: 1101 3880400 0 0
: 1102 20000000 1 0
: 1102 1999342 0 1
: 1102 999205 0 0
: 1102 998493 0 0
: 1102 810000 0 0
: X就是在各個company中,money值最高的,X就是1,其他0
: money值次高的,Y就等於1,其他0
: 我想應該有BY company吧…
: 想請問各位高手們,能不能教教我該怎麼寫
: 因為我的資料有十萬多筆 慢慢調整XY的話眼睛會脫窗
: 感激不盡...
data newdata;
set yourdata;
by company;
if first.company then temp=0;
retain temp;
temp=temp+1;
if temp=1 then x=1; else x=0;
if temp=2 then y=1; else y=0;
drop temp;
run;
這是在money已經排序過後的寫法
如果沒排序過 又希望資料回復原先的排列
可能要再多做一個中間的變數來做sort的動作
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.202.140
※ 編輯: MmmRrrrX 來自: 140.119.202.140 (03/19 01:45)