sas:中文转化为拼音首字母

%MACRO CharToPY(CharName);/*获得一个汉字的拼音第一个字母*/
OPTIONS SOURCE=0 NOTES=0;
DATA _NULL_;
TransToHex=put("&CharName",$HEX4.);
CALL SYMPUT('HexCode',TransToHex);
RUN;
%LET Now=0x&HexCode;
%GLOBAL Out;
%IF ( &Now < 0xB0A1) %THEN %LET Out=&CharName;
%ELSE %IF ( &Now < 0xB0C5) %THEN %LET Out=A;
%ELSE %IF ( &Now < 0xB2C1) %THEN %LET Out=B;
%ELSE %IF ( &Now < 0xB4EE) %THEN %LET Out=C;
%ELSE %IF ( &Now < 0xB6EA) %THEN %LET Out=D;
%ELSE %IF ( &Now < 0xB7A2) %THEN %LET Out=E;
%ELSE %IF ( &Now < 0xB8C1) %THEN %LET Out=F;
%ELSE %IF ( &Now < 0xB9FE) %THEN %LET Out=G;
%ELSE %IF ( &Now < 0xBBF7) %THEN %LET Out=H;
%ELSE %IF ( &Now < 0xBFA6) %THEN %LET Out=J;
%ELSE %IF ( &Now < 0xC0AC) %THEN %LET Out=K;
%ELSE %IF ( &Now < 0xC2E8) %THEN %LET Out=L;
%ELSE %IF ( &Now < 0xC4C3) %THEN %LET Out=M;
%ELSE %IF ( &Now < 0xC5B6) %THEN %LET Out=N;
%ELSE %IF ( &Now < 0xC5BE) %THEN %LET Out=O;
%ELSE %IF ( &Now < 0xC6DA) %THEN %LET Out=P;
%ELSE %IF ( &Now < 0xC8BB) %THEN %LET Out=Q;
%ELSE %IF ( &Now < 0xC8F6) %THEN %LET Out=R;
%ELSE %IF ( &Now < 0xCBFA) %THEN %LET Out=S;
%ELSE %IF ( &Now < 0xCDDA) %THEN %LET Out=T;
%ELSE %IF ( &Now < 0xCEF4) %THEN %LET Out=W;
%ELSE %IF ( &Now < 0xD1B9) %THEN %LET Out=X;
%ELSE %IF ( &Now < 0xD4D1) %THEN %LET Out=Y;
%ELSE %IF ( &Now < 0xD7FA) %THEN %LET Out=Z;

%put &out;
%MEND;

/*%CharToPY(张);*/

%MACRO GetPY(Chinese);/*获得每个汉字的拼音第一个字母*/
%GLOBAL PY Out;%LET PY=;%LET Out=;
%IF (%str(&Chinese) NE %STR()) %THEN %DO;
%LET C=%SYSFUNC(COMPRESS(&Chinese));
%LET LEN=%LENGTH(&C);
%LET MAX_P=%EVAL(&LEN/2);
%DO I=1 %TO &MAX_P;
%LET POS=%EVAL(&I*2-1);
%LET NOW=%SUBSTR(&C,&POS,2);
%CharToPY(CharName=&NOW);
%LET PY=%SYSFUNC(COMPRESS(&PY &Out));
%END;
%END;
%put &py;
%MEND;
/*%GetPY(南京医科大学卫生统计张汝阳);*/

posted @ 2017-04-01 11:06  Anni爱摩天轮  阅读(876)  评论(0编辑  收藏  举报