<?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: fullname to shortname in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608299#M177014</link>
    <description>&lt;P&gt;Tom, does SUBSTR actually use the length of $20?&amp;nbsp; Admittedly it has been a long time since I tested this, but I recall that SUBSTR used the length of the incoming string to define a newly created variable.&amp;nbsp; The basic idea was that the third parameter could be an expression instead of a hard-coded value, and so might not be capable of setting a length.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Nov 2019 17:09:58 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-11-29T17:09:58Z</dc:date>
    <item>
      <title>fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608272#M176998</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;
&lt;P&gt;I don't know how to code this problem below.&amp;nbsp; Any help is much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variable name fullname (length $30) has a respondent's first, middle, and last name. Create var shortname (length $20), which has only the first and last name, separated by a single blank.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 15:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608272#M176998</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2019-11-29T15:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608273#M176999</link>
      <description>&lt;P&gt;The SCAN() function ought to work here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;SCAN(fullname,1)&lt;/FONT&gt; extracts the first "word" from fullname&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give it a try, see if you can get it to do what you want.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 15:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608273#M176999</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-29T15:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608277#M177001</link>
      <description>&lt;P&gt;I tried it with sql and&amp;nbsp;prxChange. It seems to work but I don't know how to specify length $20 for shortName.&lt;/P&gt;
&lt;PRE&gt;data a;
input fullname $30.;
cards;
George W. Bush
George W Bush
George Bush
;
run;

proc sql;
select fullname, 
    prxChange("s/(\w+\s)(\s*\w\.?\s+)(\w+)/\1\3/io",1,fullname) as shortName
from a;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 16:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608277#M177001</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2019-11-29T16:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608280#M177003</link>
      <description>&lt;P&gt;You can use the LENGTH keyword in SQL to tell SAS how many bytes to use when storing the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;.... as shortname length=20&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also have used the SUBSTR() function and SAS would have figured out that your expression could only return 20 bytes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(....,1,20) as shortname&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 16:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608280#M177003</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-29T16:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608284#M177005</link>
      <description>Thank you very much for your kind help! I really appreciate it!</description>
      <pubDate>Fri, 29 Nov 2019 16:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608284#M177005</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2019-11-29T16:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608299#M177014</link>
      <description>&lt;P&gt;Tom, does SUBSTR actually use the length of $20?&amp;nbsp; Admittedly it has been a long time since I tested this, but I recall that SUBSTR used the length of the incoming string to define a newly created variable.&amp;nbsp; The basic idea was that the third parameter could be an expression instead of a hard-coded value, and so might not be capable of setting a length.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 17:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608299#M177014</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-29T17:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: fullname to shortname</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608305#M177016</link>
      <description>&lt;P&gt;In a data step it will guess the length based on the input to the SUBSTR() function. But in SQL it will guess the length based on the output of the SUBSTR() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  x=substr('1234567890',1,6);
  y=vlength(x);
  put y=;
run;

proc sql;
 create table test1 as select  substr('1234567890',1,6) as x from sashelp.class(obs=1);
quit;
data _null_;
 set test1;
 y=vlength(x);
 put y=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 17:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fullname-to-shortname/m-p/608305#M177016</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-29T17:26:06Z</dc:date>
    </item>
  </channel>
</rss>

