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
Or try this one:
data want; infile 'd:\temp\x.html' lrecl=20000 dsd dlm='<>'; input @'>' x : $200. @@; if not missing(x); run;
Ksharp
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
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
Or try this one:
data want; infile 'd:\temp\x.html' lrecl=20000 dsd dlm='<>'; input @'>' x : $200. @@; if not missing(x); run;
Ksharp
Thanks Ksharp. This helped.
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;
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 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.