<?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 Reverse in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874442#M345488</link>
    <description>&lt;P&gt;Hi. I needed to reverse string without using "reverse' function,i did but got a result without spaces. How can i apply them? The code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* 4. Reverse the string without using "reverse" function. */&lt;BR /&gt;data b1;&lt;BR /&gt;length reversed $200.;&lt;BR /&gt;var1='Reverse the string without using "reverse" function.';&lt;BR /&gt;erk=length(var1);&lt;BR /&gt;do i=length(var1) to 1 by -1;&lt;BR /&gt;reversed=strip(reversed) || substr(var1, i, 1 ) ;&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;drop erk i;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 12:50:06 GMT</pubDate>
    <dc:creator>Andrew15</dc:creator>
    <dc:date>2023-05-08T12:50:06Z</dc:date>
    <item>
      <title>Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874442#M345488</link>
      <description>&lt;P&gt;Hi. I needed to reverse string without using "reverse' function,i did but got a result without spaces. How can i apply them? The code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* 4. Reverse the string without using "reverse" function. */&lt;BR /&gt;data b1;&lt;BR /&gt;length reversed $200.;&lt;BR /&gt;var1='Reverse the string without using "reverse" function.';&lt;BR /&gt;erk=length(var1);&lt;BR /&gt;do i=length(var1) to 1 by -1;&lt;BR /&gt;reversed=strip(reversed) || substr(var1, i, 1 ) ;&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;drop erk i;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 12:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874442#M345488</guid>
      <dc:creator>Andrew15</dc:creator>
      <dc:date>2023-05-08T12:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874444#M345489</link>
      <description>&lt;P&gt;The STRIP() function is removing both any LEADING space and any TRAILING spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just keep track of where you are putting the character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to length(var1);
   substr(reversed,length(var1)-i+1,1)=substr(var1, i, 1 ) ;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;4601   data b1;
4602   length reversed $200.;
4603   var1='Reverse the string without using "reverse" function.';
4604   erk=length(var1);
4605   do i=1 to length(var1);
4606     substr(reversed,length(var1)-i+1,1)=substr(var1, i, 1 ) ;
4607   end;
4608   drop erk i;
4609   put (_character_) (/);
4610   run;


.noitcnuf "esrever" gnisu tuohtiw gnirts eht esreveR
Reverse the string without using "reverse" function.
NOTE: The data set WORK.B1 has 1 observations and 2 variables.
&lt;/PRE&gt;
&lt;P&gt;If you want to really mimic the way REVERSE() works when passed a variable name then use VLENGTH() instead of LENGTH() when calculating the location in the reversed variable.&amp;nbsp; That will preserve the trailing spaces that are stored in the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; substr(reversed,Vlength(var1)-i+1,1)=substr(var1, i, 1 ) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 May 2023 13:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874444#M345489</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-08T13:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874448#M345491</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b1;
  length reversed $200.;
  var1='Reverse the string without using "reverse" function. ĄŻŚŹĘĆŃÓŁ';
  j=1;
  do i = klength(var1) to 1 by -1;
    
    x=ksubstr(var1, i, 1); /* K...() functions are for UTF-8 symbols */
    substr(reversed, j, length(x)) = x; 
    j+length(x);
  end;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 May 2023 13:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874448#M345491</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-08T13:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874455#M345495</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA b1;
   var1='Reverse the string without using "reverse" function.';
   reversed=put(var1,$REVERS32767.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 May 2023 13:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874455#M345495</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-08T13:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874519#M345533</link>
      <description>&lt;P&gt;Is this a homework assignment? This is the &lt;A href="https://communities.sas.com/t5/SAS-Programming/Reverse-a-string-without-using-REVERSE/m-p/873580" target="_self"&gt;second time&lt;/A&gt; this question has been asked in a short period of time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS has provided the exact tool you want to reverse a string. That is the REVERSE function. It has been thoroughly tested and debugged. Why would you say that this tool can't be used? Why do you want a more complicated method that has been less thoroughly tested and debugged?&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 20:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874519#M345533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-08T20:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874555#M345539</link>
      <description>&lt;P&gt;If interested I can describe how I did this once upon a time in an assembler class by manipulating the output register buffers...&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 21:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874555#M345539</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-08T21:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874825#M345669</link>
      <description>&lt;P&gt;Yes it's homework task,and i am not allowed to use Reverse tool.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 05:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874825#M345669</guid>
      <dc:creator>Andrew15</dc:creator>
      <dc:date>2023-05-10T05:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874826#M345670</link>
      <description>Thank you!</description>
      <pubDate>Wed, 10 May 2023 05:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874826#M345670</guid>
      <dc:creator>Andrew15</dc:creator>
      <dc:date>2023-05-10T05:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874881#M345687</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442550"&gt;@Andrew15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes it's homework task,and i am not allowed to use Reverse tool.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well then I think your instructor has created a stupid problem. There are plenty of other things he could have asked you to program that don't have a built-in tool. One of the benefits of SAS (and most programming languages) is that commonly needed tools are provide so you don't have to create your own. I hope that if you ever have a need for this outside of this class, you will use the REVERSE function.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 10:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse/m-p/874881#M345687</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-10T10:18:00Z</dc:date>
    </item>
  </channel>
</rss>

