<?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: Issue with importing all excel files in folders in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497724#M132026</link>
    <description>&lt;P&gt;First off, why is the data in Excel - this is a really bad format for data, and if your using linux will mean that you need to use pcfiles server of something like that to even use it.&amp;nbsp; Bin that format as quick as possible and move to open file formats such as csv or xml and your life will be a lot easier, for instance, if these were csv files you could read them all in in one step (assuming structure is the same throughout).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now with your question here, #&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Directory /sasdata/source/tnbt/Profile_List_Files/Central/ABBA/ cannot be open or does not exist&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does that folder exist, and is it available to SAS.&amp;nbsp; &amp;nbsp;I can't check this for you, you need to go into SAS and try creating a libname to that area.&amp;nbsp; Just because a folder exists does not mean that SAS can see or have access to it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Sep 2018 08:14:09 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-09-21T08:14:09Z</dc:date>
    <item>
      <title>Issue with importing all excel files in folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497719#M132021</link>
      <description>&lt;P&gt;Hi everyone. I currently have all the excel files in Linux server. What i want to do is loading all excel files into SAS and create dataset based on the original file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read a lot of online tutorial and most of them are only on single excel files. However, i managed to find some about loading multiple excel in multiple folders.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I actually copied the code from here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Import_all_files_one_type" target="_self"&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;P&gt;However, i am getting the error of directory or path does not exist when the same exact path is accessible using mobaxterm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code below(Slight change on the path)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%*Creates a list of all files in the DIR directory with the specified extension (EXT);
%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 to import a single file, using the path, filename and an output dataset name must be specified;
%macro import_file(path, file_name, dataset_name );

	proc import 
		datafile="&amp;amp;source./tnbt/Profile_List_Files/Central/ABBA/&amp;amp;file_name."
		dbms=xlsx
		out=&amp;amp;dataset_name replace;
	run;

%mend;

*Create the list of files, in this case all XLSX files;
%list_files(&amp;amp;source./tnbt/Profile_List_Files/Central/ABBA/, xlsx);

%*Call macro once for each entry in the list table created from the %list_files() macro;
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;&lt;P&gt;However in the log, it says this:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Directory /sasdata/source/tnbt/Profile_List_Files/Central/ABBA/ cannot be open or does not exist&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no clue what is going on as I am pretty certain that the path is 100% accessible. What could be wrong here?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 07:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497719#M132021</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-09-21T07:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with importing all excel files in folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497724#M132026</link>
      <description>&lt;P&gt;First off, why is the data in Excel - this is a really bad format for data, and if your using linux will mean that you need to use pcfiles server of something like that to even use it.&amp;nbsp; Bin that format as quick as possible and move to open file formats such as csv or xml and your life will be a lot easier, for instance, if these were csv files you could read them all in in one step (assuming structure is the same throughout).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now with your question here, #&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Directory /sasdata/source/tnbt/Profile_List_Files/Central/ABBA/ cannot be open or does not exist&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does that folder exist, and is it available to SAS.&amp;nbsp; &amp;nbsp;I can't check this for you, you need to go into SAS and try creating a libname to that area.&amp;nbsp; Just because a folder exists does not mean that SAS can see or have access to it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 08:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497724#M132026</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-21T08:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with importing all excel files in folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497730#M132029</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the data was maintained by other team......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've just verified with my team and SAS Admin has "full" access right(i mean 755) to the path and files in it. They tried creating a library and point to that path and it was working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RW9, do you have any tips for me or any other code that i can try that will read excels in either mutiple folders or just a single folder?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would love to look at it and try out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again RW9.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 08:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497730#M132029</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-09-21T08:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with importing all excel files in folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497738#M132034</link>
      <description>&lt;P&gt;So if "&lt;SPAN&gt;and SAS Admin has "full" access right(i mean 755) to the path and files in it. They tried creating a library and point to that path and it was working." - is true, then it seems that&amp;nbsp;&lt;U&gt;you&lt;/U&gt; don't have access to that area, and they need to grant you or your SAS session the correct access.&amp;nbsp; Changing code will not change this fact, the SAS system needs to have access to the area.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As for how I would do it, dir list in, call execute out (note this is windows, so you would need to change the pipe to "ls .." per linux commands):&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir "c:/datalocation/*.xlsx" /b';

data _null_;
  length fname $200;
  infile tmp;
  input fname $;
  call execute(cats('proc import datafile="c:/datalocation/',fname,' out=want',put(_n_,best.),'; run;'));
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;In this example, for each filename read in from the pipe a proc import statement is created to read in the file into wantX - X being incremental.&amp;nbsp; I don't know what you want to call the output files, so I chose wantX, you would need to update that and make sure any name is SAS compliant.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 09:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497738#M132034</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-21T09:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with importing all excel files in folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497741#M132037</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 09:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-importing-all-excel-files-in-folders/m-p/497741#M132037</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-09-21T09:54:20Z</dc:date>
    </item>
  </channel>
</rss>

