%let path=D:\temp;
filename filrf "&path.";
data test;
/*Set work.FileN; This holds all the filenames and extensions e.g P1.xlsx, P2.xlsx etc.. in column called filename */
did = dopen('filrf');
memcount = dnum(did);
do while (memcount>0);
fname = dread(did,memcount);
scan(lowcase(fname),2,'.') in ('xls','xlsx')
then do;
rcref = filename('fref',catx('\',"&path.",fname));
rcdel = fdelete('fref');
memcount+-1;
stop;
If you have the name and path of the files then basically you use your existing SAS data set and modify
rcref = filename('fref',catx('\',"&path.",fname));
rcdel = fdelete('fref');
to use the information in your data set to create the file name replacing the information in
,"&path.",fname with the variables you have in your data set.
All the code in the example from the
did = dopen('filrf');
fname = dread(did,memcount);
basically only is getting the names of files in the folder provided by the &path variable.
So since you know what you want you don't need to search and go directly to the delete portion.
If you are implying that you do not know the folder they should be in, then that is another issue entirely.
It almost always helps to provide examples of your existing data so we don't have to guess as to what you might have.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
If you have the name and path of the files then basically you use your existing SAS data set and modify
rcref = filename('fref',catx('\',"&path.",fname));
rcdel = fdelete('fref');
to use the information in your data set to create the file name replacing the information in
,"&path.",fname with the variables you have in your data set.
All the code in the example from the
did = dopen('filrf');
fname = dread(did,memcount);
basically only is getting the names of files in the folder provided by the &path variable.
So since you know what you want you don't need to search and go directly to the delete portion.
If you are implying that you do not know the folder they should be in, then that is another issue entirely.
It almost always helps to provide examples of your existing data so we don't have to guess as to what you might have.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Register now!
Classroom Training Available!
Select SAS Training centers are offering in-person courses. View upcoming courses for:
Arlington, VA
Cary, NC
View all other training opportunities.