sas批量替换字符字段中的值批量替换部分字符字段的值使⽤数组:批量替换temp数据集中字符字段中的 ‘dd’ 为'xx';并对字符缺失值⽤'xxxx'填充。
1、例⼦:temp需要替换的数据集
p;
input a$9. b$9. c;
cards;
abcdedda eeffaass 123
yy789vad ccddeeww 456
yyddmmdd aabbccdd 7
tc123456 tcdeeeew 20
;
run;
林盈臻
2、替换代码(图为替换结果)
data  p2;
set  p;
我用自己的方式爱你
array char _char_;
do over char;
歌在飞 原唱
if  char ne '' then  char=tranwrd(char,'dd','xx');
else if missing(char)='xxxx';
end;
蒙古说唱run;
/***2、test 数据集中:当a=1 时 替换 b1,b2中的值为'-8888',当a=2,如果b1,b2为空 ⽤'-9999'填充 **/
st;
input a a2$9. b1$9. b2$12.;
cards;
1 abcdedda eeffaass ttddffgg
1 yy789vad ccddeeww -99999
2 yyddmmdd aabbccdd -8jjjjj
3 tc123456 tcdeeeew -99ffdd
;
run;
陆远为什么坐牢
st2;
st;
都是你吉他谱array char b:;
do i=1 to dim(char);
if a=1 and  ^missing(char[i]) then char[i] = '-8888'; else if a=2 and missing(char[i]) then char[i]='-9999' ; end;
drop i;
run;