<?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 reverse a name with space and extract part of it? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283168#M57676</link>
    <description>Yes, it works. Thank you!!!</description>
    <pubDate>Sat, 09 Jul 2016 20:10:54 GMT</pubDate>
    <dc:creator>RavenWu</dc:creator>
    <dc:date>2016-07-09T20:10:54Z</dc:date>
    <item>
      <title>how to reverse a name with space and extract part of it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283133#M57660</link>
      <description>&lt;P&gt;I want to extract the first name from a name with a space and also reverse it, and here is my codes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; PROC IMPORT DATAFILE='D:\Wow.xlsx' OUT= Wow  DBMS= XLSX  REPLACE;
 RUN;

 DATA Names;
 SET  Wow;
 First_Name = SCAN(REVERSE(Reversed_names),1);
 RUN;&lt;/PRE&gt;&lt;P&gt;The result is:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3981i99FDFCBD746AC57B/image-size/large?v=v2&amp;amp;px=-1" border="0" alt="my result.png" title="my result.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The content is empty, which is not what I want. Could anyone tell me what is the problem with my codes? (see attachment with the dataset)&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 09:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283133#M57660</guid>
      <dc:creator>RavenWu</dc:creator>
      <dc:date>2016-07-09T09:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to reverse a name with space and extract part of it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283138#M57662</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works fine for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Wow;&lt;BR /&gt;input Name $20.;&lt;BR /&gt;datalines;&lt;BR /&gt;lazraM sérdnA &lt;BR /&gt;ladiV euqirnE&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA Names;&lt;BR /&gt;SET Wow;&lt;BR /&gt;First_Name = SCAN(REVERSE(Name),1);&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Problem seems to be in variable reference&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;SCAN(REVERSE(Reversed_names),1);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Variable Reversed_names is not contained in your data set wow &lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Jul 2016 10:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283138#M57662</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-07-09T10:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to reverse a name with space and extract part of it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283143#M57665</link>
      <description>&lt;P&gt;Your code is fine. It is proabably your data that is messed up. &amp;nbsp;Most likely you have some non-printing charater at the end of the line that is being interpretted by SCAN() as the first word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your XLSX file is fine, but perhaps you actually read the data from a text file and did not properly tell SAS what characters to use for end of line and ended up with a Carriage Return character at the end of each value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname x xlsx "&amp;amp;path/Wow.xlsx";
data want;
 set x.sheet1 ;
 first_name= scan(reverse(reversed_names),1);
 put (_all_) (=);
 first_name= scan(reverse(reversed_names||'0D'x),1);
 put (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Reversed_Names=lazraM sérdnA first_name=Andrés
Reversed_Names=lazraM sérdnA first_name=

Reversed_Names=ladiV euqirnE first_name=Enrique
Reversed_Names=ladiV euqirnE first_name=

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 12:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283143#M57665</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-09T12:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to reverse a name with space and extract part of it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283146#M57670</link>
      <description>&lt;P&gt;I think &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42042"&gt;@stat_sas﻿&lt;/a&gt;&amp;nbsp;is close.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Check your variable properties. Since you're using EG, it looks like it's allowing spaces in the variable name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to refer to your variable as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Reversed Names'n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or set the following option so it converts spaces to underscores when you import your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Option validvarname = v7;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise your code is correct.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 13:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283146#M57670</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-09T13:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to reverse a name with space and extract part of it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283168#M57676</link>
      <description>Yes, it works. Thank you!!!</description>
      <pubDate>Sat, 09 Jul 2016 20:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-reverse-a-name-with-space-and-extract-part-of-it/m-p/283168#M57676</guid>
      <dc:creator>RavenWu</dc:creator>
      <dc:date>2016-07-09T20:10:54Z</dc:date>
    </item>
  </channel>
</rss>

