<?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: length of varible in sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677120#M23771</link>
    <description>&lt;P&gt;Why not just TELL the compiler what length your WANT to use for the new variables instead of forcing it to guess?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data scoredata2;
  set scoredata0;
  length gender_ac $21 gender_char $8;
  gender_ac = gender||'/'||gender_code; /*auto*/
  gender_char = put (gender_code, 8.); /*put*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will use the BEST12 format when you let it auto convert a number into a string.&amp;nbsp; So the values of GENDER_AC will be the length of GENDER (is that 1 byte? 6 bytes? Something else) plus 1 plus 12.&amp;nbsp; Whether SAS is smart enough to figure that number out or whether it just use 200 you would have to run it and see.&amp;nbsp; For the second step the values will all be length of 8 bytes.&amp;nbsp; I would assume the compiler could figure that out and define gender_char as length $8 since that length is known at compile time based on the width of the format used in the PUT() function call.&lt;/P&gt;</description>
    <pubDate>Sun, 16 Aug 2020 22:41:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-08-16T22:41:03Z</dc:date>
    <item>
      <title>length of varible in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677115#M23770</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code:&lt;/P&gt;
&lt;PRE&gt;data scoredata2;
set scoredata0;
gender_ac = gender||'/'||gender_code; /*auto*/
gender_char = put (gender_code, 8.); /*put*/
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in set scoredata0:&lt;/P&gt;
&lt;P&gt;gender=1 char&lt;/P&gt;
&lt;P&gt;gender_code=8 numeric&lt;/P&gt;
&lt;P&gt;how the length&amp;nbsp; of newvar calculated here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 22:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677115#M23770</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-08-16T22:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: length of varible in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677120#M23771</link>
      <description>&lt;P&gt;Why not just TELL the compiler what length your WANT to use for the new variables instead of forcing it to guess?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data scoredata2;
  set scoredata0;
  length gender_ac $21 gender_char $8;
  gender_ac = gender||'/'||gender_code; /*auto*/
  gender_char = put (gender_code, 8.); /*put*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will use the BEST12 format when you let it auto convert a number into a string.&amp;nbsp; So the values of GENDER_AC will be the length of GENDER (is that 1 byte? 6 bytes? Something else) plus 1 plus 12.&amp;nbsp; Whether SAS is smart enough to figure that number out or whether it just use 200 you would have to run it and see.&amp;nbsp; For the second step the values will all be length of 8 bytes.&amp;nbsp; I would assume the compiler could figure that out and define gender_char as length $8 since that length is known at compile time based on the width of the format used in the PUT() function call.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 22:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677120#M23771</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-16T22:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: length of varible in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677162#M23772</link>
      <description>length of the variable is 14 only.&lt;BR /&gt;I read the best12.  but  forget while applying that logic here.&lt;BR /&gt;Thanks a lot for letting me know quickly.&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Aug 2020 09:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/length-of-varible-in-sas/m-p/677162#M23772</guid>
      <dc:creator>rajeshm</dc:creator>
      <dc:date>2020-08-17T09:11:08Z</dc:date>
    </item>
  </channel>
</rss>

