Help using Base SAS procedures

filename url - muliple entries from same line

Accepted Solution Solved
Reply
Contributor JAR
Contributor
Posts: 45
Accepted Solution

filename url - muliple entries from same line

Hi,

I need help to read one url file into a varible called record.

</h1><br/><h2 class="pageTitle entryTitle">test<span class="homograph">1</span></h2>

/*output:*/

Record

</h1>

<br/>

<h2 class="pageTitle entryTitle">

test

<span class="homograph">

1

</span>

</h2>

Ideally, I want only "test" and "1". If someone can help me to read either the whole items or non-html-tag portion it will be highly appreciated.

Regards,

Jijil


Accepted Solutions
Solution
‎07-15-2013 04:10 AM
Super User
Posts: 9,681

Re: filename url - muliple entries from same line

Or try this one:

data want;
 infile 'd:\temp\x.html' lrecl=20000 dsd dlm='<>';
 input @'>' x : $200. @@;
 if not missing(x);
run;

Ksharp

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,743

Re: filename url - muliple entries from same line

Hi:

  Can you show the code that you've tried that produces the output? Also, can you provide an example of your FILENAME url program? Without a context for your snippet (which is only part of an HTML page)  it is hard to provide constructive suggestions. Typically, an HTML page, such as you would read with the FILENAME method is a complete syntactically correct HTML page -- with a DOCTYPE,, an <HTML> tag,  a <HEAD> container, a <BODY> container, etc. You only show a snippet from an HTML file. What program did you run to get from the snippet to the output that you show?

cynthia

Contributor JAR
Contributor
Posts: 45

Re: filename url - muliple entries from same line

Dear Cynthia,

here is the code (after filename url)

data Test;

  length Record $1000;

  infile foo lrecl=32700;

  input;

  do until (_Top);

       _Top=find(_infile_,'<article>');

       if not _Top then input;

    end;

    do until (_Bottom);

       input;

       _Bottom=find(_infile_,' </article>');

       if _Bottom then STOP;

       else do;

  Record=_infile_;

  /*This removes all the html tag*/

  *rx1=prxparse("s/<.*?>//");

  *call prxchange(rx1,99,Record);

  output;

  end;

  end;

  Drop _:;

  Drop rx1;

run;

-------------------------------------------------------------------------------------------------------------------

Here is the html sample (as it is huge, I have taken only a portion of it).

<article>

                            <div xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml" id="mainContent"><header><h1 class="entryType">Definition of <b>test</b> in     English

</h1><br/><h2 class="pageTitle entryTitle">test<span class="homograph">1</span></h2><div class="entryPronunciation headpron">Pronunciation: <a href="http://oxforddictionaries.com/words/key-to-pronunciation"> /tɛst/</a></div>........

</article>

---------------------------------------------------------------------------------------------------------

I believe Tom's answer will work. However, thanks in advance for any insight your can throw.

Jijil Ramakrishnan

Solution
‎07-15-2013 04:10 AM
Super User
Posts: 9,681

Re: filename url - muliple entries from same line

Or try this one:

data want;
 infile 'd:\temp\x.html' lrecl=20000 dsd dlm='<>';
 input @'>' x : $200. @@;
 if not missing(x);
run;

Ksharp

Contributor JAR
Contributor
Posts: 45

Re: filename url - muliple entries from same line

Thanks Ksharp. This helped.

PROC Star
Posts: 1,093

Re: filename url - muliple entries from same line

Is this what you're after?

Tom

data stuff;
length ResultText $16;
TestString = '</h1><br/><h2 class="pageTitle entryTitle">test<span class="homograph">1</span></h2>';
prxid = prxparse('S/(<[^>]*>)/|/');
TestString2 = prxchange(prxid, -1, TestString);

do i=1 to count(TestString2, "|") + 1;
  ResultText=scan(TestString2, i, '|');

  if ^missing(ResultText) then
   output;
end;
run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 266 views
  • 3 likes
  • 4 in conversation