DATA Step, Macro, Functions and more

Blanks in first few columns

Reply
Occasional Contributor
Posts: 6

Blanks in first few columns

Hi

 

I have 2 lines of data below. The 1st three characters are for ID, however 2nd row is missing the ID.

 

How can I read this file properly with the INFILE statement? MISSOVER doesn't work in this case.

 

193F1010790815950407011206811

     M1015950215960408009805410

 

Thank you

Super User
Posts: 9,681

Re: Blanks in first few columns

Using column input method:


data have;
input id $ 1-3 sex $ 4-4 others $ 5-30;
cards;
193F1010790815950407011206811
   M1015950215960408009805410
;
run;

Occasional Contributor
Posts: 6

Re: Blanks in first few columns

Hi. Thanks.

 

I am aware of column input, however M10 becomes the ID and the rest moves to the left.

 

ID in 2nd row is supposed to be blank.

 

The MISSOVER in infile does not help.

Trusted Advisor
Posts: 1,378

Re: Blanks in first few columns

change your input line to:

 

input @1 ID $CHAR3.

          @4 sex $1. 

          @5 others $char26.

 ;

the @ assigns from which postion to read 

the informat $CHAR3. means to read 3 characters without any alignment of data

othrwise, the default of input statement is to align the data to left.

 

you may change read sex as 1. if you preffer it numeric, instead $1. or $char1. as a character.

 

Shmuel

Super User
Posts: 9,681

Re: Blanks in first few columns

If that was true , then the second row maybe don't have blanks before M10.
You should check your data firstly and Post some real data here .


Super User
Posts: 5,082

Re: Blanks in first few columns

Both of the suggestions you have received are viable approaches.  If you get M10 as the value of ID, something is different than what you have presented.  Maybe M10 is actually in columns 1 through 3.  Maybe you tried a different INPUT statement.  But the suggestions you have received work properly on the data you have shown.

Super User
Posts: 10,500

Re: Blanks in first few columns

Any chance that is a tab and not 3 spaces?

 

And what does your current infile and input statement look like?

Trusted Advisor
Posts: 1,378

Re: Blanks in first few columns

you may check the contents of ID by PUT ID $HEX6. to the log.

Locate the statement at the end of INPUT statement.

In case of TAB you will see '09'x in the 1st character;

What do you get in the log ?

Ask a Question
Discussion stats
  • 7 replies
  • 321 views
  • 0 likes
  • 5 in conversation