Reading a text file with no fixed columns

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Reading a text file with no fixed columns

Hello,

This is my first SAS post ever, so please be gentle Smiley Wink

I am currently studying SAS Base in an analytic programming class, and so far I know how to read text files that have a fixed column width. Here is an example:

48370.5    20345.5      4       1     669.0    247.5     1

43621.0    22727.0      5       1     654.0    230.0     2

49538.0        0.0      6       1     606.0    237.0     1

I understand how to handle such sort of data in the DATA step using the INPUT statement, since I can specify the range of columns for each variable:

INPUT Var1 1-10 Var2 12-20 etc...

However, I have no idea on how to properly read a text file that has no fixed columns, like the following example:

1  good

2  bad

3  good

7  bad

8  bad

9  bad

10  good

12  good

13  good

100  bad

101  good

102  good

1001  good

1002  bad

100000000000  bad

Could someone please advise?

Best regards,

P.


Accepted Solutions
Solution
‎12-17-2012 04:01 PM
Super Contributor
Posts: 1,636

Re: Reading a text file with no fixed columns

Hi,

Welcome!

data have;

input id grade $;

cards;

1  good

2  bad

3  good

7  bad

8  bad

9  bad

10  good

12  good

13  good

100  bad

101  good

102  good

1001  good

1002  bad

100000000000  bad

;

proc print;run;

View solution in original post


All Replies
Solution
‎12-17-2012 04:01 PM
Super Contributor
Posts: 1,636

Re: Reading a text file with no fixed columns

Hi,

Welcome!

data have;

input id grade $;

cards;

1  good

2  bad

3  good

7  bad

8  bad

9  bad

10  good

12  good

13  good

100  bad

101  good

102  good

1001  good

1002  bad

100000000000  bad

;

proc print;run;

Contributor
Posts: 41

Re: Reading a text file with no fixed columns

Hi,

Thank you for that. So if I understand correctly, all that I need to do is to omit the column width? That's easier than I thought Smiley Happy!

Thanks for the help!

Cheers,

P.

Super Contributor
Posts: 1,636

Re: Reading a text file with no fixed columns

What you said is true for your example.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 175 views
  • 0 likes
  • 2 in conversation