<?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: Help in substring function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385084#M92067</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86703"&gt;@Kalai2008&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, I tried the compress function, but as you said its eliminating the 0 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABC000000000025225250&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ABC000000000025205250&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;its eliminating the last zero and middle zero &amp;nbsp;as well.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;POST YOUR CODE. You can specify digits or characters using the 3rd or 4th parameter of the COMPRESS function, you don't have to list them at all.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2017 19:08:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-08-02T19:08:47Z</dc:date>
    <item>
      <title>Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385075#M92062</link>
      <description>&lt;P&gt;data want;&lt;BR /&gt;set have (firstobs=1 obs=10);&lt;BR /&gt;id1=SUBSTRN(id,13,10);&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;given data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ABC00000012365948952321&lt;BR /&gt;ABC00000000000948952321&lt;BR /&gt;ABC00000000025369214558&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output want:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;12365948952321&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;948952321&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;25369214558&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;I have set of ID's that consist of 23 digits.&lt;BR /&gt;First 3 letters starts with alphabets and the rest are numbers.&lt;BR /&gt;I want to pull only the last numbers that starts after zero.&lt;BR /&gt;Since it's not constant position not sure how to use the function?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385075#M92062</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T18:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385077#M92063</link>
      <description>&lt;P&gt;Use COMPRESS to remove any characters that are letters.&lt;/P&gt;
&lt;P&gt;Use INPUT to read the remaining text as a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385077#M92063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T18:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385079#M92064</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input var $25.;&lt;BR /&gt;datalines;&lt;BR /&gt;ABC00000012365948952321&lt;BR /&gt;ABC00000000000948952321&lt;BR /&gt;ABC00000000025369214558&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;new_var=compress(var,'abcdefghijklmnopqrstuvwxyz0');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385079#M92064</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-02T19:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385081#M92065</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;It's not shown in the OP's example, but what if there was a 0 in the middle of the number? I think it's highly likely that's a possibility.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ABC00000012365948052321&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ABC00000000000948952321&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ABC00000000025369214008&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385081#M92065</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T19:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385083#M92066</link>
      <description>&lt;P&gt;Thank you, I tried the compress function, but as you said its eliminating the 0 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ABC000000000025225250&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ABC000000000025205250&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;its eliminating the last zero and middle zero &amp;nbsp;as well.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385083#M92066</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T19:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385084#M92067</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86703"&gt;@Kalai2008&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, I tried the compress function, but as you said its eliminating the 0 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABC000000000025225250&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ABC000000000025205250&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;its eliminating the last zero and middle zero &amp;nbsp;as well.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;POST YOUR CODE. You can specify digits or characters using the 3rd or 4th parameter of the COMPRESS function, you don't have to list them at all.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385084#M92067</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T19:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385085#M92068</link>
      <description>&lt;P&gt;data chk;&lt;BR /&gt;set test1.CHK2(firstobs=1 obs=10);&lt;BR /&gt;acct=compress(acct_id,'ABC0');&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;ABC000000000014256320&lt;/P&gt;&lt;P&gt;ABC000000000140252301&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output Results :&lt;/P&gt;&lt;P&gt;1425632&lt;/P&gt;&lt;P&gt;1425231&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385085#M92068</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T19:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385087#M92069</link>
      <description>&lt;P&gt;Something like this. What we are doing is making three groups. Anything mentioned in parentheis is group.1 st group is alphabets 2nd group is anything with 0 i.e. in midddle third group is from 0-9. We are replacing everything with&amp;nbsp;last group that is third group mentioned as $3&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
input var $50.;
datalines;
ABC00000012365948952321
ABC00000000000948952321
ABC00000000025369214558
ABC000000000253692145580
;


data bde;
set abc;
var1 =prxchange('s/([A-Z]+)(0+)([0-9]+)/$3/i', -1, var);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385087#M92069</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-08-02T19:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385091#M92070</link>
      <description>&lt;P&gt;Wow..It worked..Thanks a lot! Saved my time! Good &amp;amp; clear &amp;nbsp;Explanation.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385091#M92070</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T19:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385101#M92073</link>
      <description>&lt;P&gt;PRX is a great solution, but which one of these can you understand and modify if necessary?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set abc;

*Keep only digits in the string;
x=compress(var, , 'kd');

*convert to numeric;
y=input(x, best32.);

*use substring to extract all text after 3/4th character and convert to number;
z=input(substr(var, 4), best32.);

*PRX formula;
w=prxchange('s/([A-Z]+)(0+)([0-9]+)/$3/i', -1, var);

format  y z  best32.;
format x w $32.;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385101#M92073</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T20:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385102#M92074</link>
      <description>Somehow the code didn't picked this id,&lt;BR /&gt;It excluded the last zero.&lt;BR /&gt;ABCD0000000011423744160&lt;BR /&gt;ABCD0000000011129735160..&lt;BR /&gt;&lt;BR /&gt;Anyways Thank you Reeza, will try to modify as per your solution.</description>
      <pubDate>Wed, 02 Aug 2017 20:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385102#M92074</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T20:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385103#M92075</link>
      <description>Thank you Reeza. Let me try everything</description>
      <pubDate>Wed, 02 Aug 2017 20:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385103#M92075</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T20:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385105#M92076</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86703"&gt;@Kalai2008&lt;/a&gt; wrote:&lt;BR /&gt;Somehow the code didn't picked this id,&lt;BR /&gt;It excluded the last zero.&lt;BR /&gt;ABCD0000000011423744160&lt;BR /&gt;ABCD0000000011129735160..&lt;BR /&gt;&lt;BR /&gt;Anyways Thank you Reeza, will try to modify as per your solution.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that I don't understand PRX, so the function used above is as the original poster posted. &amp;nbsp;It's a perfectly valid solution, just not easy to modify especially as a beginner.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385105#M92076</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-02T20:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385106#M92077</link>
      <description>&lt;P&gt;I am so sorry, the code worked . I did a mistake in the input function ( char to num). Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385106#M92077</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-02T20:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385835#M92342</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
input var $50.;
datalines;
ABC00000012365948952321
ABC00000000000948952321
ABC00000000025369214558
ABC000000000253692145580
;


data bde;
set abc;
var1 =prxchange('s/^[A-Z0]+//i', -1, var);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Aug 2017 13:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385835#M92342</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-05T13:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help in substring function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385854#M92346</link>
      <description>&lt;P&gt;&amp;nbsp;If the maximum number you actually have is smaller than the maximum possible integer that SAS can represent exactly;&lt;/P&gt;
&lt;PRE&gt;586   data _null_;
587     x=constant('exactint');
588     put x= comma23.;
589   run;

x=9,007,199,254,740,992
&lt;/PRE&gt;
&lt;P&gt;Then you can just read the digits into a number and put it back out as a string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id1=put(input(substr(id,4),20.),20.-l);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you really have 20 decimal digits then that is too long to put into a number. &amp;nbsp;So instead using the VERIFY() funciton to find the location of the first non-zero digit. &amp;nbsp;Let's try both for some dummy data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input id $23.;
  id2=substr(id,4);
  if verify(trim(id2),'0') then id2=substr(id2,verify(id2,'0'));
  else id2='0';
  id3=put(input(substr(id,4),20.),20.-l);
  match=(id2=id3);
cards;
ABC00000012360948952321
ABC00000000000948902321
ABC00000000025369214558
ABC00000000000000000000
ABC12345678901234567890
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 576px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14348i10B599DA2BA6ECE5/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Aug 2017 16:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-substring-function/m-p/385854#M92346</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-05T16:38:23Z</dc:date>
    </item>
  </channel>
</rss>

