Jan-20-2018, 06:22 PM
I am very new to this and trying to use it for some of my tasks. I have a list of raw data files without any extension, the files are having more than 100 columns. I successfully read all those files using following code and converted into one txt file.
%do i = 1 %to &nameM.;
Data myData ;
infile "&path.\&&flt2_&i"
missover dlm='09'x firstobs = 2 lrecl=4096 ;
input
NBR $ 1-40
DT $ 41-72
TYP $ 73-112
POST $ 113
CURR $ 114-116
DECI $ 117-156
ORIG $ 157-196
....
......
.....
run;
%end;
%mend;
Since, I am very new to Python (which sadly is the only challenge), any help will be much appreciated.
thanks
import glob
path = '/Documents/Data/*'
read_files = glob.glob(path)
with open("result.txt", "wb") as outfile:
for f in read_files:
with open(f, "rb") as infile:
outfile.write(infile.read())My second task is to assign column names which I am unable to do as some of the data fields are merged with each other so I need to define the range of each column before assigning column names. I easily did this task in SAS using macros. The snippet is as follows:%do i = 1 %to &nameM.;
Data myData ;
infile "&path.\&&flt2_&i"
missover dlm='09'x firstobs = 2 lrecl=4096 ;
input
NBR $ 1-40
DT $ 41-72
TYP $ 73-112
POST $ 113
CURR $ 114-116
DECI $ 117-156
ORIG $ 157-196
....
......
.....
run;
%end;
%mend;
Since, I am very new to Python (which sadly is the only challenge), any help will be much appreciated.
thanks
