infile- problem with blanks

Reply
Contributor
Posts: 20

infile- problem with blanks

Hi,

 

I'm trying to infile rpt. file and i have problems with values that have blanks.  Sas is giving me records from next column but I want him to show me the blank.

 

the file looks like this

 

5------10----

ab      cd

           1

null    null

null    null

           4

 

no i want to infile it

 

informat  ab  $CHAR2

 

data test;

infile 'path/rpt.' missover;

@5 ab: $CHAR2.

cd:;

run;

and the result is

 

ab     cd

1       1

null  null

null  null

4       4

 

Super User
Posts: 7,758

Re: infile- problem with blanks

When posting text where positioning is crucial, use the {i} button. The standard posting window eliminates leading blanks and the like, so your examples can't be used for testing.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,338

Re: infile- problem with blanks

You might want to post a few records from your file by attaching a TXT file if the data isn't sensitive. Your data step is syntactically incorrect as posted as you do not include an INPUT statement to start reading unless that just got missed in pasting.

 

Approaches to reading this will vary depending on the actual text file structure. It may be that you want to use column input to read at specific columns for your variables for instance.

 

 

Contributor
Posts: 20

Re: infile- problem with blanks

i cant add my file,sorry. this is just an example, you can write your own. the problem is that when i have blanks in record one, sas writes values from the next record and i dont know why

ive tried missover, pointers, and it is the same. Maybe because im infiling from rpt file not txt but im not sure
Super User
Super User
Posts: 7,035

Re: infile- problem with blanks

If you raw data file is arranged in fixed column locations then tell SAS that is what you want.  So let's assume this is what your data file looks like:

----5----10----
    ab   cd
         1
    null null
    null null
         4

Do not use the MISSOVER option instead use the TRUNCOVER option because it handles short lines better.

data want ;
  infile xx truncover ;
  input var1 $5-9 var2 $10-15 ;
run;

 

Contributor
Posts: 20

Re: infile- problem with blanks

ok I know what is the problem

 

sas treats blank space as a delimiter so it goes to the next record and reads it.

 

I can use dsd option but then i have to use pointer for every column. Is there any other solution ? cause i have like 300columns.

Super Contributor
Posts: 345

Re: infile- problem with blanks


Jedrzej wrote:

I can use dsd option but then i have to use pointer for every column. Is there any other solution ? cause i have like 300columns.


 

When reading a file in fixed width format you have to tell sas where each variable begins and how many chars belong to it.

Ask a Question
Discussion stats
  • 6 replies
  • 147 views
  • 0 likes
  • 5 in conversation