Help using Base SAS procedures

Skip Error When Reading from URL

Reply
New Contributor
Posts: 3

Skip Error When Reading from URL

I am trying to read some URL webpages into SAS from an input file that contains links to URLs (fname_full).  However, some of the links are not longer valid on the web. When SAS runs the codes, it will stop and generate error if one of the links no longer exist on the web.  I wonder how I can automatically skip those lines of URLs that generate error because the links no longer exists on the web and produce an output for those lines that the URL exists.

Excerpts of code:

data &outset;

set &inset;

infile datfiles URL filevar=%STR(&fname_full) end=lastline;

.............

It displays...

ERROR: Invalid reply received from the HTTP server. Use the debug option for more info.

SAS Employee
Posts: 340

Re: Skip Error When Reading from URL

I think you will need to use the filename(), fopen(), fread(), fget() functions, and check return codes.

Here is an example:

data urls;

input url:$100.;

datalines;

http://support.sas.com/techsup/

http://support.sas.com/techsup/service_intro.html

http://support.sas.com/techsup/

;

run;

data want;

  set urls;

  length text $ 10;

  rc1=filename('urlref',url,'URL','lrecl=3200');

  if rc1=0;

  fid=fopen('urlref','S');

  if fid~=0;

  rc2=fread(fid);/*reading 1 line*/

  if rc2=0;

  rc3=fget(fid, text, 10);/*reading 10 characters*/

  rc4=fclose(fid);

  putlog rc1= fid= rc2= rc3= text= rc4= _ERROR_=;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 268 views
  • 0 likes
  • 2 in conversation