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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

5 REPLIES 5
Cynthia_sas
SAS Super FREQ

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

JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

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

Ksharp
Super User

Or try this one:

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

Ksharp

JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

Thanks Ksharp. This helped.

TomKari
Onyx | Level 15

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;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 861 views
  • 3 likes
  • 4 in conversation