<?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 appending the library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612620#M178805</link>
    <description>&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;hello&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;I have a library called new which has 50 datasets.one of the dataset name is class&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;dataset class has 5 variables and 10 observations&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Similarly we have other datasets which have some variables and observations&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Now we have another library called old which also has 50 datasets with same name that we have in library new&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;I want to to append both the library datasets since they have same dataset name and variables&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;once way to acheive is write proc append like this for all the daatsest&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;proc append base=new.class data=old.class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;But what we need to do when we have 200 libraries and each library contain 10 to 15 datasets&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;what is the code that I can write other than proc append to acheive this ?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2019 11:55:38 GMT</pubDate>
    <dc:creator>shubham1</dc:creator>
    <dc:date>2019-12-18T11:55:38Z</dc:date>
    <item>
      <title>appending the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612620#M178805</link>
      <description>&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;hello&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;I have a library called new which has 50 datasets.one of the dataset name is class&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;dataset class has 5 variables and 10 observations&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Similarly we have other datasets which have some variables and observations&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Now we have another library called old which also has 50 datasets with same name that we have in library new&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;I want to to append both the library datasets since they have same dataset name and variables&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;once way to acheive is write proc append like this for all the daatsest&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;proc append base=new.class data=old.class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;But what we need to do when we have 200 libraries and each library contain 10 to 15 datasets&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;what is the code that I can write other than proc append to acheive this ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 11:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612620#M178805</guid>
      <dc:creator>shubham1</dc:creator>
      <dc:date>2019-12-18T11:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: appending the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612622#M178806</link>
      <description>&lt;P&gt;First, create a dataset that contains the library and dataset names.&lt;/P&gt;
&lt;P&gt;Then use call execute off that dataset to dynamically create data steps that create the target dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=datasets;
by dsname;
run;

data _null_;
set datasets;
by dsname;
if first.dsname then call execute("data &amp;amp;targetlib.."!!strip(dsname)"!!;set");
call execute(" "!!strip(dsname));
if last.dsname then call execute(";run;");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 12:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612622#M178806</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-18T12:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: appending the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612691#M178817</link>
      <description>&lt;P&gt;Is the goal to combine the approximately 200 times 15 datasets into 15 datasets?&amp;nbsp; Or did you have some other goal?&amp;nbsp; Do you have the list of datasets in a dataset you can use to generate the code you need? 200 is a lot of librefs to actively use.&amp;nbsp; Most likely once this consolidation is done you will not need to reference the individual datasets anymore.&amp;nbsp; Note that SAS syntax can actually reference the files used to store datasets directly without first creating a libref for each individual directory.&amp;nbsp; You just need to use the physical filename in quotes instead of the libref.memname syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first get your list of datasets into a single dataset.&amp;nbsp; It will probably look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files ;
  infile cards truncover;
  input filename $256. ;
cards;
/dir1/ds1.sas7bdat
/dir1/ds2.sas7bdat
/dir2/ds1.sas7bdat
/dir3/ds2.sas7bdat
/dir4/ds1.sas7bdat
/dir4/ds2.sas7bdat
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can probably use some operating system command, like DIR (windows), or FIND (unix) to get the list for you without typing them into in-line data in your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you probably want to add a variable that indicates the name of the target dataset.&amp;nbsp; So in the example above there are various combinations of 2 dataset names across 4 directories.&amp;nbsp; So perhaps you want to create two output datasets using those two distinct memnames.&amp;nbsp; So sort the data by the target name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files;
  set files;
  length memname $32 ;
  memname = scan(filename,-2,'./');
run;

proc sort data=files;
  by memname filename ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use that to generate code to combine the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp ;
data _null_;
  set files ;
  by memname ;
  file code lrecl=100;
  if first.memname then put 
    'data ' memname ';' 
  / '  set ' @ 
  ;
  put filename :$quote. @ ;
  if last.memname then put
    ';'
  / 'run;'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will make these lines of code in the file CODE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1 ;
  set "/dir1/ds1.sas7bdat" "/dir2/ds1.sas7bdat" "/dir4/ds1.sas7bdat" ;
run;
data ds2 ;
  set "/dir1/ds2.sas7bdat" "/dir3/ds2.sas7bdat" "/dir4/ds2.sas7bdat" ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you can run by using %INCLUDE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 15:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/appending-the-library/m-p/612691#M178817</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-18T15:07:24Z</dc:date>
    </item>
  </channel>
</rss>

