BookmarkSubscribeRSS Feed
JC_HK
Calcite | Level 5

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.

1 REPLY 1
gergely_batho
SAS Employee

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1409 views
  • 0 likes
  • 2 in conversation