<?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-Setting length of a variable after SET statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487607#M127078</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, here's my simple code that re-sets length of variable&amp;nbsp;'EmpID' after a SET statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data department;
input EmpID;
length EmpID 5;
datalines;
38284
47372
47372
93822
;
run;

data accounting;
set department;
length EmpID 6;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although original length of EmpID in department was 5, it changes to 6.&lt;/P&gt;&lt;P&gt;I was told that if re-declaration of length of a variable occurs after a set statement, it gets ignored,&lt;/P&gt;&lt;P&gt;since there is a preset length and data are already flowing in, line-by-line, by a SET statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I wrong? Well, at least from what I have found out in SAS 9.4, it seems I'm wrong&lt;/P&gt;</description>
    <pubDate>Thu, 16 Aug 2018 23:36:02 GMT</pubDate>
    <dc:creator>jimmychoi</dc:creator>
    <dc:date>2018-08-16T23:36:02Z</dc:date>
    <item>
      <title>Re-Setting length of a variable after SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487607#M127078</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, here's my simple code that re-sets length of variable&amp;nbsp;'EmpID' after a SET statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data department;
input EmpID;
length EmpID 5;
datalines;
38284
47372
47372
93822
;
run;

data accounting;
set department;
length EmpID 6;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although original length of EmpID in department was 5, it changes to 6.&lt;/P&gt;&lt;P&gt;I was told that if re-declaration of length of a variable occurs after a set statement, it gets ignored,&lt;/P&gt;&lt;P&gt;since there is a preset length and data are already flowing in, line-by-line, by a SET statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I wrong? Well, at least from what I have found out in SAS 9.4, it seems I'm wrong&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 23:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487607#M127078</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2018-08-16T23:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Re-Setting length of a variable after SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487612#M127079</link>
      <description>&lt;P&gt;As the DATA step executes, all numerics have a length of 8.&amp;nbsp; The length you assign using a LENGTH statement can truncate the value as it gets moved to an output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For numerics, you can change the length of the numeric (once it gets output) in the way you describe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For character variables, the first mention of the variable determines its length.&amp;nbsp; To change the length, you would need to place the LENGTH statement before the SET statement.&amp;nbsp; Placing it after should generate some sort of message (error or warning).&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 00:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487612#M127079</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-17T00:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Re-Setting length of a variable after SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487630#M127086</link>
      <description>&lt;P&gt;I was just using the fact that you can set the LENGTH for numeric variables after they have been defined in a little utility I was creating to generate data step code to post sample data.&lt;/P&gt;
&lt;P&gt;If you run this program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename ds2post url 'https://raw.githubusercontent.com/sasutils/macros/master/ds2post.sas';
%inc ds2post;
%ds2post(sashelp.citiwk,obs=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will generate this data step and show it in the log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.citiwk (label='Citibase weekly indicators: DEC85-JAN92');
  infile datalines dsd dlm='|' truncover;
  input DATE MF3505 TCJ WSPCA WSPUA WSPIA WSPGLT HFBI20 FF142B FCPOIL ;
  length DATE 7 ;
  format DATE weekdatx16. ;
  label DATE='Date of Observation'
    MF3505='MONEY STOCK:M1(CURRENCY+DEMAND DEP+OTHER'
    TCJ='INDUSTRIAL MATERIALS PRICE INDEX, 18 COM'
    WSPCA='STANDARD &amp;amp; POOR''S WEEKLY BOND YIELD: COM'
    WSPUA='STANDARD &amp;amp; POOR''S WEEKLY BOND YIELD: UTI'
    WSPIA='STANDARD &amp;amp; POOR''S WEEKLY BOND YIELD:INDU'
    WSPGLT='STANDARD &amp;amp; POOR;S WEEKLY BOND YIELD: GOV'
    HFBI20='BOND BUYERS INDEX: 20 BOND GENERAL OBLIG'
    FF142B='BOND YIELD:"A" UTILITY(RECENTLY OFFERED)'
    FCPOIL='PETROLEUM, REFINED OIL PRICES: FUEL OIL,'
  ;
datalines4;
9487|||10.4339999966323|10.5379999987781|10.3289999999105|9.23999999836087|8.32999999821186|10.5899999998509|0.76749999984167
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the INPUT statement will default the variable DATE to numeric.&amp;nbsp; Then the LENGTH statement will tell SAS to truncate DATE to 7 bytes when it writes it to the dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 04:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487630#M127086</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-17T04:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Re-Setting length of a variable after SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487636#M127087</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215463"&gt;@jimmychoi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi, here's my simple code that re-sets length of variable&amp;nbsp;'EmpID' after a SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data department;
input EmpID;
length EmpID 5;
datalines;
38284
47372
47372
93822
;
run;

data accounting;
set department;
length EmpID 6;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although original length of EmpID in department was 5, it changes to 6.&lt;/P&gt;
&lt;P&gt;I was told that if re-declaration of length of a variable occurs after a set statement, it gets ignored,&lt;/P&gt;
&lt;P&gt;since there is a preset length and data are already flowing in, line-by-line, by a SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I wrong? Well, at least from what I have found out in SAS 9.4, it seems I'm wrong&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why is EmpId numeric at all? Do you know that length of 5 does not mean, that only five digits can be stored in the variable? With a length of 6 the largest storable number is 2&lt;SUP&gt;37&lt;/SUP&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 05:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Setting-length-of-a-variable-after-SET-statement/m-p/487636#M127087</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-08-17T05:42:44Z</dc:date>
    </item>
  </channel>
</rss>

