<?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: keep variable order when using length statement to merge data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251576#M47565</link>
    <description>&lt;P&gt;you are right. The order of the variables only matters in final report.&lt;/P&gt;
&lt;P&gt;I care it only because I have been used to the format, "visual effect" to my self.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as for the "merge" term, yes, this is a set operation (concatenation, like union in proc sql), not the speficially used merge term, which is like proc sql join. Thank you for the clarification.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2016 16:34:37 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-02-22T16:34:37Z</dc:date>
    <item>
      <title>keep variable order when using length statement to merge data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251572#M47562</link>
      <description>&lt;P&gt;I have several data sets and want to merge them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all7;
length  company $12.;
set demo_1 demo_2 demo_3 demo_4 demo_5 demo_6 demo_7;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The company is the last variable in all the 7 data sets to be merged, but it has different lengths in them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I use length statement to set them to the same length, the variable becomes the first one in the merged data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to work around is to set the length in all the 7 data sets first before merging. I wonder if there is a way during merge.&lt;/P&gt;
&lt;P&gt;thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 16:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251572#M47562</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-02-22T16:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: keep variable order when using length statement to merge data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251574#M47564</link>
      <description>First this is an append/set operation not merge (which is similar to a SQL join).&lt;BR /&gt;&lt;BR /&gt;What is the problem with variable order? It's just a physical thing. You usually only need to care about variable order in reports. &lt;BR /&gt;&lt;BR /&gt;But, to answer your question, the only way I see is to declare all variables in a length. Or if you know which data set that has the appropriate length set that as first data set, or set it twice (the first time with obs=0) if you need to have a specific observation order.</description>
      <pubDate>Mon, 22 Feb 2016 16:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251574#M47564</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-02-22T16:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: keep variable order when using length statement to merge data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251576#M47565</link>
      <description>&lt;P&gt;you are right. The order of the variables only matters in final report.&lt;/P&gt;
&lt;P&gt;I care it only because I have been used to the format, "visual effect" to my self.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as for the "merge" term, yes, this is a set operation (concatenation, like union in proc sql), not the speficially used merge term, which is like proc sql join. Thank you for the clarification.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 16:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251576#M47565</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-02-22T16:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: keep variable order when using length statement to merge data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251577#M47566</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56807"&gt;@fengyuwuzu﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp;mentioned the solution already: set a dataset twice.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all7;
if 0 then set demo_1(drop=company); /* creates the PDV without COMPANY */
length company $12;
set demo_1 demo_2 demo_3 demo_4 demo_5 demo_6 demo_7;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above code assumes that all 7 datasets have the same variables. Otherwise, you could include more datasets into the first SET statement (which is never executed due to the IF condition).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: This was also inspired by &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Converting-Missing-Values-with-a-macro/m-p/250304#M35938" target="_blank"&gt;this recent post&lt;/A&gt; from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;,&amp;nbsp;who used&amp;nbsp;this technique to prepare an array definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 17:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251577#M47566</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-22T17:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: keep variable order when using length statement to merge data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251578#M47567</link>
      <description>Thank you so much, FreelanceReinhard. &lt;BR /&gt;Your code is so clear. Thanks!!</description>
      <pubDate>Mon, 22 Feb 2016 16:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-variable-order-when-using-length-statement-to-merge-data/m-p/251578#M47567</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-02-22T16:39:07Z</dc:date>
    </item>
  </channel>
</rss>

