<?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 to populate string in reverse order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/681112#M205974</link>
    <description>&lt;P&gt;You can place the fname word parts, reversely indexed in a loop, in an array (i.e. conceptually a 'reverse/split') and perform a single CATX after the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data have;
input Fname $50.;
datalines;
Praveen Kumar     
Gowtham Kuppal KK 
Hari Haran M      
;

data want;
  set have;

  array items(0:49) $50 _temporary_;

  do _n_ = 1 to countw(fname);
    items(dim(items)-_n_) = scan(fname, _n_);
  end;

  fname = catx(' ', of items(*));
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Sep 2020 18:00:41 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-09-02T18:00:41Z</dc:date>
    <item>
      <title>how to populate string in reverse order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680916#M205903</link>
      <description>&lt;P&gt;How to populate the string in reverse order. For example I have a variable under name&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Fname&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Praveen Kumar&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Gowtham&amp;nbsp; Kuppal KK&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Hari Haran M&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I want the output to be in the required format:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Fname&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Kumar Praveen&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;KK Kuppal Gowtham&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;M Haran Hari&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 10:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680916#M205903</guid>
      <dc:creator>Aayushi_17</dc:creator>
      <dc:date>2020-09-02T10:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate string in reverse order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680917#M205904</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Fname $50.;
datalines;
Praveen Kumar     
Gowtham Kuppal KK 
Hari Haran M      
;

data want;
   set have;
   length FnameNew $ 50;
   do _N_ = countw(Fname) to 1 by -1;
      FnameNew = catx(' ', FnameNew, scan(Fname, _N_));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Fname              FnameNew 
Praveen Kumar      Kumar Praveen 
Gowtham Kuppal KK  KK Kuppal Gowtham 
Hari Haran M       M Haran Hari &lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2020 10:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680917#M205904</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-09-02T10:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate string in reverse order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680940#M205914</link>
      <description>&lt;P&gt;What should happen if the name consists of four words?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 12:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680940#M205914</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-02T12:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate string in reverse order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680956#M205924</link>
      <description>&lt;P&gt;I would recommend&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;'s solution over the code in this post as it works with any number of names&amp;nbsp; (see question from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I saw "reverse" in the title I just thought how might the&lt;FONT face="courier new,courier"&gt; reverse()&lt;/FONT&gt; function be used, so just for demonstration purposes, the following produces the required result for the input data provided:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;

    length name2 $ 50;

    name2 = reverse(catx(' '
                        ,reverse(scan(fname,1))
                        ,reverse(scan(fname,2))
                        ,reverse(scan(fname,3))
                    ));
run;    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 12:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/680956#M205924</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-09-02T12:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to populate string in reverse order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/681112#M205974</link>
      <description>&lt;P&gt;You can place the fname word parts, reversely indexed in a loop, in an array (i.e. conceptually a 'reverse/split') and perform a single CATX after the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data have;
input Fname $50.;
datalines;
Praveen Kumar     
Gowtham Kuppal KK 
Hari Haran M      
;

data want;
  set have;

  array items(0:49) $50 _temporary_;

  do _n_ = 1 to countw(fname);
    items(dim(items)-_n_) = scan(fname, _n_);
  end;

  fname = catx(' ', of items(*));
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2020 18:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-populate-string-in-reverse-order/m-p/681112#M205974</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-02T18:00:41Z</dc:date>
    </item>
  </channel>
</rss>

