🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Obsidian | Level 7

## Reading a Txt file that is all one line of consistant data.

Hello there.

I'm a little stuck and was sondering if someone had a solution to my problem. Im on version 9.3

I have a text file that contains account numbers. These account numbers are all 16 digits long but are all in one row in the text file.

My question is, is there a way to create an observation for each of the 16 digit account numbers

so 123456788765432112345678876543211234567887654321

would become

1234567887654321

1234567887654321

1234567887654321

Many thanks in advance for any help

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Reading a Txt file that is all one line of consistant data.

``````data want (keep=accountid);
infile 'path' lrecl=32000;
length line_in \$ 32000;
input;
line_in = _infile_;
i = 1;
do until i > length(line_in)
accountid = substr(line_in,i,16);
output;
i = i + 16;
end;
run;``````

Now, if you have no records at all (the file being one quasi-infinite stream):

``````data want;
infile 'path' lrecl=16 recfm=f;
input accountid \$16.;
run;
``````
7 REPLIES 7
Super User

## Re: Reading a Txt file that is all one line of consistant data.

``````data want (keep=accountid);
infile 'path' lrecl=32000;
length line_in \$ 32000;
input;
line_in = _infile_;
i = 1;
do until i > length(line_in)
accountid = substr(line_in,i,16);
output;
i = i + 16;
end;
run;``````

Now, if you have no records at all (the file being one quasi-infinite stream):

``````data want;
infile 'path' lrecl=16 recfm=f;
input accountid \$16.;
run;
``````
Obsidian | Level 7

## Re: Reading a Txt file that is all one line of consistant data.

data want;
infile 'path' lrecl=16 recfm=f;
input accountid \$16.;
run;

this worked except I had to remove
lrecl=16 recfm=f;

otherwise it didnt keep 16 for each record (some were 15)
Jade | Level 19

## Re: Reading a Txt file that is all one line of consistant data.

Show the log messages from both with and without LRECL and RECFM.

Seems to me that you may have record separaters that you are not aware and or other file qualities that you don't know.

Super User

## Re: Reading a Txt file that is all one line of consistant data.

In this case, I would take a more in-depth look at the file with a tool that shows all bytes (hexedit, hexdump or anything similar). It seems that you do have something that SAS treats as line separators.

Jade | Level 19

## Re: Reading a Txt file that is all one line of consistant data.

@Kurt_Bremser wrote:

In this case, I would take a more in-depth look at the file with a tool that shows all bytes (hexedit, hexdump or anything similar). It seems that you do have something that SAS treats as line separators.

SAS has tools for that too.  One being the LIST; statement.

Diamond | Level 26

## Re: Reading a Txt file that is all one line of consistant data.

Well, you can read the file one character at a time, then an if statement to check length:

```data want (drop=chr);
length id \$16;
retain id;
infile "s:\temp\rob\tmp.txt" recfm=n;
input chr \$char1.;
id=cats(id,chr);
if lengthn(id)=16 then do;
output;
id="";
end;
run;```
Obsidian | Level 7

## Re: Reading a Txt file that is all one line of consistant data.

Thank you for your swift responses on this, its appreciated

Discussion stats
• 7 replies
• 2917 views
• 2 likes
• 4 in conversation