<?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 GET FIRST 2 CHARACTER IN SAS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544455#M7854</link>
    <description>&lt;P&gt;With a numeric value, you have to take care of the conversion from numeric to character. substr() is a character function.&lt;/P&gt;
&lt;P&gt;If you always have 4 digits, you could keep it numeric:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
LOAN_APPLCTN_BNM_CODE = 1232;
new1 = int(LOAN_APPLCTN_BNM_CODE/100);
put new1=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         LOAN_APPLCTN_BNM_CODE = 1232;
29         new1 = int(LOAN_APPLCTN_BNM_CODE/100);
30         put new1=;
31         run;

new1=12
&lt;/PRE&gt;
&lt;P&gt;"Clean" programming (see Maxim 25) mandates the avoidance of implicit type conversions (and the corresponding NOTEs in the log):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
LOAN_APPLCTN_BNM_CODE = 1232;
new1 = substr(left(put(LOAN_APPLCTN_BNM_CODE,4.)),1,2);
put new1=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         LOAN_APPLCTN_BNM_CODE = 1232;
29         new1 = substr(left(put(LOAN_APPLCTN_BNM_CODE,4.)),1,2);
30         put new1=;
31         run;

new1=12
&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Mar 2019 07:12:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-03-20T07:12:49Z</dc:date>
    <item>
      <title>HOW TO GET FIRST 2 CHARACTER IN SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544441#M7850</link>
      <description>&lt;P&gt;I have a data with different length character. I want to have 2 first character for example '1232' to become '12'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;new1=substr(LOAN_APPLCTN_BNM_CODE,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 05:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544441#M7850</guid>
      <dc:creator>Zizie</dc:creator>
      <dc:date>2019-03-20T05:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO GET FIRST 2 CHARACTER IN SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544445#M7851</link>
      <description>&lt;P&gt;The third parameter of the substr() function is the length to be extracted, so it should be "2" in your case.&lt;/P&gt;
&lt;P&gt;Another merthod is to forgo the substr() altogether and define the new variable with the wanted length, causing an implicit truncation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
LOAN_APPLCTN_BNM_CODE = "1232";
length new1 $2;
new1 = LOAN_APPLCTN_BNM_CODE;
put new1=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         LOAN_APPLCTN_BNM_CODE = "1232";
29         length new1 $2;
30         new1 = LOAN_APPLCTN_BNM_CODE;
31         put new1=;
32         run;

new1=12
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 06:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544445#M7851</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-20T06:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO GET FIRST 2 CHARACTER IN SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544451#M7852</link>
      <description>thank you.&lt;BR /&gt;&lt;BR /&gt;data b;&lt;BR /&gt;set a;&lt;BR /&gt;&lt;BR /&gt;LENGTH NEW1 $2;&lt;BR /&gt;NEW1=left(new);&lt;BR /&gt;RUN;</description>
      <pubDate>Wed, 20 Mar 2019 06:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544451#M7852</guid>
      <dc:creator>Zizie</dc:creator>
      <dc:date>2019-03-20T06:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO GET FIRST 2 CHARACTER IN SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544452#M7853</link>
      <description>Can I use the same method if it is numeric value</description>
      <pubDate>Wed, 20 Mar 2019 06:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544452#M7853</guid>
      <dc:creator>Zizie</dc:creator>
      <dc:date>2019-03-20T06:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO GET FIRST 2 CHARACTER IN SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544455#M7854</link>
      <description>&lt;P&gt;With a numeric value, you have to take care of the conversion from numeric to character. substr() is a character function.&lt;/P&gt;
&lt;P&gt;If you always have 4 digits, you could keep it numeric:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
LOAN_APPLCTN_BNM_CODE = 1232;
new1 = int(LOAN_APPLCTN_BNM_CODE/100);
put new1=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         LOAN_APPLCTN_BNM_CODE = 1232;
29         new1 = int(LOAN_APPLCTN_BNM_CODE/100);
30         put new1=;
31         run;

new1=12
&lt;/PRE&gt;
&lt;P&gt;"Clean" programming (see Maxim 25) mandates the avoidance of implicit type conversions (and the corresponding NOTEs in the log):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
LOAN_APPLCTN_BNM_CODE = 1232;
new1 = substr(left(put(LOAN_APPLCTN_BNM_CODE,4.)),1,2);
put new1=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data _null_;
28         LOAN_APPLCTN_BNM_CODE = 1232;
29         new1 = substr(left(put(LOAN_APPLCTN_BNM_CODE,4.)),1,2);
30         put new1=;
31         run;

new1=12
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 07:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/HOW-TO-GET-FIRST-2-CHARACTER-IN-SAS/m-p/544455#M7854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-20T07:12:49Z</dc:date>
    </item>
  </channel>
</rss>

