BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
avhenao
Calcite | Level 5

Hello everyone!!

 

I'm trying to import a text file corresponding to a legal document. The file has approximately 125,000 characters in total, across almost 2,000 lines. I have managed to load the file to CAS into a table with one observation per record.

 

What I need to do is to concatenate all the data into a single variable, e.g.:

 

If the file contains the following:

 

This
is
a
sample
text

 

 

I want to get a dataset consisting of one variable and one row, like this:

Text
This is a sample text

 

I have come up with the following code:

 

cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US" metrics=true);
libname myCas cas caslib=casuser;
filename archivo "/path/to/file/file.txt" ;

data myCas.archivo1;
	length linea varchar(*);
	infile archivo 
		delimiter='0D0A'x
        DSD 
	;
	input linea $;
run;


data myCas.archivo2(drop=linea);
    length linea texto varchar(*);
    set myCas.archivo1 end=eof;
    retain texto;
	if not missing(linea) then
		texto = catx(" ",texto,linea);
    if eof then output;
run;

But, the resulting variable "texto" contains only 37486 characters.

Captura.PNG

 
 
Thanks a lot, guys!
 
Andres V.

 

1 ACCEPTED SOLUTION

Accepted Solutions
avhenao
Calcite | Level 5

Hello guys!

 

I made it! I mchange the code a little bit, so the file was imported to WORK and then to CAS

 

cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
libname myCas cas caslib=casuser ;
filename archivo "/path/to/file/prueba1.txt" ;

data archivo1;
	length linea $200;
	infile archivo 
		delimiter='0A'x
        DSD
		missover
	;
	input linea $;
run;

data myCas.archivo2(drop=linea);
    length texto varchar(*);
    set archivo1 end=eof;
    retain texto;
	if not missing(linea) then
		texto = catx(" ",texto,linea);
    if eof then output;
run;

And these are the results:

 

Captura2.PNG

 

Thanks a lot!

View solution in original post

1 REPLY 1
avhenao
Calcite | Level 5

Hello guys!

 

I made it! I mchange the code a little bit, so the file was imported to WORK and then to CAS

 

cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
libname myCas cas caslib=casuser ;
filename archivo "/path/to/file/prueba1.txt" ;

data archivo1;
	length linea $200;
	infile archivo 
		delimiter='0A'x
        DSD
		missover
	;
	input linea $;
run;

data myCas.archivo2(drop=linea);
    length texto varchar(*);
    set archivo1 end=eof;
    retain texto;
	if not missing(linea) then
		texto = catx(" ",texto,linea);
    if eof then output;
run;

And these are the results:

 

Captura2.PNG

 

Thanks a lot!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 833 views
  • 2 likes
  • 1 in conversation