Help using Base SAS procedures

Skip Error When Reading from URL

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.;




data want;

  set urls;

  length text $ 10;


  if rc1=0;


  if fid~=0;

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

  if rc2=0;

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


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


Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation