3

The code I use in SAS

Options symbolgen ps=10000;
Data span_nonspan;
INFILE 'C:\September 2016\SAMPLE.dat'; 
   INPUT @1     XYZ       $10.
         @11    ABC       $7.         
         @18    PM        $3.
run;

Can anyone please help me how to write in Python 3.5 to read data same way, I am new to Python and any help would be really appreciated.

The data would look something like below:

5085489966001001600220161002191219    1P  106SCHWARTZ
Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59
  • is that code written in SAS or the contents of the `.dat` file? If your question is relevent to [tag:SAS] then you should add the appropriate tag. – Tadhg McDonald-Jensen Sep 24 '16 at 17:14
  • that is a SAS code and now I want to fetch the same data in Python. The data would look something like below: " 5085489966001001600220161002191219 1P 106SCHWARTZ 17747429 " – Ramesh Dharmegowda Sep 24 '16 at 17:51
  • you will need to [edit your question](http://stackoverflow.com/posts/39673180/edit) and put the content in there, newlines are not possible in comments – Tadhg McDonald-Jensen Sep 24 '16 at 17:59
  • I have just edited my question adding the content of the file. Please assist me and thanks for your response and assistance – Ramesh Dharmegowda Sep 24 '16 at 18:05
  • Having fixed width columns, are these separated by tabs or spaces? In which way do you want to access the data later since I do not know `SAS`? – albert Sep 24 '16 at 18:38
  • separated by tabs and the file is available as .dat file and I want to read that file in Python. Fine as now, please ignore SAS and sorry if that has caused confusion. Please assist me in writing Python code to fetch the data having like above format – Ramesh Dharmegowda Sep 24 '16 at 18:51

1 Answers1

1
import pandas as p
data = p.read_fwf("filename", colspecs=[(0,10),(11,17),(17,20),(20,24)],names=['DP','PHONETYPE','MARKET','FOLDER'])
data.head()