BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rpmartin
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12

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.

View solution in original post

3 REPLIES 3
Ksharp
Super User

Can you attach a html file ?

Peter_C
Rhodochrosite | Level 12

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.

rpmartin
Calcite | Level 5

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

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
  • 3 replies
  • 765 views
  • 0 likes
  • 3 in conversation