Hi all,
I'm trying to convert some html that has company listings into a data set that has the company name and address. The general format for each company is something like this:
<p class="search-1">1.</p>
<p class="search-2"><strong>Company Name</strong> <br />
1 Test St <br />
Suite 1<br />
Test City, CA, 91763<br />
(555) 555-5555</p>
The input statement I'm using is:
input @'<p class="search-1">' ID 2.
@'<p class="search-2"><strong>' Name $40.
Address1 $40.
Address2 $40.
City $40.
Phone $40.
;
This comes close but has extra html in some fields and provides some erratic results, especially with the name and address fields. I've tried a few different things but I can't quite get it to work. Any input is greatly appreciated.
thanks in advance,
Rob
WE need to be careful with INformats on input statements. A specific length there will require and use that much data even when you might think it should 'finish earlier'!
For example
address1 $40.
will consume 40 characters
Placing a : before the informat changes behaviour closer to what you want by using input buffer up to the next delimiter or all the informat length has been used whichever comes first.
You might want to allow '<' to be your delimiter as well as blank.
Can you attach a html file ?
WE need to be careful with INformats on input statements. A specific length there will require and use that much data even when you might think it should 'finish earlier'!
For example
address1 $40.
will consume 40 characters
Placing a : before the informat changes behaviour closer to what you want by using input buffer up to the next delimiter or all the informat length has been used whichever comes first.
You might want to allow '<' to be your delimiter as well as blank.
Thanks Peter! Adding a colon and changing the delimiter worked just right.
In case any one is curious this is the input statement I ended up using:
infile test firstobs=77 dlm='<' ;
input @'<p class="search-1">' ID 2.
@'<p class="search-2"><strong>' Name : $40. /
Address1 : $40. /
Address2 : $40. /
City : $40. /
Phone : $40.
;
Thanks again!
Rob
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.
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.