BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cgsmoak56
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

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;

View solution in original post

3 REPLIES 3
ErikLund_Jensen
Rhodochrosite | Level 12

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;
ballardw
Super User

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.

 

cgsmoak56
Calcite | Level 5

Thank you, Your solution worked.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 689 views
  • 0 likes
  • 3 in conversation