<?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: Extact strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846754#M334727</link>
    <description>&lt;P&gt;The solution suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;only works if the "code=" is the first part after the actual net address. If that is not the case, I would suggest something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; /* example data */
  url='login.microsoftonline.com/common/oauth2code=abcdxy&amp;amp;session_state=ab123bf2345';
run;

data want;
  set have;
  pos=prxmatch('/(?&amp;lt;=code\=)[[:alnum:]]+(?=&amp;amp;session_state)/',url);
  if pos then 
    code=scan(substr(url,pos),1,'&amp;amp;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The PRX expression looks for an alphanumeric string between "code=" and "&amp;amp;session_state". If it is found, we can then use SCAN to find the code. If your code can contain other characters that alphanumerics, take a look at the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0bj9p4401w3n9n1gmv6tf**bleep**9m.htm" target="_self"&gt;PRX documentation&lt;/A&gt;&amp;nbsp;or just replace "[[:alnum:]]" with "." - the general wildcard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2022 07:19:28 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2022-11-29T07:19:28Z</dc:date>
    <item>
      <title>Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846746#M334723</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please suggest how to extract Following &lt;FONT color="#3366ff"&gt;highlighted&lt;/FONT&gt;&amp;nbsp;part only. This &lt;FONT color="#3366FF"&gt;abcdxy&lt;/FONT&gt;&amp;nbsp;will always between &lt;STRONG&gt;&lt;FONT color="#800080"&gt;code=&lt;/FONT&gt;&lt;/STRONG&gt; and &lt;STRONG&gt;&lt;FONT color="#800080"&gt;&amp;amp;session_state&lt;/FONT&gt;&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;A href="https://login.microsoftonline.com/common/oauth2/nativeclient" target="_blank" rel="noopener"&gt;login.microsoftonline.com/common/oauth2&lt;/A&gt;&lt;FONT color="#800080"&gt;code=&lt;/FONT&gt;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;abcdxy&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#800080"&gt;&amp;amp;session_state&lt;/FONT&gt;=ab123bf2345&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Nov 2022 06:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846746#M334723</guid>
      <dc:creator>kumarsandip975</dc:creator>
      <dc:date>2022-11-29T06:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846748#M334724</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  have='login.microsoftonline.com/common/oauth2code=abcdxy&amp;amp;session_state=ab123bf2345';
  length want $20;
  want=scan(have,2,'=&amp;amp;');
run;
proc print data=demo;
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-1669704583192.png" style="width: 545px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77799i5A8AC69CB945C47A/image-dimensions/545x60?v=v2" width="545" height="60" role="button" title="Patrick_0-1669704583192.png" alt="Patrick_0-1669704583192.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 06:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846748#M334724</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-11-29T06:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846754#M334727</link>
      <description>&lt;P&gt;The solution suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;only works if the "code=" is the first part after the actual net address. If that is not the case, I would suggest something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; /* example data */
  url='login.microsoftonline.com/common/oauth2code=abcdxy&amp;amp;session_state=ab123bf2345';
run;

data want;
  set have;
  pos=prxmatch('/(?&amp;lt;=code\=)[[:alnum:]]+(?=&amp;amp;session_state)/',url);
  if pos then 
    code=scan(substr(url,pos),1,'&amp;amp;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The PRX expression looks for an alphanumeric string between "code=" and "&amp;amp;session_state". If it is found, we can then use SCAN to find the code. If your code can contain other characters that alphanumerics, take a look at the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0bj9p4401w3n9n1gmv6tf**bleep**9m.htm" target="_self"&gt;PRX documentation&lt;/A&gt;&amp;nbsp;or just replace "[[:alnum:]]" with "." - the general wildcard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 07:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846754#M334727</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-11-29T07:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846755#M334728</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  have='login.microsoftonline.com/common/oauth2code=abcdxy&amp;amp;session_state=ab123bf2345';
  length want $20;
  s=find(have,'code=');
  e=find(have,'&amp;amp;session_state');
  want=substr(have,s+5,e-s-5);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 07:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846755#M334728</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-29T07:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846762#M334734</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; thanks. I tested with your suggestion, it is working fine with sort length value between code= and &amp;amp;session_state, but I have approx 700+ charater string between these two keywords. Can you please suggest, how to deal with long characters values.</description>
      <pubDate>Tue, 29 Nov 2022 09:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/846762#M334734</guid>
      <dc:creator>kumarsandip975</dc:creator>
      <dc:date>2022-11-29T09:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/847006#M334866</link>
      <description>&lt;P&gt;Is it the code itself that is more than 700 characters? or is it that you have other HTML parameters between the code and the session_state?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the first case, I do not see why you should not get the correct code.&lt;/P&gt;
&lt;P&gt;In the second case, where you have e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'login.microsoftonline.com/common/oauth2code=abcdxy&amp;amp;name=george&amp;amp;session_state=ab123bf2345';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you should try changing the PRX call to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pos=prxmatch('/(?&amp;lt;=code\=)[[:alnum:]]+(?=&amp;amp;)/',url);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- this will find any instance of code=[alphanumeric value], followed by another HTML parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 09:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/847006#M334866</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-11-30T09:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extact strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/847154#M334945</link>
      <description>&lt;P&gt;You need to create the variable with an appropriate length instead of SAS let it do implicitly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create variable code with a length of 700&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1669841735886.png" style="width: 516px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77881iAE706030B3D02824/image-dimensions/516x116?v=v2" width="516" height="116" role="button" title="Patrick_1-1669841735886.png" alt="Patrick_1-1669841735886.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or to create variable code with the same length as variable url which should always be sufficient:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1669841770783.png" style="width: 588px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77882i596B249EC2C5EC79/image-dimensions/588x122?v=v2" width="588" height="122" role="button" title="Patrick_2-1669841770783.png" alt="Patrick_2-1669841770783.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 20:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extact-strings/m-p/847154#M334945</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-11-30T20:57:18Z</dc:date>
    </item>
  </channel>
</rss>

