run;
有个data a如上所示. 我想把这个missing values补齐成如下data b(规则:1,code不足六位数的,通过添加前置0补齐6位. 2,如果code有missing,则延用上一行的code值): data b;
input code $ map;
cards;
10001F 200
10001F 140
10001F 205
001300 290
001300 230
001300 350
200015 102
020009 201
020009 700
020009 505
000240 300
000240 220
50010H 300
50010H 209
;
run;
谢谢!
作者: rideau 时间: 2015-5-8 09:37
笑纳:
data a(drop=code_t);
infile cards missover;
retain code;
input code_t $6. map;
if not missing(code_t) then code=code_t;
select(length(code));
when (1) code=cats("00000",code);
when (2) code=cats("0000",code);
when (3) code=cats("000",code);
when (4) code=cats("00",code);
when (5) code=cats("0",code);
otherwise;
end;
cards;
10001F 200
140
205
1300 290
230
350
200015 102
20009 201
700
505
240 300
220
50010H 300
209
;
run;作者: 艾谢依 时间: 2015-5-25 16:38
data b;
set a;
format code1 $6.;
if code^="" then do;
code1=code;
retain code1;
end;
code2="000000"||code1;
code3=substr(code2,length(code2)-5,6);
keep code3 map;
rename code3=code;
run;作者: BioSas 时间: 2016-5-17 06:07
data Bio_SAS (drop=Temp);
length Code $6;
infile datalines dlm=",";
retain Code;
input Temp : $6. Map;
if Temp ne "" then Code=Repeat("0",5-length(Temp))||strip(Temp);
datalines;
10001F,200
,140
,205
1300 ,290
,230
,350
200015,102
20009 ,201
,700
,505
240 ,300
,220
50010H,300
,209
;
run;作者: kiqi0510 时间: 2016-5-17 20:30
2楼的我支持作者: BioSas 时间: 2016-5-17 23:45
I am sorry that the number of 5 was a typo. The correct Data Step is:
data Bio_SAS (drop=Temp);
length Code $6;
infile datalines dlm=",";
retain Code;
input Temp : $6. Map;
if Temp ne " " then Code=Repeat("0",6-length(Temp))||strip(Temp);
datalines;
10001F,200
,140
,205
1300 ,290
,230
,350
200015,102
20009 ,201
,700
,505
240 ,300
,220
50010H,300
,209
;
run;