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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

4 REPLIES 4
jwillis
Quartz | Level 8

Dear Jar,

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

Thank you.

JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

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

Ksharp
Super User

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

JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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