Glad to be of help,
The main difference between what I think your original code was doing and what this is doing, is that when the data step loop sees the begining of a tag, it stores what it reads in the CellHolder variable untill it sees an | tag. When it sees the end, it only writes it out if there is not an empty tag in the cell. If the row has nothing to do with a tag, it just writes it out normally. Here is a commented version of the last code I posted.
--------------------------------------------------------
data _null_;
infile in lrecl=120;
file out lrecl=4000;
* Prepare the varaible for storing CellTags. This is where we will store the information
between a CELL open and CELL close tag;
length CellHolder $4000;
* Tell SAS to not clear the contents of CellHolder. By default it will do this every time
it reads a new row from the input file;
retain CellHolder;
* Read a row from the input file;
input;
*If we have already seen an CELL tag but not its end (CellHolder already has something in it),
append the row we just read onto the end of the stored data;
if CellHolder ne "" then do;
CellHolder = catx(" ",CellHolder,_infile_);
end;
* Otherwise check to see if the row we just read is the start of a new CELL tag. If so store the
row in CellHolder for later use;
else if strip(_infile_) =: '
CellHolder = _infile_;
end;
* If CellHolder is empty at this point, we know that the row we just read has nothing to do
with a CELL tag, so just write it out as it is;
if CellHolder = "" then do;
put _infile_;
end;
* Otherwise see if the CELL tag stores in CellHolder has a close tag at the end. If so check to see
if it contains an empty DATA Tag. If the DATA Tag is not empty, write the stored CELL tag to the
output file. If not, do nothing. In either case, empty the contents of CellHolder, because we are
done processing that tag;
else do;
if substr(CellHolder,length(CellHolder)-6) = ' | ' then
do;
* Is the Data tag empty?;
if index(CellHolder,">") = 0 then do;
*write the contents of CellHolder to the file;
put CellHolder;
end;
* Empty CellHolder;
CellHolder = "";
end;
end;
run;