how do i import a fixed-width text file with many variables which are stored in a sas filesas?

One way you can do it is:

  1. Download the WPS Workbench Community edition. WPS Workbench is a software that read sas files. If you are enrolled in some College/University, you can also download the academic edition (which is free of ads and have extra features). After you install and set it up, open it.

  2. In WPS Environment, open the .sas program: by clicking in File -> Open File and selecting your .sas file, which will open in WPS. Set three lines like that:

INFILE 'C:\Users\...\path_to_your_file\YOURDATA.TXT' LRECL=978 MISSOVER;
 @18  PROFAM  6.  /*  progressivo famiglia univoco a livello indagine */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
 @24  PROIND  2.  /*  progressivo individuo nell'ambito della famiglia*/ 

Just choose the name you want for your data in the first line and put the correct path to your .txt file in the second line.

2.1 Correct the code by: Erasing the line ***Column VarName Varlength VarLabel*** that is between the INPUT statement and the first line of data.

2.2 Check the last two lines after the last variable, it should end something like that:

@235 NCOMPL  8. /*  n° rendimento la famiglia attuale */

If it is not, add the last two lines above.

  1. Write the syntax to export your data to a .csv. Just write the following code at the end of the .sas program file:
proc export data=YOUR_DATA

Make sure to write again the correct name of your file (the one you chose) in the first line, and the correct path where you want the .csv file to be saved in the second line.

Press ctrl + R to run the code, or click on the run button. Click Ok in the Save and run WPS dialog box.

  1. Finally, open the .csv in Pandas.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top