<?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  and format not coming correct in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590146#M168867</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127952"&gt;@shubham1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code was running on host SAS&lt;/P&gt;
&lt;PRE&gt;data long;
  length name $ 8;
  format name $8.;
  infile datalines dsd;
  input name;
datalines4;
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
;;;;
run; 
 
data short;
  length name $ 4;
  format name $4.;
  infile datalines dsd;
  input name;
datalines4;
eeee
ffff
gggg
hhhh
;;;;
run;
 
data longfirst;
  set long short;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;when this code was running on SAS Host&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;dataset longfirst has variable name with length 8 and format $8.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name&lt;/P&gt;
&lt;P&gt;aaaaaaaa&lt;/P&gt;
&lt;P&gt;bbbbbbbb&lt;/P&gt;
&lt;P&gt;cccccccc&lt;/P&gt;
&lt;P&gt;dddddddd&lt;/P&gt;
&lt;P&gt;eeee&lt;/P&gt;
&lt;P&gt;ffff&lt;/P&gt;
&lt;P&gt;gggg&lt;/P&gt;
&lt;P&gt;hhhh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;But when I am running the same code on SAS 9.4 on windows&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;dataset longfirst has output with variable name has&amp;nbsp; length 8 and format $4.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;name&amp;nbsp;&lt;/P&gt;
&lt;P&gt;aaaa&lt;/P&gt;
&lt;P&gt;bbbb&lt;/P&gt;
&lt;P&gt;cccc&lt;/P&gt;
&lt;P&gt;dddd&lt;/P&gt;
&lt;P&gt;eeee&lt;/P&gt;
&lt;P&gt;ffff&lt;/P&gt;
&lt;P&gt;gggg&lt;/P&gt;
&lt;P&gt;hhhh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is when i am running the same code on windows why variable name has format $4. due to which output data is not showing correct ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show the exact code as run &lt;STRONG&gt;copied from the log with any messages&lt;/STRONG&gt;. You describe for your Windows run what would happen with :&lt;/P&gt;
&lt;PRE&gt;data longfirst;
  set  short long;
run;&lt;/PRE&gt;
&lt;P&gt;I ran your code on a Windows stand alone SAS install and Name is length 8 with format $8.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2019 18:00:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-09-19T18:00:26Z</dc:date>
    <item>
      <title>length  and format not coming correct</title>
      <link>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590118#M168859</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below code was running on host SAS&lt;/P&gt;&lt;PRE&gt;data long;
  length name $ 8;
  format name $8.;
  infile datalines dsd;
  input name;
datalines4;
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
;;;;
run; 
 
data short;
  length name $ 4;
  format name $4.;
  infile datalines dsd;
  input name;
datalines4;
eeee
ffff
gggg
hhhh
;;;;
run;
 
data longfirst;
  set long short;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;when this code was running on SAS Host&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;dataset longfirst has variable name with length 8 and format $8.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&lt;/P&gt;&lt;P&gt;aaaaaaaa&lt;/P&gt;&lt;P&gt;bbbbbbbb&lt;/P&gt;&lt;P&gt;cccccccc&lt;/P&gt;&lt;P&gt;dddddddd&lt;/P&gt;&lt;P&gt;eeee&lt;/P&gt;&lt;P&gt;ffff&lt;/P&gt;&lt;P&gt;gggg&lt;/P&gt;&lt;P&gt;hhhh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But when I am running the same code on SAS 9.4 on windows&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;dataset longfirst has output with variable name has&amp;nbsp; length 8 and format $4.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name&amp;nbsp;&lt;/P&gt;&lt;P&gt;aaaa&lt;/P&gt;&lt;P&gt;bbbb&lt;/P&gt;&lt;P&gt;cccc&lt;/P&gt;&lt;P&gt;dddd&lt;/P&gt;&lt;P&gt;eeee&lt;/P&gt;&lt;P&gt;ffff&lt;/P&gt;&lt;P&gt;gggg&lt;/P&gt;&lt;P&gt;hhhh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is when i am running the same code on windows why variable name has format $4. due to which output data is not showing correct ?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 17:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590118#M168859</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2019-09-19T17:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: length  and format not coming correct</title>
      <link>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590146#M168867</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127952"&gt;@shubham1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code was running on host SAS&lt;/P&gt;
&lt;PRE&gt;data long;
  length name $ 8;
  format name $8.;
  infile datalines dsd;
  input name;
datalines4;
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
;;;;
run; 
 
data short;
  length name $ 4;
  format name $4.;
  infile datalines dsd;
  input name;
datalines4;
eeee
ffff
gggg
hhhh
;;;;
run;
 
data longfirst;
  set long short;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;when this code was running on SAS Host&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;dataset longfirst has variable name with length 8 and format $8.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name&lt;/P&gt;
&lt;P&gt;aaaaaaaa&lt;/P&gt;
&lt;P&gt;bbbbbbbb&lt;/P&gt;
&lt;P&gt;cccccccc&lt;/P&gt;
&lt;P&gt;dddddddd&lt;/P&gt;
&lt;P&gt;eeee&lt;/P&gt;
&lt;P&gt;ffff&lt;/P&gt;
&lt;P&gt;gggg&lt;/P&gt;
&lt;P&gt;hhhh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;But when I am running the same code on SAS 9.4 on windows&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;dataset longfirst has output with variable name has&amp;nbsp; length 8 and format $4.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;name&amp;nbsp;&lt;/P&gt;
&lt;P&gt;aaaa&lt;/P&gt;
&lt;P&gt;bbbb&lt;/P&gt;
&lt;P&gt;cccc&lt;/P&gt;
&lt;P&gt;dddd&lt;/P&gt;
&lt;P&gt;eeee&lt;/P&gt;
&lt;P&gt;ffff&lt;/P&gt;
&lt;P&gt;gggg&lt;/P&gt;
&lt;P&gt;hhhh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is when i am running the same code on windows why variable name has format $4. due to which output data is not showing correct ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show the exact code as run &lt;STRONG&gt;copied from the log with any messages&lt;/STRONG&gt;. You describe for your Windows run what would happen with :&lt;/P&gt;
&lt;PRE&gt;data longfirst;
  set  short long;
run;&lt;/PRE&gt;
&lt;P&gt;I ran your code on a Windows stand alone SAS install and Name is length 8 with format $8.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 18:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590146#M168867</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-19T18:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: length  and format not coming correct</title>
      <link>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590206#M168878</link>
      <description>&lt;P&gt;The result you explain is not possible. Please check what you have done.&lt;/P&gt;
&lt;P&gt;When you are setting multiple datasets together like that the first place SAS sees the variable will determine the variables type (and length).&amp;nbsp; The first place where there is a non-empty format attached will determine what format is attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you must have done this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
  length x $8 ;
run;
data short;
  length x $4 ;
  format x $4. ;
run;

data long_short ;
  set long short ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of what you described.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is why I recommend to NOT attach $ format to any character variables. And rant at posters that use FORMAT statement as if it was intended to DEFINE the variables. The FORMAT statement is for attaching a default format to use when display a variable. It will only define the variable as a side effect when it is the first place that the compiler sees the variable referenced.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 21:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/length-and-format-not-coming-correct/m-p/590206#M168878</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-19T21:07:46Z</dc:date>
    </item>
  </channel>
</rss>

