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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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