DATA Step, Macro, Functions and more

prxchange: change URL into <a href="URL">URL</a>

Reply
Contributor
Posts: 24

prxchange: change URL into <a href="URL">URL</a>

In the test below, wherever I have a reference field that looks like a URL, I want to change it into an HTML link to that

reference.  But there's something I'm missing between perl regexps and the translation into a call to prxchange()

data refs;

    input obs lname $ reference $160;

    datalines;

  2    Halley         http://www-groups.dcs.st-and.ac.uk/history/Biographies/Halley.html

  4    Graunt         Graunt:1662, http://www.encyclopedia.com/topic/John_Graunt.aspx

  6    Galton         Stigler:1986, p.281

17    Halley         http://www-history.mcs.st-and.ac.uk/Biographies/Halley.html

19    Serjev         Wainer-Harik:2013

20    Ortelius       http://en.wikipedia.org/wiki/Theatrum_Orbis_Terrarum

21    Playfair       Tufte:1983

28    Hollerith      Wikipedia

29    Lippershey     http://en.wikipedia.org/wiki/History_of_the_telescope#The_first_known_telescopes

33    Pascal         Ball:1908

37    de Colmar      http://en.wikipedia.org/wiki/Arithmometer

38    Minard         Tufte:1983, Minard:1869a

44    Galton         Stigler:1986,p297

46    Halley         http://www-groups.dcs.st-and.ac.uk/history/Biographies/Halley.html

;

data refs;

    set refs;

        *-- Turn URLs into links-- why doesnt this work??

            reference = prxchange('s|(https?://.*)[\s\b;]?|<a href="$1">$1</a>|i', -1, reference);

run;

proc print data=refs;

run;

I get a syntax error:

19   data refs;

20       set refs;

21           *-- Turn URLs into links-- why doesnt this work??

22               reference = prxchange('s|(https?://.*)[\s\b;]?|<a

                                                             -

                                                             180

22 ! href="$1">$1</a>|i', -1, reference);

ERROR 180-322: Statement is not valid or it is used out of proper order.

Respected Advisor
Posts: 4,918

Re: prxchange: change URL into <a href="URL">URL</a>

Posted in reply to michael_friendly

It was almost right, this works :

data refs;
length reference $160;
    input obs lname $ reference;
    datalines;
  2    Halley         http://www-groups.dcs.st-and.ac.uk/history/Biographies/Halley.html
  4    Graunt         Graunt:1662, http://www.encyclopedia.com/topic/John_Graunt.aspx
  6    Galton         Stigler:1986, p.281
17    Halley         http://www-history.mcs.st-and.ac.uk/Biographies/Halley.html
19    Serjev         Wainer-Harik:2013
20    Ortelius       http://en.wikipedia.org/wiki/Theatrum_Orbis_Terrarum
21    Playfair       Tufte:1983
28    Hollerith      Wikipedia
29    Lippershey     http://en.wikipedia.org/wiki/History_of_the_telescope#The_first_known_telescopes
33    Pascal         Ball:1908
37    de Colmar      http://en.wikipedia.org/wiki/Arithmometer
38    Minard         Tufte:1983, Minard:1869a
44    Galton         Stigler:1986,p297
46    Halley         http://www-groups.dcs.st-and.ac.uk/history/Biographies/Halley.html
;

data refs2;
length reference2 $160;
    set refs;
    /*-- Turn URLs into links -- */
    reference2 = prxchange('s|(https?://.*)[\s\b;]?|<a href="$1">$1</a>|i', 1, trim(reference));
run;

options linesize=132;
proc sql;
select reference, reference2 from refs2;
quit;

PG

PG
Ask a Question
Discussion stats
  • 1 reply
  • 167 views
  • 0 likes
  • 2 in conversation