Hi everyone, I just updated from SAS EG 8.2 to 8.3 this morning, the code worked yesterday now announce an error as below.
This code is for running the same code through all files in one folder
filename mydir 'C:\Users\pnguyen\OneDrive -University\PhD JOURNEY\filtering';
data _null_;
did = dopen('mydir');
do i = 1 to dnum(did);
fname = scan(dread(did,i),1,'.');
/*fname= ARGENTINA_FILTERF*/
length short_fn $29;
short_fn= substr(fname, 1,length(fname)-8);
/*short_fn=ARGENTINA*/
cmd=cats('%variablescalculation(File=C:\Users\pnguyen\OneDrive - University\PhD JOURNEY\filtering\',
strip(fname),',outf=',short_fn,');');
call execute(cmd);
end;
keep fname;
run;
And the log is as below
240 /*Replicate all files in one folder*/
241
242 filename mydir 'C:\Users\pnguyen\OneDrive - University\PhD JOURNEY\filtering';
243 data _null_;
244 did = dopen('mydir');
245 do i = 1 to dnum(did);
246 fname = scan(dread(did,i),1,'.');
247 /*At this point I assign that the filename has the tail is xlsx or sas7bdat, if not, use another way
248 fname= ARGENTINA_FILTERF*/
249 length short_fn $29;
250 short_fn= substr(fname, 1,length(fname)-8);
251 /*short_fn=ARGENTINA*/
252
253 cmd=cats('%variablescalculation(File=C:\Users\pnguyen\OneDrive - University\PhD JOURNEY\filtering\',
254 strip(fname),',outf=',short_fn,');');
255 call execute(cmd);
256 end;
257 keep fname;
258 run;
NOTE: Argument 1 to function DNUM(0) at line 245 column 13 is invalid.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero,
or invalid.
Can you please help me to sort it out?
Many thanks and warm regards.
@PhilC wrote:
I would be interested in seeing the return values of your functions in your code.
dopen('mydir');
and
dnum(did);
I would think it would inform us whilst debugging.
I think it did. DNUM(0) in the message tells me that DOPEN failed. Or did you mean all the variables as dumped when other Invalid data is encountered?
If the directory cannot be opened, DOPEN returns 0, and you can obtain the error message by calling the SYSMSG function.
@Phil_NZ Check the spelling on your path. In another post you have
libname myfolder 'C:\Users\pnguyen\OneDrive - Massey University\PhD JOURNEY\3calculation1';
and this post does not include the "Massey" part of the path in the libname statement.
I might also suggest having your libnames names mean something like Libname Calc for the one immediately above and Libname Filter instead of constantly renaming "myfolder" and never knowing which actual files are there.
I would be interested in seeing the return values of your functions in your code.
dopen('mydir');
and
dnum(did);
I would think it would inform us whilst debugging.
Hi @PhilC
The code stop there. And the returns logically speaking are
did = dopen('mydir');
is a code to open the directory 'C:\Users\pnguyen\OneDrive - University\PhD JOURNEY\filtering'
and
dnum(did);
is to retrieve the number of file in this directory, in particular, in my case, I have 64 files.
Cheers.
@PhilC wrote:
I would be interested in seeing the return values of your functions in your code.
dopen('mydir');
and
dnum(did);
I would think it would inform us whilst debugging.
I think it did. DNUM(0) in the message tells me that DOPEN failed. Or did you mean all the variables as dumped when other Invalid data is encountered?
If the directory cannot be opened, DOPEN returns 0, and you can obtain the error message by calling the SYSMSG function.
@Phil_NZ Check the spelling on your path. In another post you have
libname myfolder 'C:\Users\pnguyen\OneDrive - Massey University\PhD JOURNEY\3calculation1';
and this post does not include the "Massey" part of the path in the libname statement.
I might also suggest having your libnames names mean something like Libname Calc for the one immediately above and Libname Filter instead of constantly renaming "myfolder" and never knowing which actual files are there.
good catch.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.