<?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: how to use macro to sort multiple datasets then to merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282314#M57369</link>
    <description>&lt;P&gt;With 4 datasets shown (and with 7 possibly implied by the day of the week name) I wouldn't bother to go to any macro to sort the data&amp;nbsp;but they do need to be sorted before merging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2016 22:49:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-07-05T22:49:05Z</dc:date>
    <item>
      <title>how to use macro to sort multiple datasets then to merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282203#M57324</link>
      <description>&lt;P&gt;I have multiple datasets to merge but first I need to sort by id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there an efficient way to use macro to do this? And to keep index so that I can see which record from which previous dataset?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 16:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282203#M57324</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-07-05T16:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro to sort multiple datasets then to merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282256#M57337</link>
      <description>&lt;P&gt;How many is "many datasets"? Are they named in anyway that they are amenable to simple loop processing such as set1, set2, set3, ...setn?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By "keep index" do you mean a way to know if the resulting data set had contributions from different datasets?&lt;/P&gt;
&lt;P&gt;If so here is one example using the IN dataset option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.one;
   input id;
datalines;
1
3
5
10
;

data work.two;
   input id;
datalines;
2
3
5
;
run;

data work.merged;
   merge
      work.one (in=one)
      work.two (in=two)
   ;
   by id;
   InOne=one;
   InTwo=two;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The final data set has a variable that has a value of one indicating that the given dataset contributed and zero otherwise. Since you have multiple datasets that may contribute to any given ID result then one variable per dataset. Notice that for the Id values of 1 and 10&amp;nbsp;that InOne is 1 and InTwo is 0. So only dataset work.one contributed to the result. For Id 3 and 5 both InOne and InTwo are 1 indicating both of the sets contributed. And for Id two only work.two contributed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 19:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282256#M57337</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-05T19:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro to sort multiple datasets then to merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282263#M57339</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;There is an error message below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: BY variables are not properly sorted on data set Ie.tue.&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of&lt;/P&gt;&lt;P&gt;errors.&lt;/P&gt;&lt;P&gt;NOTE: There were 282812 observations read from the data set&lt;/P&gt;&lt;P&gt;Ie.mon.&lt;/P&gt;&lt;P&gt;NOTE: There were 12205 observations read from the data set&lt;/P&gt;&lt;P&gt;Ie.tue.&lt;/P&gt;&lt;P&gt;NOTE: There were 12161 observations read from the data set&lt;/P&gt;&lt;P&gt;Ie.wed.&lt;/P&gt;&lt;P&gt;NOTE: There were 9858 observations read from the data set&lt;/P&gt;&lt;P&gt;Ie.thu.&lt;/P&gt;&lt;P&gt;WARNING: The data set Ie.MERGED may be incomplete. When this&lt;/P&gt;&lt;P&gt;step was stopped there were 302460 observations and&lt;/P&gt;&lt;P&gt;242 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 19:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282263#M57339</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-07-05T19:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro to sort multiple datasets then to merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282314#M57369</link>
      <description>&lt;P&gt;With 4 datasets shown (and with 7 possibly implied by the day of the week name) I wouldn't bother to go to any macro to sort the data&amp;nbsp;but they do need to be sorted before merging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 22:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282314#M57369</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-05T22:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro to sort multiple datasets then to merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282366#M57383</link>
      <description>Or store the data in a SPDE libref which will remove the need for pre sorting  (it will be sorted implicitly when the data set encounter a BY statement).</description>
      <pubDate>Wed, 06 Jul 2016 08:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282366#M57383</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-07-06T08:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro to sort multiple datasets then to merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282411#M57396</link>
      <description>&lt;P&gt;Thanks. Would you please provide a sample code for this?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 13:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-to-sort-multiple-datasets-then-to-merge/m-p/282411#M57396</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-07-06T13:19:32Z</dc:date>
    </item>
  </channel>
</rss>

