BookmarkSubscribeRSS Feed
Kiy
Calcite | Level 5 Kiy
Calcite | Level 5

Basically as it says in the title, I have an excel list of files which can be deleted and the filepath is given. How can I delete all of these filepaths in one piece of code?

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

What kind of files? Can you show us the Excel sheet?

 

Kiy
Calcite | Level 5 Kiy
Calcite | Level 5
They are other sas datasets stored within the Same SAS server
BrunoMueller
SAS Super FREQ

Have a look here:

https://communities.sas.com/t5/General-SAS-Programming/dynamically-deleting-external-files/td-p/2633...

 

You will use the FILENAME and FDELETE functions to do what you want

Kiy
Calcite | Level 5 Kiy
Calcite | Level 5
The files are internal within the same SAS server and as a beginner on SAS I am a little confused on where I should fill in the filepaths.
BrunoMueller
SAS Super FREQ

What does the list of files to delete look like?

 

Find below a sample program that shows how to use the FILENAME and FDELETE functions. This should help you understand how to use them. Additionally you have to read the documentation of does function as well. 

 

*
* file we want to delete
*;
%let myfile = c:\temp\sugus.dat;

%put NOTE: does &myfile exists %sysfunc(fileexist(&myfile)) (1=true 0=false) ;

*
* create file for delete testing
*;
data _null_;
  file "&myfile";
  put "hello world";
run;

%put NOTE: does &myfile exists %sysfunc(fileexist(&myfile)) (1=true 0=false) ;

*
* delete file using FDELETE function, needs a fileref
*;
data _null_;
  rc_assign_fileref = filename("_fd", "&myfile");
  rc_fdelete = fdelete("_fd");
  rc_deassign_fileref = filename("_fd");
  putlog _all_;
run;

%put NOTE: does &myfile exists %sysfunc(fileexist(&myfile)) (1=true 0=false) ;

andreas_lds
Jade | Level 19
  1. Import the Excel-file.
  2. Use a data-step to process the imported data using the already suggested fdelete function.

The documentation contains an example explaining how to use fdelete.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 1328 views
  • 0 likes
  • 4 in conversation