Help using Base SAS procedures

Using SAS code to delete .csv files in a folder

Reply
Contributor
Posts: 52

Using SAS code to delete .csv files in a folder

I have SAS code that takes multiple Excel tabs and exports each of them into the same directory as .csv files.  Using PROC IMPORT each of these csv files are used to create individual SAS datasets via SAS EG.

 

My question: Once my SAS datasets are created I have no need for these csv files.  How would I code my program to delete these csv files?

 

Thanks.

Jack

Respected Advisor
Posts: 3,124

Re: Using SAS code to delete .csv files in a folder

Grand Advisor
Posts: 16,925

Re: Using SAS code to delete .csv files in a folder

So I understand correct, the Excel file is converted to CSV, then imported to SAS. Now you want to delete the CSV files?

 

I'm assuming you're using x commands at some point so you could use 

 

X 'RM path_to_file.csv;

 

 

Contributor
Posts: 52

Re: Using SAS code to delete .csv files in a folder

To answer your original question:

 

So I understand correct, the Excel file is converted to CSV, then imported to SAS. Now you want to delete the CSV files?

 

Yes, that is correct.

 

But I have 12 csv files to delete (in a future run, I will a lot more).  How can I efficeintly code this?  I have 12 csv files that are named by month of the year (Jan, Feb, etc.).

 

Thanks

Grand Advisor
Posts: 16,925

Re: Using SAS code to delete .csv files in a folder

Assuming you're on Windows you can use a wildcard in your command. 

 

Find the appropriate system command to remove all files that end with .CSV

 

X "rm folder/*.csv"
Contributor
Posts: 52

Re: Using SAS code to delete .csv files in a folder

Great, thanks for quick reply...

Ask a Question
Discussion stats
  • 5 replies
  • 460 views
  • 0 likes
  • 3 in conversation