1
votes

I currently have python code running a html scrape and storing the data as CSV files in a folder on my computer called "New Data". I would then like to run my SAS code through every CSV file that is uploaded to that folder. After I run that data through my SAS code I would like to move all of the CSV files from "New Data", to a folder named "Processed Data". I was wondering what SAS code would help me to move CSV files from one folder on my computer to another, after they have been sent through code. Also, the code has to be automated as there will be new CSV files coming in daily.

Thanks!

1
FCOPY function will move files. However, if you have XCMD enabled, you're likely better off using a system command (varies depending on your OS) that will move the whole folder at once.Reeza
This reference for macros may also be helpful, though you can probably do this without macros as well. communities.sas.com/t5/SAS-Communities-Library/…Reeza
Do you launch the python code from within SAS ? Is your SAS session within a SAS server environment, or stand alone (PC-SAS/Display Manager)? Is the content of all the scraped files consistent (column names, types and maximum lengths) ? Are the scraped filenames consistent or follow a pattern ? What is the operating system ? Do you know how to schedule tasks or create a cron job entry ? Have you ever launched batch SAS program from python code ?Richard

1 Answers

0
votes

I have done something similar. Part of data steps is copying files from one folder to another. I used DOS commands in SAS. The command need to be in single quotation. If there is a space in the folder name or file name, the directory of the file needs to be in double quotation. Here is an example for all the csv files in the "new data" folder to be moved to the "processed data" folder:

data a;
b = system ('move "x:\sas\project\new data\*.csv" "x:\sas\project\processed data\" ');
run;

Pay attention to the quotation. As Reeza mentioned, this code assumes XCMD is enabled.