DATA Step, Macro, Functions and more

fixed width text file import

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

fixed width text file import

[ Edited ]

Hello everyone,

 

 


Accepted Solutions
Solution
‎09-05-2017 04:56 PM
Super User
Super User
Posts: 8,273

Re: fixed width text file import

Use the Insert Code or Insert SAS Code icons in the editor to paste in data and/or code so that the format is preserved.

Your INPUT statement has a lot of extra $.

input
  type 1-1
  code $ 2-3
  ID $ 4-9
  direction $ 10-10
  lane $ 11-11
  year $ 12-13
  month $ 14-15
  day $ 16-17
  hour $ 18-19
  volume $ 20-24
  class1 $ 25-29
  class2 $ 30-34
  class3 $ 35-39
  class4 $ 40-44
  class5 $ 45-49
  class6 $ 50-54
  class7 $ 55-59
  class8 $ 60-64
  class9 $ 65-69
  class10 $ 70-74
  class11 $ 75-79
  class12 $ 80-84
  class13 $ 85-89
  class14 $ 90-94
  class15 $ 95-99
;

 

View solution in original post


All Replies
Super User
Posts: 13,926

Re: fixed width text file import

The basic approach for fixed width is to specify the start and end column for each variable:

data want;

    infile "file to read" <any needed options like lrecl >;

    input

       var1 1

       var2  2-3

       var3  4-9

       <etc.>

   ;

run;

 

If you are reading character data then use varx $ startcolumn-endcolumn.

New Contributor
Posts: 4

Re: fixed width text file import

i wrote this code and it kept giving me the following message:

the code:
DATA Jan;
infile 'C:\Users\maa285\Desktop\MySAS\Jan.07';
input @1 type 1. code $ 2-3 ID $ 4-9 $ direction $ 10-10 lane $ 11-11 year
$ 12-13 $ month $ 14-15 $ day $ 16-17 $ hour $ 18-19 $ volume 20-24 $
class1 $ 25-29 $ class2 $ 30-34 $ class3 $ 35-39 $ class4 $ 40-44 $ class5
45-49 $ class6 $ 50-54 $ class7 $ 55-59 $ class8 $ 60-64 $ class9 $ 65-69 $
class10 $ 70-74 $ class11 $ 75-79 $ class12 $ 80-84 $ class 13 $ 85-89 $
class14 $ 90-94 $ class15 $ 95-99;
run;
proc print;
title 'january card';
run;

and the error message is:
LINE and COLUMN cannot be determined.
and:
Expecting a name.

Super User
Posts: 6,931

Re: fixed width text file import

Looks like you put an extra space in one variable name:  class 13 should be class13

Solution
‎09-05-2017 04:56 PM
Super User
Super User
Posts: 8,273

Re: fixed width text file import

Use the Insert Code or Insert SAS Code icons in the editor to paste in data and/or code so that the format is preserved.

Your INPUT statement has a lot of extra $.

input
  type 1-1
  code $ 2-3
  ID $ 4-9
  direction $ 10-10
  lane $ 11-11
  year $ 12-13
  month $ 14-15
  day $ 16-17
  hour $ 18-19
  volume $ 20-24
  class1 $ 25-29
  class2 $ 30-34
  class3 $ 35-39
  class4 $ 40-44
  class5 $ 45-49
  class6 $ 50-54
  class7 $ 55-59
  class8 $ 60-64
  class9 $ 65-69
  class10 $ 70-74
  class11 $ 75-79
  class12 $ 80-84
  class13 $ 85-89
  class14 $ 90-94
  class15 $ 95-99
;

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 2337 views
  • 0 likes
  • 4 in conversation