<?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 Importing all data files from a directory in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-all-data-files-from-a-directory/m-p/281530#M57111</link>
    <description>&lt;P&gt;I am trying to import a lot of data files from a single directory. My code is as below.&lt;/P&gt;
&lt;P&gt;Every time I am running the program I get the following error. Where Am I going wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt; %scan((&amp;amp;RC_Files),&amp;amp;st,&amp;amp;x) ne &lt;BR /&gt;ERROR: The condition in the %DO %WHILE loop, %scan((&amp;amp;RC_Files),&amp;amp;st,&amp;amp;x) ne, yielded an invalid or missing value, . The macro will &lt;BR /&gt; stop executing.&lt;BR /&gt;ERROR: The macro READALLRATECARDFILES will stop executing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro get_filenames(location);
filename _dir_ "%bquote(&amp;amp;location.)";
data filenames(keep=memname);
handle=dopen( '_dir_' );
if handle &amp;gt; 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;

%macro ReadInputFiles(filePath, Fformat, sheetName, outDS);

proc import out=inlib.&amp;amp;outDS DATAFILE="&amp;amp;filePath"
dbms=&amp;amp;Fformat replace;
getnames=yes;
%if %length(%cmpres(&amp;amp;sheetName)) &amp;gt; 0 %then %do;
Sheet=&amp;amp;sheetName;
%end;
run;
data inlib.&amp;amp;outDS;
set inlib.&amp;amp;outDS;
if compress(cats(of _all_),,'kad') = '' then delete;
run;
%mend;

%macro ReadAllRateCardFiles;
%get_filenames(&amp;amp;inXLRCDir);
proc sql;
select memname into :RC_Files separated by ','
from filenames;
quit;
%put &amp;amp;RCFiles;
%let st = 1; 
%let DSNamePrefix = Std_RC_Set_;
%let x = %str(,) ;
%do %while(%scan((&amp;amp;RC_Files),&amp;amp;st,&amp;amp;x) ne );
%let FileName = %cmpres(%scan(%bquote(&amp;amp;RC_Files),&amp;amp;st,%str(,)));
data ReadFile_Status1;
/* if exists('ReadFile_Status','DATA') then 
set ReadFile_Status;
end;*/
length path $5000 DSName $50;

%let FilePath = "%trim(&amp;amp;inXLDir./&amp;amp;FileName)";
path = &amp;amp;FilePath;
FileExists = fileexist(path);
DSName = "&amp;amp;DSNamePrefix.&amp;amp;st";
%put &amp;amp;FilePath;
if FileExists &amp;gt; 0 then do;
call execute('%ReadExcelInput('||path||',csv,,'||DSName||')');
end;

run;

%let st = %sysevalf(&amp;amp;st + 1); 
%end;
%mend;
%ReadAllRateCardFiles;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2016 17:47:18 GMT</pubDate>
    <dc:creator>SASEnthusiast</dc:creator>
    <dc:date>2016-06-30T17:47:18Z</dc:date>
    <item>
      <title>Importing all data files from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-all-data-files-from-a-directory/m-p/281530#M57111</link>
      <description>&lt;P&gt;I am trying to import a lot of data files from a single directory. My code is as below.&lt;/P&gt;
&lt;P&gt;Every time I am running the program I get the following error. Where Am I going wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt; %scan((&amp;amp;RC_Files),&amp;amp;st,&amp;amp;x) ne &lt;BR /&gt;ERROR: The condition in the %DO %WHILE loop, %scan((&amp;amp;RC_Files),&amp;amp;st,&amp;amp;x) ne, yielded an invalid or missing value, . The macro will &lt;BR /&gt; stop executing.&lt;BR /&gt;ERROR: The macro READALLRATECARDFILES will stop executing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro get_filenames(location);
filename _dir_ "%bquote(&amp;amp;location.)";
data filenames(keep=memname);
handle=dopen( '_dir_' );
if handle &amp;gt; 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;

%macro ReadInputFiles(filePath, Fformat, sheetName, outDS);

proc import out=inlib.&amp;amp;outDS DATAFILE="&amp;amp;filePath"
dbms=&amp;amp;Fformat replace;
getnames=yes;
%if %length(%cmpres(&amp;amp;sheetName)) &amp;gt; 0 %then %do;
Sheet=&amp;amp;sheetName;
%end;
run;
data inlib.&amp;amp;outDS;
set inlib.&amp;amp;outDS;
if compress(cats(of _all_),,'kad') = '' then delete;
run;
%mend;

%macro ReadAllRateCardFiles;
%get_filenames(&amp;amp;inXLRCDir);
proc sql;
select memname into :RC_Files separated by ','
from filenames;
quit;
%put &amp;amp;RCFiles;
%let st = 1; 
%let DSNamePrefix = Std_RC_Set_;
%let x = %str(,) ;
%do %while(%scan((&amp;amp;RC_Files),&amp;amp;st,&amp;amp;x) ne );
%let FileName = %cmpres(%scan(%bquote(&amp;amp;RC_Files),&amp;amp;st,%str(,)));
data ReadFile_Status1;
/* if exists('ReadFile_Status','DATA') then 
set ReadFile_Status;
end;*/
length path $5000 DSName $50;

%let FilePath = "%trim(&amp;amp;inXLDir./&amp;amp;FileName)";
path = &amp;amp;FilePath;
FileExists = fileexist(path);
DSName = "&amp;amp;DSNamePrefix.&amp;amp;st";
%put &amp;amp;FilePath;
if FileExists &amp;gt; 0 then do;
call execute('%ReadExcelInput('||path||',csv,,'||DSName||')');
end;

run;

%let st = %sysevalf(&amp;amp;st + 1); 
%end;
%mend;
%ReadAllRateCardFiles;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 17:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-all-data-files-from-a-directory/m-p/281530#M57111</guid>
      <dc:creator>SASEnthusiast</dc:creator>
      <dc:date>2016-06-30T17:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Importing all data files from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-all-data-files-from-a-directory/m-p/281541#M57116</link>
      <description>&lt;P&gt;Here's my suspicion.&amp;nbsp; This statement is the culprit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%while&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;RC_Files&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;st&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;x&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some paths to files may contain a dash or a slash (- or /).&amp;nbsp; When macro language evaluates whether the %DO %WHILE condition is still satisfied, it applies %EVAL to the comparison.&amp;nbsp; And when it sees a dash or slash, it interprets those as "minus" or "divide".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try switching from %SCAN to %QSCAN.&amp;nbsp; The %SCAN function returns an unquoted result, even when the incoming string is quoted.&amp;nbsp; Switching to %QSCAN will return a quoted result, treating - or / as text. &lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 18:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-all-data-files-from-a-directory/m-p/281541#M57116</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-30T18:46:36Z</dc:date>
    </item>
  </channel>
</rss>

