<?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: question about length statement in merge data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744690#M233328</link>
    <description>&lt;P&gt;Thanks for your reply. What would be an example of a proper way to create the data with a name variable length of 20 when merging?&lt;/P&gt;</description>
    <pubDate>Sun, 30 May 2021 17:11:05 GMT</pubDate>
    <dc:creator>jcrepper</dc:creator>
    <dc:date>2021-05-30T17:11:05Z</dc:date>
    <item>
      <title>question about length statement in merge data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744674#M233315</link>
      <description>&lt;P&gt;While studying for base exam I encountered this question. I had thought that the length statement before the merge step would allow for a character length to be set for a variable. Not sure why the question does not reflect that. Am I missing something?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="length question sas.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59898i8810A8C1FD20C4E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="length question sas.png" alt="length question sas.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 15:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744674#M233315</guid>
      <dc:creator>jcrepper</dc:creator>
      <dc:date>2021-05-30T15:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: question about length statement in merge data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744679#M233318</link>
      <description>&lt;P&gt;The length statement does indeed create a variable with a length of $20, but that alone is not enough because the format is empty.&lt;/P&gt;
&lt;P&gt;The subsequent merge statement will reflect the $CHAR15. format of the sales dataset to be read first.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You can see this by executing the following steps.&lt;BR /&gt;The variable a in dataset TEST1 has an empty format, and the variable a in dataset TEST2 has a format of date9..&lt;BR /&gt;As shown in results1, only when the format is empty, the format to be read later will be reflected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
  a=1;x=3;
run;
data test2;
  a=1;y=2;
  format a date9.;
run;
data results1;
  merge test1 test2;
  by a;
run;
proc print noobs;
run;


data test3;
  a=100000;x=3;
  format a time5.;
run;
data test4;
  a=100000;y=2;
  format a time8.;
run;
data results2;
  merge test3 test4;
  by a;
run;
proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 May 2021 15:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744679#M233318</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-05-30T15:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: question about length statement in merge data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744685#M233324</link>
      <description>&lt;P&gt;Which FORMAT specification to permanently attach to a variable is a totally separate attribute of a variable than the LENGTH of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just because you defined the variable be character with a length of 20 does not prevent you from using any of the formats listed in the question and answer with that variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because the data step does not explicit attach any format specification the data step compiler will use the first non empty setting that it sees.&amp;nbsp; In this case it is the format attached to the variable in the SALES dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 17:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744685#M233324</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-30T17:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: question about length statement in merge data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744690#M233328</link>
      <description>&lt;P&gt;Thanks for your reply. What would be an example of a proper way to create the data with a name variable length of 20 when merging?&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 17:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744690#M233328</guid>
      <dc:creator>jcrepper</dc:creator>
      <dc:date>2021-05-30T17:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: question about length statement in merge data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744693#M233330</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191852"&gt;@jcrepper&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply. What would be an example of a proper way to create the data with a name variable length of 20 when merging?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why would you do anything different than what the posted code?&lt;BR /&gt;If you want to remove the format from name use a format statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data both;
  length name $20 ;
  set sales employee;
  by id;
  format name ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A FORMAT in SAS is special instructions for how to print the data.&amp;nbsp; SAS does not need any special instructions for how to print character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 17:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744693#M233330</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-30T17:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: question about length statement in merge data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744696#M233332</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191852"&gt;@jcrepper&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply. What would be an example of a proper way to create the data with a name variable length of 20 when merging?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The variable&amp;nbsp;&lt;U&gt;is&lt;/U&gt; created with a&amp;nbsp;&lt;EM&gt;length&lt;/EM&gt; of 20, but only 15 characters are&amp;nbsp;&lt;EM&gt;displayed&lt;/EM&gt; because of the format inherited from the first dataset.&lt;/P&gt;
&lt;P&gt;Use a separate FORMAT statement to either remove any format, or set the format to CHAR20.&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 18:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-length-statement-in-merge-data-step/m-p/744696#M233332</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-30T18:35:59Z</dc:date>
    </item>
  </channel>
</rss>

