<?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: Merge all the tables of Library in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Merge-all-the-tables-of-Library/m-p/134373#M36487</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, its a bit vague but what you will need to do is to get a list from SASHELP.VTABLE with a where clause of your libname.&amp;nbsp; This will give you a list of the datasets in that libname.&amp;nbsp; You can then use that call execute a macro which will sort and merge that onto a base table.&amp;nbsp; E.g&lt;/P&gt;&lt;P&gt;%macro add (ds);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort data=&amp;amp;ds. out=temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by idvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data base;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge base temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by idvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%mend add;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data list_of_tables (keep=libname memname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.vtable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="WORK";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data base; set '||strip(libname)||"."||strip(memname)||'; run;'); /* This takes the first dataset as the base */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else call execute('%add('||strip(libname)||"."||strip(memname)||';');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course this assumes a lot of things - datasets are the same, have the same idvar, there is more than 1 etc.&amp;nbsp; You could build an SQL statement using call execute, this is limited to 256 tables though.&amp;nbsp; As for you coalesce, well, in the merge I would rename the temp variables, and then compare.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Jun 2014 11:07:02 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-06-09T11:07:02Z</dc:date>
    <item>
      <title>Merge all the tables of Library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-all-the-tables-of-Library/m-p/134372#M36486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have some kind of weird requirement, but have to fulfill. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to merge all the tables of the library. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I don't know how many tables will be available.&lt;/P&gt;&lt;P&gt;2. Table structure for all the tables in library is same. &lt;/P&gt;&lt;P&gt;3. I want to use coalesce function to find out which is the non-missing variable and that value I have to pick up for a variable of output dataset.&lt;/P&gt;&lt;P&gt;4. Yes, key is same. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone please help at earliest?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Hatshit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 10:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-all-the-tables-of-Library/m-p/134372#M36486</guid>
      <dc:creator>skygold16</dc:creator>
      <dc:date>2014-06-09T10:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merge all the tables of Library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-all-the-tables-of-Library/m-p/134373#M36487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, its a bit vague but what you will need to do is to get a list from SASHELP.VTABLE with a where clause of your libname.&amp;nbsp; This will give you a list of the datasets in that libname.&amp;nbsp; You can then use that call execute a macro which will sort and merge that onto a base table.&amp;nbsp; E.g&lt;/P&gt;&lt;P&gt;%macro add (ds);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort data=&amp;amp;ds. out=temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by idvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data base;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge base temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by idvar;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%mend add;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data list_of_tables (keep=libname memname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.vtable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="WORK";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('data base; set '||strip(libname)||"."||strip(memname)||'; run;'); /* This takes the first dataset as the base */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else call execute('%add('||strip(libname)||"."||strip(memname)||';');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course this assumes a lot of things - datasets are the same, have the same idvar, there is more than 1 etc.&amp;nbsp; You could build an SQL statement using call execute, this is limited to 256 tables though.&amp;nbsp; As for you coalesce, well, in the merge I would rename the temp variables, and then compare.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 11:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-all-the-tables-of-Library/m-p/134373#M36487</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-09T11:07:02Z</dc:date>
    </item>
  </channel>
</rss>

