BookmarkSubscribeRSS Feed
ovonel
Calcite | Level 5

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

7 REPLIES 7
Ksharp
Super User
Using column input method:


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

ovonel
Calcite | Level 5

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.

Shmuel
Garnet | Level 18

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

Ksharp
Super User
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 .


Astounding
PROC Star

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.

ballardw
Super User

Any chance that is a tab and not 3 spaces?

 

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

Shmuel
Garnet | Level 18

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 ?

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
  • 7 replies
  • 1156 views
  • 0 likes
  • 5 in conversation