BookmarkSubscribeRSS Feed
JT99
Obsidian | Level 7
Hello! I need to import a txt file with a column that exceeds 32000. This is a simplified version of my code. Sorry i’m using my phone since I can’t use my work laptop to login here.

%macro import(file)
Data file;
infile “/abc/defg/&file” truncover lrecl=32000;
input @1 banner $32000.;
data file;set file;
Enum=substr(banner,43,9);
Run;
%mend import;

How do I make banner spill to another column say banner2 if characters are more than 32000?
4 REPLIES 4
LinusH
Tourmaline | Level 20

Without having tried, I would use a second input variable:

input @1 banner $32000. @32001 banner2 $32000.;
Data never sleeps
yabwon
Onyx | Level 15

If there is more than 32k data in single line, you also probably want to increase the "lrecl=" to something bigger than 32k, e.g. "lrecl=1000000;"

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



Patrick
Opal | Level 21

IF you have access to a Viya 4 environment then you could load the .csv into a CAS table where you've got data type varchar(*) that can store more than 32KB characters.

Tom
Super User Tom
Super User

You don't seem to be "importing" anything.  You appear to just want to READ a text file.

For example to read up to 5*32000 bytes from each line into 5 character variables just do something like this:

data want;
  infile 'myfile' lrecl=1000000 truncover;
  input (var1-var5) ($char32000.);
run;

If the lines are varying length it will probably save space and be easier to work with if you read the text into multiple observations.

data want;
  infile 'myfile' lrecl=1000000 length=ll colum=cc truncover;
  row+1;
  do col=1 by 1 until(cc>ll);
    input string $char32000. @;
    output;
  end;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 748 views
  • 4 likes
  • 5 in conversation