<?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: First 3 positions of a numeric variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/First-3-positions-of-a-numeric-variable/m-p/74576#M21652</link>
    <description>Hi:&lt;BR /&gt;
  The basic procedure is:&lt;BR /&gt;
1) convert your number to a left-justified character string with the LEFT and PUT functions&lt;BR /&gt;
2) extract the first3 characters from the left-justified character string with the SUBSTR function&lt;BR /&gt;
3) if you need the first 3 characters as character, then you're done, But, if you need the first 3 characaters as a number, then you need to convert from a character string to a number using the INPUT function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
  charvar = left(put(num, 30.));   /* #1 */&lt;BR /&gt;
  first3_char = substr(charvar,1,3);   /* #2  */&lt;BR /&gt;
  first3_num = input(first3_char,3.);   /* #3 */&lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
You could have done everything in one assignment statement, but I find it useful to break down each step in the transformation, so it's easier to understand.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Thu, 19 Feb 2009 07:47:24 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-02-19T07:47:24Z</dc:date>
    <item>
      <title>First 3 positions of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-3-positions-of-a-numeric-variable/m-p/74575#M21651</link>
      <description>i have a numeric variable i want the first 3 positions of that variable&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
input num;&lt;BR /&gt;
format num 30.;&lt;BR /&gt;
cards;&lt;BR /&gt;
987987899787&lt;BR /&gt;
768767868755567&lt;BR /&gt;
578676474545&lt;BR /&gt;
56756959695998&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The out put should be like this&lt;BR /&gt;
&lt;BR /&gt;
987&lt;BR /&gt;
768&lt;BR /&gt;
578&lt;BR /&gt;
567</description>
      <pubDate>Thu, 19 Feb 2009 06:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-3-positions-of-a-numeric-variable/m-p/74575#M21651</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2009-02-19T06:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: First 3 positions of a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-3-positions-of-a-numeric-variable/m-p/74576#M21652</link>
      <description>Hi:&lt;BR /&gt;
  The basic procedure is:&lt;BR /&gt;
1) convert your number to a left-justified character string with the LEFT and PUT functions&lt;BR /&gt;
2) extract the first3 characters from the left-justified character string with the SUBSTR function&lt;BR /&gt;
3) if you need the first 3 characters as character, then you're done, But, if you need the first 3 characaters as a number, then you need to convert from a character string to a number using the INPUT function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
  charvar = left(put(num, 30.));   /* #1 */&lt;BR /&gt;
  first3_char = substr(charvar,1,3);   /* #2  */&lt;BR /&gt;
  first3_num = input(first3_char,3.);   /* #3 */&lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
You could have done everything in one assignment statement, but I find it useful to break down each step in the transformation, so it's easier to understand.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 19 Feb 2009 07:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-3-positions-of-a-numeric-variable/m-p/74576#M21652</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-02-19T07:47:24Z</dc:date>
    </item>
  </channel>
</rss>

