<?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: Create a macro for loading multiple files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706275#M216760</link>
    <description>Thank you! it works very well!</description>
    <pubDate>Wed, 16 Dec 2020 10:41:42 GMT</pubDate>
    <dc:creator>MCB1</dc:creator>
    <dc:date>2020-12-16T10:41:42Z</dc:date>
    <item>
      <title>Create a macro for loading multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706233#M216742</link>
      <description>&lt;P&gt;Hello, I need to create a macro that processes data files stored in different folders. The structure for storage of the files and their filenames are the same. The files are large&amp;nbsp; and havmillions of observations and many variables. I have a solution if i copy all the files I need and paste them into the same folder. I prefer to avoid doing that. I would like to reach the original folder for each file with a macro. The output I need is a file for each iteration in the makro. Here is&amp;nbsp;av very simple&amp;nbsp;example of the data I have and what I want to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets corresponding to data for 2018:&lt;/P&gt;&lt;P&gt;data dm18ir18;&lt;/P&gt;&lt;P&gt;input ID Inc;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;4 25&lt;/P&gt;&lt;P&gt;5 40&lt;/P&gt;&lt;P&gt;6 55&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dm18vm18;&lt;/P&gt;&lt;P&gt;input ID weight;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;4 2&lt;/P&gt;&lt;P&gt;5 3&lt;/P&gt;&lt;P&gt;6 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two datasets corresponding to data for 2017:&lt;/P&gt;&lt;P&gt;data dm17ir17;&lt;/P&gt;&lt;P&gt;input ID Inc;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;25&lt;/P&gt;&lt;P&gt;2&amp;nbsp;40&lt;/P&gt;&lt;P&gt;3&amp;nbsp;55&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data dm17vm17;&lt;/P&gt;&lt;P&gt;input ID weight;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;2&lt;/P&gt;&lt;P&gt;2&amp;nbsp;3&lt;/P&gt;&lt;P&gt;3 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;If these files are stored in the same folder :&lt;/P&gt;&lt;P&gt;libname c 'd:\sasdata\test';&lt;/P&gt;&lt;P&gt;then a solution that works is&amp;nbsp;the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test(year);&lt;/P&gt;&lt;P&gt;data want&amp;amp;year;&lt;/P&gt;&lt;P&gt;merge c.dm&amp;amp;year.ir&amp;amp;year&amp;nbsp; c.dm&amp;amp;year.vm&amp;amp;year&amp;nbsp;;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test(17)&lt;/P&gt;&lt;P&gt;%test (18);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results in this case are two files : want17 and want18.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I do not copy the files to a new folder as assumed above, the data would be in the following original folders:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'D:\sasdata\test\year17\V4'&amp;nbsp;&amp;nbsp; (many files corresponding data för 2017)&lt;/P&gt;&lt;P&gt;''D:\sasdata\test\year18\V4'&amp;nbsp;&amp;nbsp;&amp;nbsp;(many files corresponding data för 2018)&lt;/P&gt;&lt;P&gt;I still want to create two files (want17 and want18) but by using the original stored files in stead of copying them into the same folder. Thank You!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 07:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706233#M216742</guid>
      <dc:creator>MCB1</dc:creator>
      <dc:date>2020-12-16T07:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro for loading multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706236#M216744</link>
      <description>&lt;P&gt;The problem is not clear: you need a macro for reading files or a macro merging datasets?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 08:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706236#M216744</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-16T08:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro for loading multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706238#M216745</link>
      <description>&lt;P&gt;Add a LIBNAME to your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(year);

libname inlib "D:\sasdata\test\year&amp;amp;year.\V4";

data want&amp;amp;year;
merge
  inlib.dm&amp;amp;year.ir&amp;amp;year
  inlib.dm&amp;amp;year.vm&amp;amp;year
;
by ID;
run;

libname inlib clear;

%mend;

%test(17)
%test(18)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Dec 2020 08:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706238#M216745</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-16T08:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro for loading multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706243#M216750</link>
      <description>&lt;P&gt;You can define a library that points to multiple folders. An example would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Libname mult ("C:\thisfolder\thatfolder" "C:\thisfolder\otherfolder" "C:\thisfolder\differentfolder");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as none of the individual data set names are duplicated then there shouldn't be any problems with specific names.&lt;/P&gt;
&lt;P&gt;From the example that you show then you may combine all of these data sets with something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; merge mult.dm: ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;I say may as there are some issues. The list of data sets resulting from the DM: (yes that colon is important) will attempt to use all of the datasets in the library whose name starts with DM.&lt;/P&gt;
&lt;P&gt;Second issue: every single variable with a common name must be of the same type. And if variables are character you may have issues with lengths of commonly named variables if the length is not the same in each data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really having a hard time understanding you placed the year in data set names twice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 08:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706243#M216750</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T08:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro for loading multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706275#M216760</link>
      <description>Thank you! it works very well!</description>
      <pubDate>Wed, 16 Dec 2020 10:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706275#M216760</guid>
      <dc:creator>MCB1</dc:creator>
      <dc:date>2020-12-16T10:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro for loading multiple files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706276#M216761</link>
      <description>Thank you! I have got a suggestion that works very well:&lt;BR /&gt;&lt;BR /&gt;%macro test(year);&lt;BR /&gt;libname inlib "D:\sasdata\test\year&amp;amp;year.\V4";&lt;BR /&gt;data want&amp;amp;year;&lt;BR /&gt;merge&lt;BR /&gt;inlib.dm&amp;amp;year.ir&amp;amp;year&lt;BR /&gt;inlib.dm&amp;amp;year.vm&amp;amp;year&lt;BR /&gt;;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;BR /&gt;libname inlib clear;&lt;BR /&gt;%mend;&lt;BR /&gt;%test(17)&lt;BR /&gt;%test(18);</description>
      <pubDate>Wed, 16 Dec 2020 10:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-for-loading-multiple-files/m-p/706276#M216761</guid>
      <dc:creator>MCB1</dc:creator>
      <dc:date>2020-12-16T10:44:21Z</dc:date>
    </item>
  </channel>
</rss>

