Search code examples
importsasproc

SAS PROC IMPORT GROUPED VARIABLES


How to I keep variables in separate columns when using proc import with a tab delimited txt file? Only one variable is created called Name__Gender___Age. Is it only possible with the data step?

This is the code


proc import datafile= '/folders/myfolders/practice data/IMPORT DATA/class.txt'  
out=new
dbms=tab
replace;
delimiter='09'x; 
run;




Solution

  • You told PROC IMPORT that your text file had tabs between the fields. From the name of the variable it created it is most likely that instead your file just has spaces between the fields. And multiple spaces so that the lines look neatly aligned when viewed with a fixed width font.

    Just write your own data step to read the file (something you should do anyway for text files).

    data mew;
      infile '/folders/myfolders/practice data/IMPORT DATA/class.txt' firstobs=2 truncover;
      length Name $30 Gender $6 Age 8 ;
      input name gender age;
    run;
    

    If there are missing values for either NAME or GENDER that are not entered as a period then you probably will want to read it using formatted or column mode input instead the simple list mode input style above.