BookmarkSubscribeRSS Feed
SASEnthusiast
Obsidian | Level 7

I am trying to import a lot of data files from a single directory. My code is as below.

Every time I am running the program I get the following error. Where Am I going wrong.

 

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
%scan((&RC_Files),&st,&x) ne
ERROR: The condition in the %DO %WHILE loop, %scan((&RC_Files),&st,&x) ne, yielded an invalid or missing value, . The macro will
stop executing.
ERROR: The macro READALLRATECARDFILES will stop executing.

 


%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=memname);
handle=dopen( '_dir_' );
if handle > 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.&outDS DATAFILE="&filePath"
dbms=&Fformat replace;
getnames=yes;
%if %length(%cmpres(&sheetName)) > 0 %then %do;
Sheet=&sheetName;
%end;
run;
data inlib.&outDS;
set inlib.&outDS;
if compress(cats(of _all_),,'kad') = '' then delete;
run;
%mend;

%macro ReadAllRateCardFiles;
%get_filenames(&inXLRCDir);
proc sql;
select memname into :RC_Files separated by ','
from filenames;
quit;
%put &RCFiles;
%let st = 1; 
%let DSNamePrefix = Std_RC_Set_;
%let x = %str(,) ;
%do %while(%scan((&RC_Files),&st,&x) ne );
%let FileName = %cmpres(%scan(%bquote(&RC_Files),&st,%str(,)));
data ReadFile_Status1;
/* if exists('ReadFile_Status','DATA') then 
set ReadFile_Status;
end;*/
length path $5000 DSName $50;

%let FilePath = "%trim(&inXLDir./&FileName)";
path = &FilePath;
FileExists = fileexist(path);
DSName = "&DSNamePrefix.&st";
%put &FilePath;
if FileExists > 0 then do;
call execute('%ReadExcelInput('||path||',csv,,'||DSName||')');
end;

run;

%let st = %sysevalf(&st + 1); 
%end;
%mend;
%ReadAllRateCardFiles;

 

 

1 REPLY 1
Astounding
PROC Star

Here's my suspicion.  This statement is the culprit:

 

%do %while(%scan((&RC_Files),&st,&x) ne );

 

Some paths to files may contain a dash or a slash (- or /).  When macro language evaluates whether the %DO %WHILE condition is still satisfied, it applies %EVAL to the comparison.  And when it sees a dash or slash, it interprets those as "minus" or "divide". 

 

Try switching from %SCAN to %QSCAN.  The %SCAN function returns an unquoted result, even when the incoming string is quoted.  Switching to %QSCAN will return a quoted result, treating - or / as text.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1534 views
  • 0 likes
  • 2 in conversation