Here' a single step solution that uses the often overlooked INPUT @"character string" technique. And because the routine looks ahead for the next schemeid, there is an explicity output statement, followed by an update to schemeid (which is retained).
It makes the following assumptions.
the order of elements are SCHEMEID, PRODUCT, INCENTIVES, and (optionally) CONDITIONS.
schemeid is a single line
there can be no lines or any number of blank lines between schemeid and productid
product id is two lines, one with the keyword and one with the value
there can be no lines or any number of blank lines between productid and incentives
incentives can have multiple lines and are always terminated with a blank line (although that could be easily relaxed).
conditions can have any number of lines and are terminated wiht a new schemeid line.
With the exception of schemeid, it would be relatively straightforward to accomodate any order of the elements.
data want (drop=_:);
infile 'c:\temp\t.txt' end=eod;
retain schemeid .;
if schemeid=. then input @ "Scheme ID:" schemeid;
input @ "Product:" / product && $80.;
length incentive $500;
input @ "Incentive:" / ;
do until (_infile_=' ');
incentive=catx(' ',incentive,_infile_);
input;
end;
length conditions $1000;
do until (eod or index(_infile_,"Scheme ID:"));
input;
if _condition_found then conditions=catx(' ',conditions,_infile_);
else if index(_infile_,"Conditions:") then _condition_found=1;
end;
output;
if eod=0 then schemeid=input(scan(_infile_,3),10.);
run;
... View more