DATA Step, Macro, Functions and more

SAS import text file

Accepted Solution Solved
Reply
Contributor scb
Contributor
Posts: 50
Accepted Solution

SAS import text file

I would like to import the text file, the 2nd column should be all characters. 

 

When i import, as the first record was numeric, the format was numeric and those records with alphabet became . ; may i know how to import the file that the 2nd columns should become characters instead of numeric?

 

Anyone can help? Sample file attached.


Accepted Solutions
Solution
‎11-28-2016 09:27 AM
Super User
Posts: 6,928

Re: SAS import text file

data want;
infile 'have.txt' dlm=';';
input col1 $ col2 $;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎11-28-2016 09:27 AM
Super User
Posts: 6,928

Re: SAS import text file

data want;
infile 'have.txt' dlm=';';
input col1 $ col2 $;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor scb
Contributor
Posts: 50

Re: SAS import text file

I tried the file with more variables...The COL5 and COL6 was incomplete after the import...Any idea? Thanks.

 

data want;
infile 'D:\RenewalCSV1.txt' dlm=';';
input col1 $ col2 $ COL3 $ COL4 $ COL5 $ COL6 $;
run;

 

 

PROC Star
Posts: 547

Re: SAS import text file

When you say incomplete, do you mean truncated? Smiley Happy In that case use a length statement.

Super User
Posts: 17,750

Re: SAS import text file

Your text file either has more than 6 cols or the data is on a single line. 

 

If single line make make sure to use the trailing @@. 

Super User
Posts: 10,466

Re: SAS import text file

If you do not indicate to SAS that a character variable will exceed 8 characters that is the default length.

You may want to use an INFormat statement to indicate how to read the variable.

It would look something like this:

data want;
   infile 'D:\RenewalCSV1.txt' dlm=';';
   informat Col5 Col6 $50.
   input col1 $ col2 $ COL3 $ COL4 $ COL5 $ COL6 $;
run;

Make the size, 50 in my example, sufficient to hold the longest expected value.

 

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 412 views
  • 2 likes
  • 5 in conversation