z***9 发帖数: 1052 | 1 I have a practical SAS question. There are many solutions, but I am looking
for the best way to do it.
I have a character variable, ID, which has a lot of values and each value
has a lot of rows, for example, a,a,a,a,..b,b,b,b...c,c,c,c,c....... I want
assign a sequential number to each value, so all a will equal to 1, all b
will equal to 2.
I don't want to do a "if then" because there are too many values, what will
be the best way you can think of? | a*****3 发帖数: 601 | 2 上回我看见ooloo(还是精算?)用monotonic function , 每个group前面加个序号。 a
b c d就变成了 1 2 3 4.
可惜我学艺不精 细节都忘了. | l******n 发帖数: 9344 | 3 select distinct ID and create a value map, map the value back to ID
looking
want
will
【在 z***9 的大作中提到】 : I have a practical SAS question. There are many solutions, but I am looking : for the best way to do it. : I have a character variable, ID, which has a lot of values and each value : has a lot of rows, for example, a,a,a,a,..b,b,b,b...c,c,c,c,c....... I want : assign a sequential number to each value, so all a will equal to 1, all b : will equal to 2. : I don't want to do a "if then" because there are too many values, what will : be the best way you can think of?
| k*******a 发帖数: 772 | 4 order by ID
then by ID, if first.id then group+1 | d******9 发帖数: 404 | 5 Try to use proc format--- invalue. | a*****3 发帖数: 601 | 6 人家变量太多, 不愿意手写 - 所以没法用 format
【在 d******9 的大作中提到】 : Try to use proc format--- invalue.
| a*****3 发帖数: 601 | 7 方法不错 , 但听说monotonic最近比较流行.
【在 k*******a 的大作中提到】 : order by ID : then by ID, if first.id then group+1
| z***9 发帖数: 1052 | 8 this is the same method I can think of, I believe there might be better ways
to do, that's why I post the question here.
【在 l******n 的大作中提到】 : select distinct ID and create a value map, map the value back to ID : : looking : want : will
|
| z***9 发帖数: 1052 | 9 it works. i think this is probably the easiest one. thanks a lot.
【在 k*******a 的大作中提到】 : order by ID : then by ID, if first.id then group+1
| g****8 发帖数: 2828 | 10 恩,如果,比code长短,这个方法应该是最优的
【在 z***9 的大作中提到】 : it works. i think this is probably the easiest one. thanks a lot.
| l******n 发帖数: 9344 | 11 efficiency?
monitonic那个感觉会比较慢,如果data多
【在 g****8 的大作中提到】 : 恩,如果,比code长短,这个方法应该是最优的
| p***r 发帖数: 920 | 12 try this code:
DATA FMT; SET LIBFMT.'DATASET$'N END=LAST;
RETAIN FMTNAME '$(FORMATNAME)' /**/'(FORMATNAME)' ;
START=;LABEL=;OUTPUT;
IF LAST THEN DO;
HLO='O'; LABEL='ZZ:UNIDENTIFIED';OUTPUT;
END;
KEEP FMTNAME START LABEL HLO;
RUN;
PROC FORMAT CNTLIN=FMT;RUN; |
|