/* T1003210 load a file in one character variable(mystring) of length 128,004.
Associated problem. We really need to what the op wants to do with the
array of 32k chunks.
I load a file in one character variable(mystring) of length 128,004.
This type of problem is best solved with Perl or Python.
I present an R solution because I am a little more skilled in R.
inspired
https://goo.gl/eOu829
https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343429
HAVE (A file with two 64000 byte records)
=========================================
FILE: d:/txt/fyl1
RECORD 1: 64002 bytes first recrord (crlf once)
RECORD 2: 128004 bytes full file (crlf twice)
WANT ( load the the file both records into one character variable of length 128,004 bytes)
==========================================================================================
Pull some substrings out
1] "FILE LENGTH"
1] 128004
1] "substr(mystring,60001,60010)"
1] "1234567890"
1] "substr(mystring,30001,30010)"
1] "1234567890"
* _ _ _
_ __ ___ __ _| | _____ __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| | < __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___| \__,_|\__,_|\__\__,_|
;
data _null_;
length txt1 txt2 $32000;
txt1=repeat('1234567890',3199);
txt2=txt1;
do fyls=1 to 1;
fylvar=cats('d:/txt/fyl',put(fyls,1.));
file dummy filevar=fylvar lrecl=64000 recfm=v;
put txt1 +(-1) txt2;
put txt1 +(-1) txt2;
end;
run;quit;
NOTE: 2 records were written to the file DUMMY.
The minimum record length was 64000.
*____
| _ \
| |_) |
| _ <
|_| \_\
;
%utl_submit_r64('
library(readr);
mystring <- read_file("d:/txt/fyl1");
"FILE LENGTH";
nchar(mystring);
"substr(mystring,60001,60010)";
substr(mystring,60001,60010);
"substr(mystring,30001,30010)";
substr(mystring,30001,30010);
');
1] "FILE LENGTH"
1] 128004
1] "substr(mystring,60001,60010)"
1] "1234567890"
1] "substr(mystring,30001,30010)"
1] "1234567890"
... View more