<?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: How do i print the last remaining in a string? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615511#M76979</link>
    <description>&lt;P&gt;Must it be length of 4 as a start?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
str='JOHNhhk';
run;

data want;
 set have;
 ln=4;
 do until(ln=1);
  substr(str,ln)=' ';
  output;
  ln=lengthn(str);
 end;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;str&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ln&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;JOH&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;JO&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;J&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 07 Jan 2020 00:15:33 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-07T00:15:33Z</dc:date>
    <item>
      <title>How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615507#M76977</link>
      <description>I have a string JOHN that contains 4 characters. I want to delete the 4th letter every time.&lt;BR /&gt;example:&lt;BR /&gt;JOHN- 4th letter is N. N is deleted.&lt;BR /&gt;Now the string is reduced to JOH&lt;BR /&gt;JOH- count 3 letters and go back to the beginning and count J as 4th letter. J is deleted.&lt;BR /&gt;JO- 4th letter is O. O is deleted.&lt;BR /&gt;last remaining letter is J which should be printed as the result.&lt;BR /&gt;&lt;BR /&gt;how do I do this with sas?&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance</description>
      <pubDate>Mon, 06 Jan 2020 23:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615507#M76977</guid>
      <dc:creator>sneha_dodle</dc:creator>
      <dc:date>2020-01-06T23:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615510#M76978</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
str='JOHN';
run;

data want;
 set have;
 do until(lengthn(str)=1);
    substr(str,lengthn(str),1)=' ';
  output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;str&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;JOH&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;JO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;J&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 Jan 2020 00:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615510#M76978</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-07T00:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615511#M76979</link>
      <description>&lt;P&gt;Must it be length of 4 as a start?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
str='JOHNhhk';
run;

data want;
 set have;
 ln=4;
 do until(ln=1);
  substr(str,ln)=' ';
  output;
  ln=lengthn(str);
 end;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;str&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ln&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;JOH&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;JO&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;J&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 Jan 2020 00:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615511#M76979</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-07T00:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615522#M76982</link>
      <description>Sorry. There’s a mistake in the question. Lets take a longer word. Say DONALD. There are 6 letters. SAS should count the 6th letter in DONALD in each iteration and delete the 6th letter.&lt;BR /&gt;DONALD -delete D&lt;BR /&gt;DONAL - delete D&lt;BR /&gt;ONAL - delete N&lt;BR /&gt;OAL - delete L&lt;BR /&gt;OA - delete A&lt;BR /&gt;Print the result as O</description>
      <pubDate>Tue, 07 Jan 2020 01:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615522#M76982</guid>
      <dc:creator>sneha_dodle</dc:creator>
      <dc:date>2020-01-07T01:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615539#M76983</link>
      <description>&lt;P&gt;It's a bit late for me, so the brain is turning to mush here.&amp;nbsp; But here's an approach that should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a six-letter word, you will always want the second letter.&amp;nbsp; So ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Set up an array with 20 elements, all zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apply some numeric algorithm that just escapes me for now.&amp;nbsp; But after 1 iteration, it is 6 and thus turns the sixth array element to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then repeat.&amp;nbsp; On the second iteration, the mystery algorithm generates 1, and thus turns the first array element to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the third iteration, turn the third array element to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point is that you don't need to change the character string.&amp;nbsp; You can work with the positions of the elements, and track which ones have already been changed.&amp;nbsp; When the number of changed elements is one less than the number of letters in the word, the first zero is the position of the letter that remains.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 04:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615539#M76983</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-07T04:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615605#M76984</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258581"&gt;@sneha_dodle&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=DONALD;

data _null_;
c="&amp;amp;string";
p=length(c);
do i=1 to p-1;
  substr(c,mod(p-1,length(c))+1,1)=' ';
  c=compress(c);
  put c;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Not surprisingly, the sequence of the last remaining positions (of initial strings of length 1, 2, 3, ...) can be found in the OEIS:&amp;nbsp;&lt;A href="http://oeis.org/A128982" target="_blank" rel="noopener"&gt;http://oeis.org/A128982&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 09:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615605#M76984</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-07T09:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615697#M76989</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wow.&amp;nbsp; Didn't know there was such a thing as OEIS.&amp;nbsp; You not only knew about it, but knew how to find the right problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe this is my fault for looking at this before the morning cup of coffee, but is that formula correct?&amp;nbsp; Isn't it looking for the 7th character on the first iteration?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 15:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615697#M76989</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-07T15:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do i print the last remaining in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615702#M76993</link>
      <description>&lt;P&gt;Actually, I first wrote my program and then suspected that there might be a corresponding entry in the OEIS -- given that the resulting sequence of integers is both non-trivial and easily defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the first iteration in the example the character at position&amp;nbsp;&lt;FONT face="courier new,courier"&gt;mod(p-1,length(c))+1=mod(6-1,6)+1=5+1=&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/FONT&gt; is replaced with a blank, as it should.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 15:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-i-print-the-last-remaining-in-a-string/m-p/615702#M76993</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-07T15:47:43Z</dc:date>
    </item>
  </channel>
</rss>

