<?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: Cutting some words from a character variable with varied lengths in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714398#M220547</link>
    <description>&lt;P&gt;1) Function CATS is one out of few functions CATx - where x can be space or S or T or X - all of them are variations of CONCATENATNG strings.&lt;/P&gt;
&lt;P&gt;2) Other functions dealing with strings helps to deal with substrings like: SUBSTR, FINDW, INDEX, INDEXC, TRANWRD, TRANSLATE and others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can learn a lot by reading SAS Documentation and run examples given within the documentation.&lt;/P&gt;
&lt;P&gt;Easy way to find the documentation is by searching Google:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"sas documentation " followed by any sas keyword: function name, procedure name etc.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jan 2021 19:56:40 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-01-26T19:56:40Z</dc:date>
    <item>
      <title>Cutting some words from a character variable with varied lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714215#M220469</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Previously, I want to generate a new variable &lt;STRONG&gt;short_fn&lt;/STRONG&gt; the first three characters of a country name (&lt;STRONG&gt;fname&lt;/STRONG&gt;) with an underline "_", so my code is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;short_fn= cats(substr(fname, 1,3),'_');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Therefore, when fname=Argentina_ =&amp;gt; short_fn =ARG_&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;fname=UK_&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; short_fn=UK__&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, I want to change the code to be compatible of the new name&lt;/P&gt;
&lt;P&gt;For example, now the fname are ArgentinaARS, United KingdomGBP, and United StatesUSD&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;And I want to write code to get two separate variables:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;short_fn: ARGENTINA, UNITED KINGDOM, UNITED STATES&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;currency: ARS, GBP, USD&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help me to sort it out? (If we can make use of the function &lt;STRONG&gt;cats&lt;/STRONG&gt; or &lt;STRONG&gt;substr&lt;/STRONG&gt;, it would be great, if not, I am also willing to learn new SAS function)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks in advance and warmest regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Jan 2021 11:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714215#M220469</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-26T11:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting some words from a character variable with varied lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714218#M220471</link>
      <description>&lt;P&gt;Assuming currency is always 3 characters then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;len = length(counytry);
short_fn = substr(country,1,len-3);
currency = substr(country,len-2,3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2021 11:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714218#M220471</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-26T11:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting some words from a character variable with varied lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714387#M220544</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really appreciate your answer. Just wondering if we should use function "cats" here?&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Jan 2021 19:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714387#M220544</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-26T19:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting some words from a character variable with varied lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714395#M220546</link>
      <description>&lt;P&gt;It is not clear what you are asking for.&amp;nbsp; It sounds like you have input like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input fname $32. ;
cards;
ArgentinaARS
United KingdomGBP
United StatesUSD
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you will want to write code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length short_fn $29 currency $3 ;
  short_fn = substr(fname,1,length(fname)-3);
  currency = substr(fname,length(fname)-2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs          fname          short_fn          currency

 1     ArgentinaARS         Argentina           ARS
 2     United KingdomGBP    United Kingdom      GBP
 3     United StatesUSD     United States       USD
&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2021 19:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714395#M220546</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-26T19:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting some words from a character variable with varied lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714398#M220547</link>
      <description>&lt;P&gt;1) Function CATS is one out of few functions CATx - where x can be space or S or T or X - all of them are variations of CONCATENATNG strings.&lt;/P&gt;
&lt;P&gt;2) Other functions dealing with strings helps to deal with substrings like: SUBSTR, FINDW, INDEX, INDEXC, TRANWRD, TRANSLATE and others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can learn a lot by reading SAS Documentation and run examples given within the documentation.&lt;/P&gt;
&lt;P&gt;Easy way to find the documentation is by searching Google:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"sas documentation " followed by any sas keyword: function name, procedure name etc.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 19:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714398#M220547</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-26T19:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cutting some words from a character variable with varied lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714404#M220550</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; Just wondering if we should use function "cats" here?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;answers the question as you described it. There is nothing to concatenate that I can see. Is there?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 20:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cutting-some-words-from-a-character-variable-with-varied-lengths/m-p/714404#M220550</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-26T20:13:34Z</dc:date>
    </item>
  </channel>
</rss>

