BookmarkSubscribeRSS Feed
xxformat_com
Barite | Level 11

Hi,

Is there any procedure... which could be used to validate an hyperlink?

Background for the question is this paper where hyperlinks are checked using Python:

https://www.lexjansen.com/pharmasug/2019/AD/PharmaSUG-2019-AD-211.pdf

Best Regards,

Véronique

3 REPLIES 3
unison
Lapis Lazuli | Level 10

Here’s a paper on working with urls in SAS: https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/100-30.pdf

 

I imagine you’ll approach this problem by reading the http response of a get request to the url and if status=200 then the link checks out?

-unison
xxformat_com
Barite | Level 11

Thanks. I will look into it.

unison
Lapis Lazuli | Level 10

Assuming you have working urls, you can check the status and message as follows:

 

%macro checkurl(lib=,url_dset=,url_out=);
%local num i currenturl;

%let dsid = %sysfunc(open(&url_dset.));
%let num  = %sysfunc(attrn(&dsid,nlobs));
%let rc   = %sysfunc(close(&dsid));

%do i=1 %to #

data _null_;
  p = &i;
  set &url_dset. point=p;
  call symputx('currenturl',URL);
  stop;
run;

proc http 
   url="&currenturl" 
   headerout=headout;
run;
data TEMP_&i.;
length url $200.;
infile headout scanover truncover;
input @'HTTP/1.1' code 4. message $255.;
if _n_=1 then do;
url="&currenturl";
output;
end;
run;

%end;

proc sql noprint;
select memname into :temp_dsets separated by " " from dictionary.tables where libname="&lib" and memname like 'TEMP%';
quit;

data &url_out.;
set &temp_dsets.;
run;

proc delete data=&temp_dsets; run;

%mend;

filename headout TEMP;

data myurls;
length url $200.;
input url $;
datalines;
http://httpbin.org/get
http://httpbin.org/post
;
run;

%checkurl(lib=WORK,url_dset=myurls,url_out=check);

proc print data=check; run;

However, notice what happens when I run proc http on a fake url.

 

proc http
   url="http://fake.website" 
   headerout=headout;
run;

Here's an attempt to see what happens in this case (from the docs https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.3&docsetId=proc&docsetTarget=n1ie...😞

 

%macro prochttp_check_return(url=,code=);
proc http url="&url";
run;
%if %symexist(SYS_PROCHTTP_STATUS_CODE) ne 1 %then %do;
  %put ERROR: Expected &code., but a response was not received from
 the HTTP Procedure;
  %abort;
  %end;
%else %do;
  %if &SYS_PROCHTTP_STATUS_CODE. ne &code. %then %do;
   %put ERROR: Expected &code., but received &SYS_PROCHTTP_STATUS_CODE.
 &SYS_PROCHTTP_STATUS_PHRASE.;
   %abort;%end;
%end;
%mend;

%prochttp_check_return(url=http://fake.website,code=200);

-unison

-unison

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 1793 views
  • 1 like
  • 2 in conversation