Hi,
The following code used to work for me perfectly to get a list of SAS datasets in a folder. Now with SAS version 9.4, I am getting an error message.
filename dir "c:\tempsas";
data fname(keep=fname);
length filename $ 200;
did = dopen(‘dir’);
do i = 1 to dnum(did);
filename = dread(did, i);
ext_name = index(filename, ‘.’);
if ext_name > 0 then fname = substr(filename, 1, ext_name – 1);
If upcase(substr(left(reverse(filename)), 1, 10)) eq ‘TADB7SAS.’ then output;
end;
rc = dclose(did);
run;
The log shows the following error:
77 data fname(keep=fname);
78 length filename $ 200;
79 did = dopen(‘dir’);
_
386
200
76
ERROR 386-185: Expecting an arithmetic expression.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 76-322: Syntax error, statement will be ignored.
80 do i = 1 to dnum(did);
81 filename = dread(did, i);
82 ext_name = index(filename, ‘.’);
_
386
200
76
83 if ext_name > 0 then fname = substr(filename, 1, ext_name – 1);
_
388
200
______
72
Thank you in advance for any assistance.
Hi @cgsmoak56
It seems that your code on it's way to your SAS editor has been through MS Word or something similar, because the syntax errors come from illegal characters used as quotes (around 'dir', 'i' and 'TADB7SAS', and the - in the substring has also been converted to an illegal type of dash. I have corrected these errors in the following code, and it runs without any syntax errors:
data fname(keep=fname);
length filename $ 200;
did = dopen('dir');
do i = 1 to dnum(did);
filename = dread(did, i);
ext_name = index(filename, '.');
if ext_name > 0 then fname = substr(filename, 1, ext_name - 1);
If upcase(substr(left(reverse(filename)), 1, 10)) eq 'TADB7SAS.' then output;
end;
rc = dclose(did);
run;
Hi @cgsmoak56
It seems that your code on it's way to your SAS editor has been through MS Word or something similar, because the syntax errors come from illegal characters used as quotes (around 'dir', 'i' and 'TADB7SAS', and the - in the substring has also been converted to an illegal type of dash. I have corrected these errors in the following code, and it runs without any syntax errors:
data fname(keep=fname);
length filename $ 200;
did = dopen('dir');
do i = 1 to dnum(did);
filename = dread(did, i);
ext_name = index(filename, '.');
if ext_name > 0 then fname = substr(filename, 1, ext_name - 1);
If upcase(substr(left(reverse(filename)), 1, 10)) eq 'TADB7SAS.' then output;
end;
rc = dclose(did);
run;
Please post LOG entries into a text box opened on the forum with the </> icon. As you can see from your post the message window has reformatted the log text so that the _ characters, which should appear directly under the place where the 386-185 and other characters occur and instead appear under the line numbers. The message windows reformat text removing space characters resulting in the misalignment as shown.
The log would typically show something more like:
79 did = dopen(‘dir’); _
Note that the text box also makes the curly quotes more obvious.
Thank you, Your solution worked.
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.