<?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: Creating a new variable with reduced characters... in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371923#M2852</link>
    <description>&lt;P&gt;These can all be accomplished with SAS functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This list has SAS functions by category so you can search for the function that you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6x0an0z2dzozh2ouzm.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6x0an0z2dzozh2ouzm.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pas an example:&lt;/P&gt;
&lt;P&gt;1. SUBSTR() &amp;nbsp;to take a portion of a string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. SCAN() allows you to extract strings based on a delimiter&lt;/P&gt;
&lt;P&gt;2. TRANWRD() allows you to replace a word&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - the number of rows doesn't matter. The code is the same unles you maybe have 20 million plus. Then you'll save time processing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data example;
Set SASHELP.class;

Name = substr(name, 1,5); *takes first 5 characters of the name;

Sample_text = "Hudson County";

County = scan(sample_text, 1);

Run;

Proc print data=example;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 29 Jun 2017 22:09:03 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-06-29T22:09:03Z</dc:date>
    <item>
      <title>Creating a new variable with reduced characters...</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371919#M2849</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS programming and I am trying to:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Create a new variable that is reduced from 14 characters to 7 characters for 17898 observations.&lt;/P&gt;&lt;P&gt;2. I also need to use one or more text manipulation functions to remove the word "COUNTY" from each value because each variable is two words, ie. Hudson County.&lt;/P&gt;&lt;P&gt;3. Finally, I also need to keep the variable name should also be County in the output data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help anyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;T. Faison&lt;/P&gt;&lt;P&gt;Jersey City, NJ&lt;/P&gt;&lt;P&gt;Chemistry teacher&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 21:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371919#M2849</guid>
      <dc:creator>teharris007</dc:creator>
      <dc:date>2017-06-29T21:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable with reduced characters...</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371920#M2850</link>
      <description>&lt;P&gt;Are you trying to do something like the following?:&lt;/P&gt;
&lt;PRE&gt;data have;
  informat address $14.;
  input address &amp;amp;;
  cards;
North County
South County
N. West County
County County
;

data want;
  set have;
  length County $7.;
  county=tranwrd(address,' County','');
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 22:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371920#M2850</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-29T22:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable with reduced characters...</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371921#M2851</link>
      <description>&lt;P&gt;What does "reduced" mean? Does it mean only use the first seven characters? If so, the code below will work. If "reduced" means something else, then please tell us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;county=tranwrd(county,'county','');
county=substr(county,1,7);&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2017 22:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371921#M2851</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-06-29T22:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable with reduced characters...</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371923#M2852</link>
      <description>&lt;P&gt;These can all be accomplished with SAS functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This list has SAS functions by category so you can search for the function that you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6x0an0z2dzozh2ouzm.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6x0an0z2dzozh2ouzm.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pas an example:&lt;/P&gt;
&lt;P&gt;1. SUBSTR() &amp;nbsp;to take a portion of a string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. SCAN() allows you to extract strings based on a delimiter&lt;/P&gt;
&lt;P&gt;2. TRANWRD() allows you to replace a word&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - the number of rows doesn't matter. The code is the same unles you maybe have 20 million plus. Then you'll save time processing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data example;
Set SASHELP.class;

Name = substr(name, 1,5); *takes first 5 characters of the name;

Sample_text = "Hudson County";

County = scan(sample_text, 1);

Run;

Proc print data=example;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2017 22:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Creating-a-new-variable-with-reduced-characters/m-p/371923#M2852</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-29T22:09:03Z</dc:date>
    </item>
  </channel>
</rss>

