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

I have csv files saved in my local machine need to delete it using SAS.

 

I have used the below code but its not working.

 

%macro abc;
%do i=1 %to #
filename delfile&i. "C:\MBR\CSV\&&nama&i..csv";
data _null_;
rc=fdelete("delfile&i.");
run;
%end;
%mend;
%abc;

 

 

I get the below error

 

 

ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.

NOTE: In a call to the FDELETE routine, the fileref delfile61 exceeds 8 characters, and will be truncated.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.

NOTE: In a call to the FDELETE routine, the fileref delfile62 exceeds 8 characters, and will be truncated.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.

NOTE: In a call to the FDELETE routine, the fileref delfile63 exceeds 8 characters, and will be truncated.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.

NOTE: In a call to the FDELETE routine, the fileref delfile64 exceeds 8 characters, and will be truncated.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.03 seconds

 

 

files which i want to delete in my local machine.

 

 

CAMEROON.csv
CHINA.csv
CHINAGBS.csv
COLOMBIA.csv
COTEDIVOIRE.csv
EGYPT.csv
FALKLANDISLANDS.csv
FRANCE.csv
GAMBIA.csv
GERMANY.csv
GHANA.csv
GUERNSEY.csv
HONGKONG.csv
INDIA.csv
INDIAGBS.csv
INDONESIA.csv
IRAQ.csv
IRELAND.csv
JAPAN.csv
JERSEY.csv
JORDAN.csv
KENYA.csv
LAOS.csv
LEBANON.csv
MACAO.csv
MALAYSIA.csv
MALAYSIAGBS.csv
MAURITIUS.csv
MYANMAR.csv
NEPAL.csv
NIGERIA.csv
OMAN.csv
PAKISTAN.csv
PHILIPPINES.csv
POLAND.csv
QATAR.csv
SAUDIARABIA.csv
SIERRALEONE.csv
SINGAPORE.csv
SOUTHAFRICA.csv
SOUTHKOREA.csv
SRILANKA.csv
SWEDEN.csv
SWITZERLAND.csv
TAIWAN.csv
TANZANIA.csv
THAILAND.csv
TURKEY.csv
UAE.csv
UGANDA.csv
UNITEDKINGDOM.csv
UNITEDSTATES.csv
VIETNAM.csv
ZAMBIA.csv
ZIMBABWE.csv

 

Can anyone please assist.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Your FILEREF delfile&i exceeds the limit of 8 characters when &i reaches 10 in value. Reduce the length by calling it say delfl&i.

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

Your FILEREF delfile&i exceeds the limit of 8 characters when &i reaches 10 in value. Reduce the length by calling it say delfl&i.

parmesh
Calcite | Level 5

thank you 

Kurt_Bremser
Super User

Store your filenames in a dataset, and use data step logic in place of the macro code. It's cleaner and performs better:

data files_to_delete;
input fname :$256.;
datalines;
$HOME/test/test1.csv
$HOME/test/test2.csv
;

data _null_;
set files_to_delete;
rc = filename('fdel',fname);
if rc = 0
then do;
  rc = fdelete('fdel');
  if rc then put "delete failed: " fname;
end;
else put "filename failed: " fname;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2499 views
  • 2 likes
  • 3 in conversation