<?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: importing files from different subdirectories and positional parameters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343152#M78751</link>
    <description>&lt;P&gt;IT WORKED!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its just that instead of naming the files test1 test2 ... I wanted to name them by their real names. But the thingis that for the "fourth file" I was getting 2 empty data sets, namely "fourth" and "file" - I guess that this is because of the empty space, so in case when there are empty spaces I just replaced them with underscores. I also added a variable in each file that will contan the file's name like this I can know which data came from which file. Here are the small modifications that I did:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_file(path, file_name, dataset_name );

	proc import 
		datafile="&amp;amp;path.\&amp;amp;file_name."
		dbms=xls
		out=&amp;amp;dataset_name replace;
	run;

data &amp;amp;dataset_name;
	set &amp;amp;dataset_name indsname=source;
dsname = scan(source,2,'.');
run;

       proc append base=master data=&amp;amp;dataset_name force;
       run;

       proc sql;
              drop table &amp;amp;dataset_name;
       quit;
     

%mend;

data list;
set list;
file_name = translate(trim(the_name),'_',' ');
run;

data _null_;
	set list;
string = catt('%import_file(', dir, ', ',  name,', ', file_name, ');');
/*string = catt('%import_file(', dir, ', ',  name,', ', catt('test', put(_n_, z2.)), ');');*/
	call execute (string);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks Reeza for the help!&lt;/P&gt;
&lt;P&gt;If you like, please put all your steps into one post (including the appending step) so that I can mark it as the solution!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 02:10:29 GMT</pubDate>
    <dc:creator>ilikesas</dc:creator>
    <dc:date>2017-03-22T02:10:29Z</dc:date>
    <item>
      <title>importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343041#M78697</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data table "list" which contains 2 variables: path (the full path of a fileincluding ame and extension; files can be in different subdirectories) and name (the name of the files, excluding extensions).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then create a macro list for each of the variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
 select path ,the_name
 into :path separated by ',',
 :the_name separated by ','
 from list;
 quit;&lt;/PRE&gt;
&lt;P&gt;Then I use these 2 macro lists in a macro that will import these files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro import_from_all_subdirectories(file_path,file_name);

 %let k=1;

    %let the_path= %scan(&amp;amp;file_path, &amp;amp;k);
	%let name= %scan(&amp;amp;file_name, &amp;amp;k);
%do %while("&amp;amp;the_path" NE "");

proc import 
    datafile='&amp;amp;the_path'
    dbms=xls
    out=&amp;amp;name;
    
run;



%let k = %eval(&amp;amp;k + 1);
    %let the_path = %scan(&amp;amp;the_path, &amp;amp;k);
    %let name = %scan(&amp;amp;name, &amp;amp;k);
%end;


%mend;

%import_from_all_subdirectories(&amp;amp;path,&amp;amp;the_name);
&lt;/PRE&gt;
&lt;P&gt;But I get an error message that "More positional parameters found than defined". Please help me slove this issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 19:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343041#M78697</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T19:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343051#M78704</link>
      <description>&lt;P&gt;Are all your files the same structure?&lt;/P&gt;
&lt;P&gt;If so, you don't need a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check your 'order of operations' inside your macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're trying to use macro variables that don't exist when calling the macro and they'll only exist within the macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 19:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343051#M78704</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T19:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343055#M78708</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use macro variables when I call the macro because these are the macro lists that I created (I assume I can use macro lists)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the structure of the files, what do you mean by that? They are all Excel files, but from different folders.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 19:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343055#M78708</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T19:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343058#M78709</link>
      <description>&lt;P&gt;File structure, a concept completely foreign to Excel, is that the variables in each column represent the same basic data a the same column in another file. Example: the first column in two different files is an ID value that is numeric, the second is the first name of a client and the third colum represents a last name. In the same order with similar characteristics, which for character values means that the maximum lengths of any value are at least similar, say 20 characters in one file and 24 in the other. Also the actual data starts on the same row in both files and if one has column headers the other should as well. The number of rows may differ as the main difference in file layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 20:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343058#M78709</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T20:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343062#M78711</link>
      <description>&lt;P&gt;In this sense my files have the same structure; they all have 2 varibales with the same type of data.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 20:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343062#M78711</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T20:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343064#M78713</link>
      <description>&lt;P&gt;This call using your macro variables created a shown will fail in almost every case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%import_from_all_subdirectories(&amp;amp;path,&amp;amp;the_name);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Reason: You define the macro with two parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values of your macro variables will have commas embedded because you use "separated by ',' "&lt;/P&gt;
&lt;P&gt;So the second value in the &amp;amp;path list will be treated by the macro processor as the second parameter and everything else after will be unrecognized parameters and generate the error: More positional parameters found then defined.&lt;/P&gt;
&lt;P&gt;Please see this example:&lt;/P&gt;
&lt;PRE&gt;%let parm = a, b, c;

%macro dummy (var);
%mend;

%dummy(&amp;amp;parm);&lt;/PRE&gt;
&lt;P&gt;So you probably should use " separated by ' '&amp;nbsp; " in building the parameter list in Proc Sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that passing commas in macro variables is a common problem causer.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 20:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343064#M78713</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T20:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343068#M78714</link>
      <description>&lt;P&gt;I did the appropriate change, but now I get another error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Physical file does not exist. C:\Documents and Setting\HP_Administrator\&amp;amp;the_path.xls&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for some reason it put the &amp;amp;the_path as the name of the file!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 20:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343068#M78714</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T20:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343076#M78718</link>
      <description>&lt;P&gt;The macro variable 'swallows' the period so you need 2 periods, one to denote the end of the macro variable and one for the extension.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;C:\Documents and Setting\HP_Administrator\&amp;amp;the_path..xls&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 21:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343076#M78718</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T21:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343087#M78723</link>
      <description>&lt;P&gt;In my original data I changed the variable path so that it includes the path up to .xls, and then in the macro I did:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datafile='&amp;amp;the_path&amp;amp;..xls'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and several other modifications, but it didn't work, I still get the message that the physical file doesn't exist&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 21:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343087#M78723</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T21:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343092#M78725</link>
      <description>&lt;P&gt;Are you running on a server version of SAS and trying to read files on your local harddrive? The server likely does not have a way of looking at your hard drive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343092#M78725</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T22:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343094#M78726</link>
      <description>&lt;P&gt;Make sure the file is named exactly as indicated, if you're on Unix the path may be case sensitive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you're not working on SAS server (ie EG/Studio), the server won't have access to your desktop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try a plain jane proc import with all values hardcoded, no macro variables or macro, and see if that works.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343094#M78726</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T22:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343096#M78728</link>
      <description>&lt;P&gt;The SAS is on my computer and so are all the files, and I can create a macro that imports all the files if they are in the same folder&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343096#M78728</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T22:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343099#M78731</link>
      <description>&lt;P&gt;The SAS is on my computer and so are the files. If all the files are in the same directory I can import them with a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, first I used a macro to extract all the file paths and names into a table, and from that table I want to get the paths into a another macro that will import those files. The file paths and names extraction macro is actually a solution to one of my other questions, here I put it in case it i sof interest:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro list_files(dir,ext);
  %local filrf rc did memcnt name i;
  %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
  %let did=%sysfunc(dopen(&amp;amp;filrf));      

   %if &amp;amp;did eq 0 %then %do; 
    %put Directory &amp;amp;dir cannot be open or does not exist;
    %return;
  %end;

   %do i = 1 %to %sysfunc(dnum(&amp;amp;did));   

   %let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

      %if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
        %put &amp;amp;dir\&amp;amp;name;

%let file_name =  %qscan(&amp;amp;name,1,.); 
%put &amp;amp;file_name;

        data _tmp;
          length dir $512 name $100 ;
          dir=symget("dir");
          name=symget("name");
		  path = catx('\',dir,name);
		 the_name = substr(name,1,find(name,'.')-1);
		
        run;
        proc append base=list data=_tmp force;
        run;quit;

      %end;
      %else %if %qscan(&amp;amp;name,2,.) = %then %do;        
        %list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
      %end;

   %end;
   %let rc=%sysfunc(dclose(&amp;amp;did));
   %let rc=%sysfunc(filename(filrf));     

%mend list_files;
%list_files(C:\Documents and Settings\HP_Administrator\Desktop\files,xls)&lt;/PRE&gt;
&lt;P&gt;"files" is the folder that contains the other folders that contain the xls files &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343099#M78731</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T22:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343100#M78732</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datafile='&amp;amp;the_path&amp;amp;..xls'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;P&gt;datafile= "&amp;amp;the_path&amp;amp;..xls"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;macro variables do not resolve within single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run your macro with option mprint symbolgen; to see the code generated an resolved.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343100#M78732</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T22:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343102#M78733</link>
      <description>&lt;P&gt;now it says that the data C:\Documents.xls doesn't exist, so it truncated the path to the first word&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343102#M78733</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T22:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343105#M78735</link>
      <description>&lt;P&gt;Yes, your scan function - why are you doing this? - doesn't make sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    %let the_path= %scan(&amp;amp;file_path, &amp;amp;k);
	%let name= %scan(&amp;amp;file_name, &amp;amp;k);&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343105#M78735</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T22:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343106#M78736</link>
      <description>&lt;P&gt;what I want to do here is with each iteration of k, extract the kth path from the list of paths and the kth name from the list of names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the kth proc import I imput the kth path to extract the file, and do out the kth name to give it that name in SAS&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 22:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343106#M78736</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T22:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343108#M78737</link>
      <description>&lt;P&gt;You've overly complicated this a bit in several places. If you're trying to import the file, why not specify the entire path than try to compile it? And when concatenating, you forgot the \ in as a spacer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, here's one way that works - tested it out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Import_all_files_one_type" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Import_all_files_one_type&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext);
	%local filrf rc did memcnt name i;
	%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
	%let did=%sysfunc(dopen(&amp;amp;filrf));

	%if &amp;amp;did eq 0 %then
		%do;
			%put Directory &amp;amp;dir cannot be open or does not exist;

			%return;
		%end;

	%do i = 1 %to %sysfunc(dnum(&amp;amp;did));
		%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

		%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then
			%do;
				%put &amp;amp;dir\&amp;amp;name;
				%let file_name =  %qscan(&amp;amp;name,1,.);
				%put &amp;amp;file_name;

				data _tmp;
					length dir $512 name $100;
					dir=symget("dir");
					name=symget("name");
					path = catx('\',dir,name);
					the_name = substr(name,1,find(name,'.')-1);
				run;

				proc append base=list data=_tmp force;
				run;

				quit;

				proc sql;
					drop table _tmp;
				quit;

			%end;
		%else %if %qscan(&amp;amp;name,2,.) = %then
			%do;
				%list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
			%end;
	%end;

	%let rc=%sysfunc(dclose(&amp;amp;did));
	%let rc=%sysfunc(filename(filrf));
%mend list_files;

%macro import_file(path, file_name, dataset_name );

	proc import 
		datafile="&amp;amp;path.\&amp;amp;file_name."
		dbms=xlsx
		out=&amp;amp;dataset_name replace;
	run;

%mend;

%list_files(c:\_localData\temp, xlsx);

data _null_;
	set list;
	string = catt('%import_file(', dir, ', ',  name,', ', catt('test', put(_n_, z2.)), ');');
	call execute (string);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 23:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343108#M78737</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T23:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343109#M78738</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;what I want to do here is with each iteration of k, extract the kth path from the list of paths and the kth name from the list of names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the kth proc import I imput the kth path to extract the file, and do out the kth name to give it that name in SAS&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But you don't have that in a macro list, you have that in a DATASET. You need to access the kth element of a data set, so you need to call the macro for each row.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 23:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343109#M78738</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T23:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: importing files from different subdirectories and positional parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343112#M78740</link>
      <description>&lt;P&gt;Thanks for the code Reeza!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a small question:&lt;/P&gt;
&lt;P&gt;when I was doing my previous code, I was hoping to append all the imported files together, and I wanted to do this within a macro in such a way that when a file is imported it is directly appended to the master data and then it is immediately erased - first importing all the files and then appending them all together might take a very long time if there are many files.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 23:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-files-from-different-subdirectories-and-positional/m-p/343112#M78740</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-03-21T23:29:00Z</dc:date>
    </item>
  </channel>
</rss>

