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.
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:
Thanks a lot!
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:
Thanks a lot!
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.
Ready to level-up your skills? Choose your own adventure.