<?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: Append / combine data sets under a folder with source / contributing data sets identified in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270699#M53828</link>
    <description>&lt;P&gt;One aproach&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   Length dataset $ 41;
   set lib.file1 lib.file2 indsname=ds;
   dataset=ds;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The varaible referenced by indsname option will be a temporary variable so you need to create a permanent one to keep the value as assigned above in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use explicit dataset names as in the example or if you have similar names you could use a list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set lib.sales: indsname=ds; would get all data sets in the library that start with SALES in the name.&lt;/P&gt;
&lt;P&gt;Note that you my get warning about lengths of character variables different. The length of the first encountered set will be the length so truncation may be an issue. Also any variables with the same name must be of the same type. If VARX is numeric in one set and character in another this will fail (unless you rename the variable using dataset options).&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2016 14:27:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-05-16T14:27:28Z</dc:date>
    <item>
      <title>Append / combine data sets under a folder with source / contributing data sets identified</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270694#M53823</link>
      <description>&lt;P&gt;How do I go through a directory and combine datasets under it? &amp;nbsp;I also need to add a column / variable that identifies contributing&amp;nbsp;dataset (dataset name). &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 14:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270694#M53823</guid>
      <dc:creator>zz</dc:creator>
      <dc:date>2016-05-16T14:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Append / combine data sets under a folder with source / contributing data sets identified</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270697#M53826</link>
      <description>&lt;P&gt;The indsname option on set statement can be used to get dataset name:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have1 have2 have3 indsname=dsname;
run;
&lt;/PRE&gt;
&lt;P&gt;You can use the set to append datasets. &amp;nbsp;Proc append can also be used. &amp;nbsp;You could also do union all in proc sql. &amp;nbsp;They all have their pluses and negatives so check out the manual.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 14:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270697#M53826</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-16T14:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Append / combine data sets under a folder with source / contributing data sets identified</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270699#M53828</link>
      <description>&lt;P&gt;One aproach&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   Length dataset $ 41;
   set lib.file1 lib.file2 indsname=ds;
   dataset=ds;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The varaible referenced by indsname option will be a temporary variable so you need to create a permanent one to keep the value as assigned above in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use explicit dataset names as in the example or if you have similar names you could use a list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set lib.sales: indsname=ds; would get all data sets in the library that start with SALES in the name.&lt;/P&gt;
&lt;P&gt;Note that you my get warning about lengths of character variables different. The length of the first encountered set will be the length so truncation may be an issue. Also any variables with the same name must be of the same type. If VARX is numeric in one set and character in another this will fail (unless you rename the variable using dataset options).&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 14:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270699#M53828</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-16T14:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Append / combine data sets under a folder with source / contributing data sets identified</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270764#M53842</link>
      <description>&lt;P&gt;Thanks for your input, ballardw!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tested out the code with below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LIBNAME dt '/data';&lt;BR /&gt;LIBNAME rs '/results';&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt; SELECT memname into : names&lt;BR /&gt; FROM dictionary.tables&lt;BR /&gt; WHERE libname='DT'&lt;BR /&gt; ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA RS.combined;&lt;BR /&gt; LENGTH dataset $ 41;&lt;BR /&gt; SET DT.&amp;amp;names indsname=ds;&lt;BR /&gt; dataset=ds;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It created dataset that only included the first dataset 'ae' under 'DT' as source, with variable 'dataset having value 'DT.ae'. &amp;nbsp;There are about 30 some datasets under 'DT'. &amp;nbsp;How would I improve the above, so it includes all dataset&amp;nbsp;in the 'combined' dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 19:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270764#M53842</guid>
      <dc:creator>zz</dc:creator>
      <dc:date>2016-05-16T19:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Append / combine data sets under a folder with source / contributing data sets identified</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270803#M53852</link>
      <description>&lt;P&gt;First you need to look at the results of %put &amp;amp;names;&lt;/P&gt;
&lt;P&gt;Second, you would have had only one reference to the libname.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Warning: &lt;/STRONG&gt;writing into the same library can result in appending the same datasets multiple times if you keep running the code as the second time you will get ds.combined appended (and some corresponding issues about the value of the indsname variable)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easier to create the libname.datasetname construct when you select it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select catt(libname,'.',memname) into : Names separated by ' '
   from dictionary.tables
   where libname='DT' and memtype='DATA';
quit;

%put &amp;amp;names;    /* so you see what the names are*/
data rs.combined;
   length dataset $ 41;
   set &amp;amp;names indsname;
   dataset=ds;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if your goal was to combine the sets in DS and DT then use this for the SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select catt(libname,'.',memname) into : Names separated by ' '
   from dictionary.tables
   where libname in ('DT','DS') and memtype='DATA';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 22:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270803#M53852</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-16T22:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Append / combine data sets under a folder with source / contributing data sets identified</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270900#M53878</link>
      <description>&lt;P&gt;Try the one step approach:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="DT")) end=last;
  if _n_=1 then call execute('data final; length dataset $100; set ');
  call execute(cat(' ',strip(name));
  if last the call execute(' indsname=ds; dataset=ds; run;');
run;&lt;/PRE&gt;
&lt;P&gt;Basically the sashelp.vtable is pulled in, filetering on the where clause. &amp;nbsp;On first record the datastep part is written out, then for each obs returned that is written out and on the final record the datastep is closed, and then that whole code block is run. &amp;nbsp;You can aplpy any manipulations to it you want.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 08:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-combine-data-sets-under-a-folder-with-source-contributing/m-p/270900#M53878</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-17T08:36:40Z</dc:date>
    </item>
  </channel>
</rss>

