BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

@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?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



acordes
Rhodochrosite | Level 12

Understood, thank you Bart. 

 

pic.png

 

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;
ballardw
Super User

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.

Tom
Super User Tom
Super User

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.

https://communities.sas.com/t5/SAS-Programming/How-to-import-a-csv-file-with-a-column-that-exceeds-l...

 

 

If you want more help parsing your existing file then you should share an example of the file. 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1264 views
  • 3 likes
  • 4 in conversation