运行中文转换拼音的宏,程序出现warning:没有解析符号引用 NBSP。
怎么解决,程序如下:
(程序原帖https://bbs.pinggu.org/thread-2921875-2-1.html)
/*2. 提取拼音 a.death1302 */
%macro TransHanziToPinyinForTable(SourceTable,TargetTable,InputVar,OutputVar,delimiter);
/**********************************************************************/
/* 此宏用于将指定变量中的汉字转换为对应的拼音。其中,SourceTable是原 */
/* 始表格;TargetTable是结果表格;InputVar是需要转换的目标变量,仅能 */
/* 设置一个,可包含除汉字外的英文字母、数字和其他字符;OutputVar是转 */
/* 换得到的结果变量;Delimiter是用来分隔拼音的分隔符,若不需要分隔可 */
/* 设为空。注意,Delimiter的设置如下,注意需要加引号: */
/* 逗号分隔 delimiter = ',' */
/* 空隔分隔 delimiter = ' ' */
/* 下划线分隔 delimiter = '_' */
/* */
/* 最终指定变量中的汉字转换为对应的拼音,并保存至结果表格中。 */
/* */
/* Created on 2014.2.27 */
/* Modified on 2014.2.27 */
/**********************************************************************/
/* 第一步:导入汉字拼音对照表 */
proc import datafile="E:\work\cohort\GB2312汉字拼音对照表(6727字).txt"
out=RHTPFT_HanziToPinyin
dbms=dlm
replace;
guessingrows=2000;
delimiter=' ';
getnames=No;
run;
data RHTPFT_HanziToPinyin;
set RHTPFT_HanziToPinyin;
rename VAR1=RHTPFT_Hanzi;
rename VAR2=RHTPFT_Pinyin;
drop VAR3 VAR4 VAR5;
run;
/* 第二步:得到输入变量的长度,由此计算出输出变量的长度 */
proc contents data=&SourceTable out=RHTPFT_VarList noprint;
run;
proc sql noprint;
select LENGTH*5 into :RHTPFT_LengthOfInputVar
from RHTPFT_VarList
where UPCASE(NAME) EQ %UPCASE("&InputVar");
quit;
/* 第三步:将汉字文件名转为拼音 */
data &TargetTable(drop=RHTPFT_Hanzi RHTPFT_Pinyin RHTPFT_i);
length RHTPFT_Hanzi 2RHTPFTPinyin2 RHTPFT_Pinyin 6;
if _N_ EQ 1 then do;
declare hash h(dataset: 'RHTPFT_HanziToPinyin');
h.defineKey('RHTPFT_Hanzi');
h.defineData('RHTPFT_Pinyin');
h.defineDone();
end;
set &SourceTable;
length &OutputVar $&RHTPFT_LengthOfInputVar..;
do RHTPFT_i=1 to KLENGTH(&InputVar);
RHTPFT_Hanzi=KSUBSTR(&InputVar,RHTPFT_i,1);
%if &Delimiter EQ %STR() %then %do;
if h.find() EQ 0 then &OutputVar.=CATS(&OutputVar,RHTPFT_Pinyin);
else &OutputVar.=CATS(&OutputVar,RHTPFT_Hanzi);
%end;
%else %do;
if h.find() EQ 0 then &OutputVar.=CATX(&Delimiter,&OutputVar,RHTPFT_Pinyin);
else &OutputVar.=CATS(&OutputVar,RHTPFT_Hanzi);
%end;
end;
run;
/* 删除不必要的表格 */
proc datasets lib=work nolist;
delete RHTPFT_:;
quit;
%mend;
%macro Demo();
%let SourceTable=a.death1301a;
%let TargetTable=a.death1302;
%let InputVar=patientname01;
%let OutputVar=Pinyin;
%let Delimiter=' ';
%TransHanziToPinyinForTable(&SourceTable,&TargetTable,&InputVar,&OutputVar,&Delimiter);
%mend;
/*提取拼音宏的运行*/
data _null_;
set RHTPFT_HanziToPinyin;
call symputx(RHTPFT_Hanzi,RHTPFT_Pinyin);
run;
proc sql noprint;
select distinct RHTPFT_Hanzi into :hcl separated by "|" from RHTPFT_HanziToPinyin;
quit;
options noquotelenmax;
data a.death1302;
set a.death1301a;
pinyin=resolve(prxchange("s/(&hcl)/&\1./",-1,patientname01));
run;