DATA Step, Macro, Functions and more

infile-input vs. Set

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

infile-input vs. Set

Dear All,

I would like to use the following code to read some data from a sas file:

data want;

infile 'd:\temp\x.html' lrecl=20000 dsd dlm='<>';

input @'>' x : $200. @@;

if not missing(x);

run;

Instead of reading the same data from x.html file, I have the following SAS7bDat file under SASUser.x

How do I use the same code here:

data want;

set sasuser.x;

(I have no clue beyond this... plz help)

Your help is greatly appreciated in advance...

Jijil Ramakrishnan


Accepted Solutions
Solution
‎05-24-2014 07:40 AM
Super User
Posts: 9,682

Re: infile-input vs. Set

Thank you to refer to me. Here is :

data have;

infile cards length=len;

input text  $varying200. len;

datalines4;

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

;;;;

run;

data want;

set have;

re=prxparse('/(?<=>)[^<]+/o');

start = 1;

stop = length(text);

call prxnext(re, start, stop,text, position, length);

do while (position > 0);

found = substr(text, position, length);

output;

call prxnext(re, start, stop, text, position, length);

end;

keep found;

run;

Xia Keshan

Message was edited by: xia keshan

View solution in original post


All Replies
Regular Contributor
Posts: 217

Re: infile-input vs. Set

Dear Jar,

Please post the first few (5?) records from both the html and SAS file.

Thank you.

Contributor JAR
Contributor
Posts: 45

Re: infile-input vs. Set

This is my earlier communication

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

(KSharp had helped me earlier with the code above, thanks to him)

This time, the raw html data is not in an html file, rather it is in sas under 'sasuser'.

Jijil

Solution
‎05-24-2014 07:40 AM
Super User
Posts: 9,682

Re: infile-input vs. Set

Thank you to refer to me. Here is :

data have;

infile cards length=len;

input text  $varying200. len;

datalines4;

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

;;;;

run;

data want;

set have;

re=prxparse('/(?<=>)[^<]+/o');

start = 1;

stop = length(text);

call prxnext(re, start, stop,text, position, length);

do while (position > 0);

found = substr(text, position, length);

output;

call prxnext(re, start, stop, text, position, length);

end;

keep found;

run;

Xia Keshan

Message was edited by: xia keshan

Contributor JAR
Contributor
Posts: 45

Re: infile-input vs. Set

Dear KSharp,

Perhaps I had not illustrated my question enough earlier. The solution is much simpler, and if I had asked more claerly all of you could have helped me better:

Instead of accessing to a file(with HTML raw data in it) using infile input, I had to access to a sas dataset:

data Want;

Set have;

  before=Record;

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

  call prxchange(rx1,99,Record);

  if Record="" then delete;

Run;

Jijil Ramakrishnan

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 305 views
  • 1 like
  • 3 in conversation