l*******s 发帖数: 437 | 1 我感觉这个问题不难,却不知道怎么做。
问题:有500个孩子,每个孩子可能有1,2或多于2个代理人,我要给孩子编号,从001编
到500,代理人有相应的编号,00101,00102,......50001,50002.
谢谢! | h********o 发帖数: 103 | 2 Try this:
=================================
DATA TEST;
INPUT CHILD $ REPRE $ @@;
CARDS;
A AAA A CCC B BBB
B CCC B DDD C AAA
C DDD C EEE C FFF
;
PROC SORT DATA = TEST OUT = CHILD (KEEP = CHILD) NODUPKEY;
BY CHILD;
RUN;
PROC SORT DATA = TEST OUT = REPRE (KEEP = REPRE) NODUPKEY;
BY REPRE;
RUN;
DATA CHILD (DROP = INDEX);
SET CHILD;
INDEX + 1;
CHILD_INDEX = PUT(INDEX, Z3.);
RUN;
DATA REPRE (DROP = INDEX);
SET REPRE;
INDEX + 1;
REPRE_INDEX = PUT(INDEX, Z5.);
RUN;
PROC SQL;
CREATE TABLE FINAL AS
SELECT A.CHILD, A.REPRE, CHILD_INDEX, REPRE_INDEX
FROM TEST AS A LEFT JOIN CHILD AS B ON A.CHILD = B.CHILD
LEFT JOIN REPRE AS C ON A.REPRE = C.REPRE
ORDER BY A.CHILD, A.REPRE;
QUIT;
======================================================
CHILD_ REPRE_
CHILD REPRE INDEX INDEX
A AAA 001 00001
A CCC 001 00003
B BBB 002 00002
B CCC 002 00003
B DDD 002 00004
C AAA 003 00001
C DDD 003 00004
C EEE 003 00005
C FFF 003 00006 | a****g 发帖数: 8131 | 3 child guardian
1 1
1 2
2 1
...
500
then convert them to character variable
do a series of string manipulation to achieve your goal
【在 l*******s 的大作中提到】 : 我感觉这个问题不难,却不知道怎么做。 : 问题:有500个孩子,每个孩子可能有1,2或多于2个代理人,我要给孩子编号,从001编 : 到500,代理人有相应的编号,00101,00102,......50001,50002. : 谢谢!
| l*******s 发帖数: 437 | 4 thank you very much!!!
lemonades,您好:
您转给 honglajiao,现金(伪币):20,收取手续费:0.2
同时附加了如下留言给 honglajiao.
thanks
【在 h********o 的大作中提到】 : Try this: : ================================= : DATA TEST; : INPUT CHILD $ REPRE $ @@; : CARDS; : A AAA A CCC B BBB : B CCC B DDD C AAA : C DDD C EEE C FFF : ; : PROC SORT DATA = TEST OUT = CHILD (KEEP = CHILD) NODUPKEY;
| j******o 发帖数: 127 | 5 孩子的代理有重复,你怎么编号?假如没有重复,可以试试下面:
data have;
input Child $ Guardian $;
datalines;
John David
John Mary
Ling Wang
Ling Peng
Ling Kevin
Lew Mike
;;
run;
proc sort data=have;
by child;
run;
data obtain(drop=G_number);
set have;
by child;
retain child_id;
if first.child then do;
child_id+1;
G_number=0;
end;
G_number +1;
Guardian_id=child_id*100+G_number;
format child_id z3. Guardian_id z5.;
run; |
|