BookmarkSubscribeRSS Feed
Jedrzej
Obsidian | Level 7

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

 

6 REPLIES 6
Kurt_Bremser
Super User

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.

ballardw
Super User

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.

 

 

Jedrzej
Obsidian | Level 7
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
Tom
Super User Tom
Super User

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;

 

Jedrzej
Obsidian | Level 7

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.

andreas_lds
Jade | Level 19

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 3926 views
  • 0 likes
  • 5 in conversation