Interesting problem. First thought was to use two input statements, the first reads the whole line, then some tweaking of _infile_ and the second input statement could use named input to fill the variables. On a second glance this route is blocked by reusing names (InfoType => InfoType + D_InfoType).
So everything has to be done manually. At this point "interesting" changed to "annoying".
Here's a first attempt:
data work.have;
infile "PATH_TO_YOUR_FILE";
input; /* read whole line */
_infile_ = compress(_infile_, '"'); /* remove annoying quotes */
length info value $ 40; /* maybe to short/long */
info = upcase(scan(_infile_, 1, ':'));
value = scan(_infile_, 2, ':');
run;
data work.want;
set work.have end=jobDone;
length
BatchNo $ 3
GoodsName $ 40
Quantity 8
Infotype $ 20
D_Infotype $ 3
D_Typeid $ 3
D_Quantity 8
is_info 8
;
retain BatchNo GoodsName Quantity Infotype D_Infotype D_Typeid D_Quantity is_info;
if _n_ = 1 then do;
is_info = 0;
end;
select (info);
when ('BATCHNO') do;
if not missing(BatchNo) then do;
output;
call missing(GoodsName, Quantity, Infotype, of D_:);
end;
BatchNo = value;
is_info = 0;
end;
when ('GOODSNAME') do;
if not missing(GoodsName) then do;
output;
call missing(Quantity, Infotype, of D_:);
end;
GoodsName = value;
is_info = 0;
end;
when ('QUANTITY') do;
if not is_info then do;
Quantity = input(value, ?? best.);
end;
else do;
D_Quantity = input(value, ?? best.);
end;
end;
when ('INFOTYPE') do;
if not is_info then do;
Infotype = value;
end;
else do;
D_Infotype = value;
end;
end;
when ('TYPEID') do;
D_TypeID = value;
end;
when ('NEWLY', 'CAUSE') do;
is_info = 1;
end;
otherwise;
end;
if jobDone then do;
output;
end;
drop info value;
run;
... View more