10-13-2013 03:42 AM
I need your help. I have around 150 data files (CSV files) with in different folders.
I wrote a macro to pick the data from the each folder and create data set.
1)The problem in some of variable the values are in exponents. I used IMPORT procedure in macro . But default it taking format as best12 for all numeric. So I went for Import wizard. Is there any proces to make all numeric to best 32. in format so that I can save time.
2) Is there any way to create automatic process to pick files automatically and create data set from the folder I keep all the files in one folder and create a new data set. What I mean was I show the macro the folder the macro must read all the files and create a ew data set for each and every data set. With above case.
Can you give me hint hot to do this using macro.Because in coming days we are going to get huge files .
I'm looking for solution in windows. We are using base sas 9.2V.
10-13-2013 02:57 PM
About question 2: In Windows, you can use wildcards to read multiple files from the same directory. The only difficulty with CSV files is skipping the header line in each file. You may also want to record from which file each observation comes from. The following code takes care of both issues.
filename myCSV "c:\csvPath\*.csv";
infile myCSV dsd missover eov=skip filename=fromFile;
if skip then skip=0;
input myVar1 myVar2 myVar3;
myVar0 = fromFile;
10-13-2013 08:27 PM
In the past I used a macro (following the progra from some website that I don't remember). This actually helps.
Please change the macro to cater for your requirement. This is just a guide line.
%let outfilepath=myoutfilepath ;*outfile path name;
%let SourceDatapath=mysourcedata ;*sourcedata path name;
%let rc=%sysfunc(filename(filrf,"&root_dir\Source Data\Online Source Data"));
%if &memcount > 0 %then
%do i=1 %to &memcount;
%let loc=%substr(&fname,1,%eval(&iw-1)); /* get first part of file name */
filename dr "&SourceDatapath\&fname.";
filename outfile "&outfilepath\&fname."; /* use file name to determine;
directory for output file */
PROC IMPORT OUT= WORK.A