3
you might just read in all data first then process each record afterwards
using character functions or Perl Regular Expressions.
data one;
input title $ Pet_owner $ pet $ number;
length name $20.;
name=compress(title)||' '||compress(pet_owner);
cards;
Mr. Black dog 2
Mr. Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data one: if one(or more) space(s) always exist(s) between the title
and the name";
run;
data two;
input title $ Pet_owner $ pet $ number;
length name $20.;
name=compress(title)||' '||compress(pet_owner);
cards;
Mr. Black dog 2
Mr.Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data two: if one space is missing between the title and the name";
run;
data three(keep=Pet_owner pet number);
infile cards truncover;
input lines $200.;
length name title Pet_owner pet $20. number 8.;
Pet_owner=scan(lines,1,'.')||'. '||compress(scan(scan(lines,2,'.'),1,' '));
Pet=compress(scan(scan(lines,2,'.'),2,' '));
number=compress(scan(scan(lines,2,'.'),3,' '))*1;
cards;
Mr. Black dog 2
Mr.Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data three: read in all data first.";
title "data three: then use SCAN. to process data";
run;
proc contents;
run;