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
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;
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;
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.
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.
@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.
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;
Thank you for your swift responses on this, its appreciated
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.