/*Same idea*/
data have;
infile datalines truncover dlm='|';
input ID:$10. p1q1_living:$30.;
datalines;
12007c|17-35
12024x|
12024c|18 to 27 years
12025c|18-25
12032c|18-30
12033c|18-45
12043c|19 to 50 years
12044|19-27
12045c|19-33 years, 36-52 years
12048c|20 to 40 years
12049c|20-34
12314c|21 to 39 years
;
data want;
set have;
n=countw(p1q1_living,,'kd');
if mod(n,2)=0 and n ne 0 then do;
do i=1 to n by 2;
want=catx('-',scan(p1q1_living,i,,'kd'),scan(p1q1_living,i+1,,'kd'));
output;
end;
end;
else output;
drop n i;
run;
proc print noobs;run;
... View more