<?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 create a new variable with the first 3 digits of the old variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594664#M18147</link>
    <description>I really appreciate it! It is very helpful!&lt;BR /&gt;With regards,</description>
    <pubDate>Tue, 08 Oct 2019 08:08:44 GMT</pubDate>
    <dc:creator>CynthiaWei</dc:creator>
    <dc:date>2019-10-08T08:08:44Z</dc:date>
    <item>
      <title>How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594309#M18142</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having a question that I have a variable---code, the values code are so many digits there, such as B11234, B402345, C23456, and F6794321 etc. I want to create a new variable---newcode, with only the first three digits, that are B11, B40, C23, and F67.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, how to use array to create a series of newcode1 to newcode10 variables if I have code1, code2, code3..., and code10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any instruction!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 07:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594309#M18142</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2019-10-06T07:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594335#M18143</link>
      <description>&lt;P&gt;It seems like this is a perfect place to use an ARRAY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array code $ code1-code10;
    array newcode $ newcode1-newcode10;
    do i=1 to dim(code);
        newcode(i)=substr(code(i),1,3);
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Oct 2019 11:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594335#M18143</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-06T11:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594337#M18144</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266374"&gt;@CynthiaWei&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe you can try this, assuming you have 10 code variables, named code1 code2 etc.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array code (10);
	array newcode (10) $;
	do i=1 to dim(code);
		newcode(i) = substr(code(i),1,3);
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this help&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 11:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594337#M18144</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-10-06T11:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594339#M18145</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266374"&gt;@CynthiaWei&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know that many things you can do with the new variables can be done with the existing variables as well by using format &lt;FONT face="courier new,courier" size="3"&gt;$3.&lt;/FONT&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (code1-code4) ($) x;
cards;
B11234 B402345 C23456 F6794321 1
B11111 B422222 C23333 F634444  2
;

proc print data=have;
format code: $3.;
run;

proc freq data=have;
format code: $3.;
tables code:;
run;

proc means data=have;
format code1 $3.;
class code1;
var x;
run;

data test;
set have;
format code1 $3.;
by code1 groupformat;
if first.code1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Oct 2019 12:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594339#M18145</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-06T12:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594367#M18146</link>
      <description>&lt;P&gt;Also note, if you do decide to create the new variables, the SUBSTR function will only slow the program down.&amp;nbsp; You can get there using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array code $ code1-code10;
    array newcode $ 3 newcode1-newcode10;
    do i=1 to dim(code);
        newcode{i}=code{i};
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The ARRAY statement is capable of assigning a length to newly created variables in the array.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 20:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594367#M18146</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-06T20:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594664#M18147</link>
      <description>I really appreciate it! It is very helpful!&lt;BR /&gt;With regards,</description>
      <pubDate>Tue, 08 Oct 2019 08:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594664#M18147</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2019-10-08T08:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new variable with the first 3 digits of the old variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594665#M18148</link>
      <description>&lt;P&gt;I really appreciate it! It is very helpful!&lt;BR /&gt;With regards,&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 08:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-create-a-new-variable-with-the-first-3-digits-of-the-old/m-p/594665#M18148</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2019-10-08T08:09:18Z</dc:date>
    </item>
  </channel>
</rss>

