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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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