@data_null__ I've read your blog post https://communities.sas.com/t5/SAS-Programming/Import-text-file-with-string-longer-than-32767/td-p/2... and it comes in very handy.
I'm exporting via code json files for Visual Analytics reports, they act as copy and transfer vehicle as you can rebuild the report with them.
But I'm struggling to adapt it to the _infile_ statement.
The following works (it's only part of tyhe code, I'm aware that you cannot re-run the code like this), but it derails when the string gets longer than 32767, in this case it becomes truncated.
data info;
length report $128
path $1024
content $32767;
infile content;
input;
report="&name";
path="&path";
content=_infile_;
run;
Si I've tried without success to adapt it in the following way:
data info;
length report $128
path $1024
content $32767;
infile content truncover ;
array part[10] $32767.;
input (part[*])($char32767.);
report="&name";
path="&path";
content=_infile_;
run;
I get as result the table 'info' with the column 'centent' containing the first 32767 characters of _infile_ and part1 is identical to content, but part2-part10 are empty.
Any idea?
Analyse this:
filename content TEMP recfm=n;
data _null_;
file content;
do I=1 to 10;
do l="a","b","c";
do j= 1 to 32767;
put l $char1.;
end;
end;
put '0a'x ;
end;
run;
filename content2 "%sysfunc(pathname(content))" lrecl=1000000000;
data info;
infile content2 truncover ;
array part[3] $32767.;
input (part:) ($char32767.);
run;
Bart
Analyse this:
filename content TEMP recfm=n;
data _null_;
file content;
do I=1 to 10;
do l="a","b","c";
do j= 1 to 32767;
put l $char1.;
end;
end;
put '0a'x ;
end;
run;
filename content2 "%sysfunc(pathname(content))" lrecl=1000000000;
data info;
infile content2 truncover ;
array part[3] $32767.;
input (part:) ($char32767.);
run;
Bart
Understood, thank you Bart.
filename content TEMP recfm=n;
data _null_;
file content;
do I=1 to 10;
do l="a","b","c", "d";
do j= 1 to choosen((l="d")+1, 32767, 5);
put l $char1.;
end;
end;
put '0a'x ;
end;
run;
filename content2 "%sysfunc(pathname(content))" lrecl=1000000000;
data info;
infile content2 truncover ;
array part[4] $32767.;
input (part:) ($char32767.);
run;
The _infile_ variable, like the rest of the variables is limited to 32K characters.
You would also have to set a LRECL greater than 32K on the Infile Statement to read more characters to begin with. To read 10 variables of length 32767 you would need Lrecl to be at least 10 times 32767
infile content lrecl=327670 ;
Depending on your operating system and/or the SAS system option LRECL the default length for Lrecl is very likely much less than you need.
The article you linked to is talking about WRITING existing long records to a different file by using the _INFILE_ directive on the PUT statement. There is no _INFILE_ statement. And if the logical record length of the file being read is longer then 32,767 then there will be no _INFILE_ automatic character variable.
If you want to read a value from a file that is longer than what can fit in one variable then you need multiple variables. Either multiple different variables, or multiple observations of the same variable.
Here is a post that is more appropriate for how to read from a file with a single value that is longer than can be stored in a variable.
If you want more help parsing your existing file then you should share an example of the file.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.