04-06-2017 04:26 AM
I am trying to write a SAS macro that will import multiple .csv files present in the current folder as per the user inputs given. Here is what i have written so far but it is throwing exit 2. I am running SAS9. on unix. In the below example, Meijer and publix will be user provided details. I want to write a macro that will import files titled Meijer and publix from current folder and create data sets of the same name. This list i.e retailers can vary everytime users run this code. I am currently getting exit 2 which says too few arguements for %scan function. Please advise.
%let retailers= Meijer publix;
%do %while (%scan(&retailers &i) ne );
%let next_retailer = %scan(&retailers &i);
proc import datafile = "&next_retailer" out=&next_retailer_stores dbms=csv replace;
%let i = %eval(&i + 1);
04-06-2017 05:08 AM
Am going to suggest a far out there idea here, I put "import multiple csv" into the search area at the top, and there was about 100 topics suggesting many different ways of doing it /sarcasm
To note, you don't need macro - you never need macro.
Also, I would avoid using proc import - this is guessing procedure so you don't really know what your going to get out. Write a datastep and code in exactly what each column should be, what it looks like, and how to read it. I.e. you take 100% full control over your data.
04-06-2017 07:55 AM
Arguments for SAS macro functions are separated with a comma, your scan expression should look like this:
04-06-2017 10:51 AM
Are your file names actually going to match "&next_retailer"? As in does that macro variable have the file extention such as .csv? You may need, at a minimum, "&next_retailer..csv" and the two . are needed. The first one tells the macro compilier it is the end of the name of the macro variable the second is part of the actual file name.
And it really is a good idea to have the complete path as well as I'm not sure that you will get the correct "current folder".