BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Curtis,

WOW!! This is soo awesome... you are amazing.. I just cant thank you enough..... Thanks a million for your help.

Also, if I'm not troubling you, would you be kind enough to explain the logic to me.... In my initial code i had a similar flow.... but I just need to make sure that I understand the logic...

Once again ...

Many Many Many Thanks,
Jerry
CurtisMack
Fluorite | Level 6
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;
deleted_user
Not applicable
Curtis,

Excellent. Thank you so much.... I'm so grateful for your help and once again thanks a million for taking the time to help me with this problem.

I now have a clear understanding of the flow. In the beginning I kept missing the append string part. Now its all clear to me.

Regards,
Jerry Message was edited by: jerry001

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 2828 views
  • 0 likes
  • 4 in conversation