<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Regular expression to a url link in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944531#M370067</link>
    <description>&lt;P&gt;Why you have to use PRX ? using classic sas function would be a lot easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data websites;
    input url :$100.;
    datalines;
google.com
http://twitter.com/Marko_met_een_K/status/1725797169897021653
https://regioonline.nl/regio-den-bosch/schade-aan-stuw-lith/
https://www.aa.com/en/how-to-regex?id=123
;
run;
data want;
 set websites;
temp=scan(substrn(url,find(url,'//')),1,'/');
if scan(temp,1,'.')='www' then want=scan(temp,2,'.');
 else want=scan(temp,1,'.');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Sep 2024 01:18:40 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-09-19T01:18:40Z</dc:date>
    <item>
      <title>Regular expression to a url link</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944428#M370031</link>
      <description>&lt;P&gt;how can you use regular expression in sas to select the name of the website from a data and display it.&lt;/P&gt;&lt;P&gt;Examples:&lt;/P&gt;&lt;P&gt;A1 = google.com&amp;nbsp; &amp;nbsp;the result should be equal to:&amp;nbsp; google&lt;/P&gt;&lt;P&gt;A2 = &lt;A href="http://twitter.com/Marko_met_een_K/status/1725797169897021653" target="_blank"&gt;http://twitter.com/Marko_met_een_K/status/1725797169897021653&amp;nbsp;&lt;/A&gt; the result should be equal to:&amp;nbsp; twitter&lt;/P&gt;&lt;P&gt;A3 = &lt;A href="https://regioonline.nl/regio-den-bosch/schade-aan-stuw-lith/" target="_blank"&gt;https://regioonline.nl/regio-den-bosch/schade-aan-stuw-lith/&amp;nbsp;&lt;/A&gt;&amp;nbsp; then the result should be equal to:&amp;nbsp; regioonline&amp;nbsp;&lt;/P&gt;&lt;P&gt;A4 = &lt;A href="https://www.aa.com/en/how-to-regex?id=123" target="_blank"&gt;https://www.aa.com/en/how-to-regex?id=123&amp;nbsp;&lt;/A&gt;&amp;nbsp; the result should be equal to:&amp;nbsp; &amp;nbsp;aa&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 14:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944428#M370031</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-09-18T14:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression to a url link</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944520#M370064</link>
      <description>&lt;P&gt;The following code generated by chatGPT using prompts: Using SAS code &amp;lt;copy/paste your question&amp;gt;&lt;/P&gt;
&lt;P&gt;The chatGPT returned code required only one small fix to make it work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data websites;
    input url :$100.;
    datalines;
google.com
http://twitter.com/Marko_met_een_K/status/1725797169897021653
https://regioonline.nl/regio-den-bosch/schade-aan-stuw-lith/
https://www.aa.com/en/how-to-regex?id=123
;
run;

data extracted_names;
    set websites;
    /* Use PRX to define a regex pattern to extract the website name */
    retain pattern;
    if _N_ = 1 then pattern = prxparse('/(?:https?:\/\/)?(?:www\.)?([^\/\.]+)\./');

    /* Apply the regex to the url and store the result in website_name */
    if prxmatch(pattern, url) then do;
        call prxsubstr(pattern, url, start_pos);
        website_name = prxposn(pattern, 1, url);
    end;

    /* Keep only the relevant columns */
    keep url website_name;
run;

proc print data=extracted_names noobs;
    title "Extracted Website Names";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1726702422278.png" style="width: 481px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100498i1B883136D0E3BAF2/image-dimensions/481x152?v=v2" width="481" height="152" role="button" title="Patrick_0-1726702422278.png" alt="Patrick_0-1726702422278.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 23:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944520#M370064</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-09-18T23:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression to a url link</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944531#M370067</link>
      <description>&lt;P&gt;Why you have to use PRX ? using classic sas function would be a lot easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data websites;
    input url :$100.;
    datalines;
google.com
http://twitter.com/Marko_met_een_K/status/1725797169897021653
https://regioonline.nl/regio-den-bosch/schade-aan-stuw-lith/
https://www.aa.com/en/how-to-regex?id=123
;
run;
data want;
 set websites;
temp=scan(substrn(url,find(url,'//')),1,'/');
if scan(temp,1,'.')='www' then want=scan(temp,2,'.');
 else want=scan(temp,1,'.');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2024 01:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944531#M370067</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-19T01:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression to a url link</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944820#M370178</link>
      <description>&lt;P&gt;Thank you for your quick response i really appreciate it&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2024 10:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944820#M370178</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-09-21T10:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression to a url link</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944821#M370179</link>
      <description>&lt;P&gt;thank you for your response.&lt;/P&gt;&lt;P&gt;That is very nice of you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2024 10:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-to-a-url-link/m-p/944821#M370179</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-09-21T10:53:52Z</dc:date>
    </item>
  </channel>
</rss>

