Problem importing text file

Accepted Solution Solved
Reply
Regular Contributor
Posts: 183
Accepted Solution

Problem importing text file

Hi Experts,

My text files looks the following. When I am importing this file to SAS, then SAS file shows all variables in one column. How can I solve this?

PERMNO            DATE       CRSP     Return

10001                20040416   20839    -0.003487

10001                20040419   20840     0.051085

10001                20040420   20841    -0.087883


Accepted Solutions
Solution
‎04-19-2015 08:15 PM
Super User
Super User
Posts: 6,364

Re: Problem importing text file

If your file is that simple then just write the data step to read.  If you use an importing tool it will have to guess at what variable types to use.

data want ;

   infile 'myfile' firstobs=2 truncover ;

  input PERMNO DATE CRSP Return;

  informat date yymmdd8.;

  format date yymmddN8. ;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,837

Re: Problem importing text file

By choosing the correct delimiter. Is it a TAB or 1 to n blanks? Are you using a data step or Proc Import?

Base SAS(R) 9.4 Procedures Guide, Third Edition

Regular Contributor
Posts: 183

Re: Problem importing text file

I think this is 1 to n blanks. Using both data step and proc import shows all variables in one column.

Solution
‎04-19-2015 08:15 PM
Super User
Super User
Posts: 6,364

Re: Problem importing text file

If your file is that simple then just write the data step to read.  If you use an importing tool it will have to guess at what variable types to use.

data want ;

   infile 'myfile' firstobs=2 truncover ;

  input PERMNO DATE CRSP Return;

  informat date yymmdd8.;

  format date yymmddN8. ;

run;

Regular Contributor
Posts: 183

Re: Problem importing text file

Now it works. Thanks a lot to Tom, Reeza and Patrick.

Grand Advisor
Posts: 17,396

Re: Problem importing text file

What does your code look like?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 228 views
  • 0 likes
  • 4 in conversation