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.
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.