if sex=1 then set two(rename=(symptom=sym));
if sex=0 then set three(rename=(symptom=sym));
*根据sex=0或1把symptom重命名后,拼接进去;
do i=1 to (count(sym,",")+1);
*根据逗号的个数+1 判断sym中有几串字符,将这些字符串进入循环逐个判断替换;
if count(symptom,scan(sym,i,",")) then do;
*如果symptom中,出现了sym的第i个字符;
if i< count(sym,",")+1 then symptom=strip(tranwrd(symptom,scan(sym,i,",")||",",""));
else if i=count(sym,",")+1 then symptom=strip(tranwrd(symptom,","||scan(sym,i,","),""));
*首尾的情况不同,分别处理。尾部替换的是",小狗",前面替换的是"小狗,"。注:此处有一点小bug,如果倒数第二个字符已经替换,最后一个字符应该替换"小狗"而非",小狗";
*tranwrd():字符替换函数;
|