Hello,
I want to concat 3 columns but the content are to large, in the final concat i got blank.
Exemple : columns A , B, C => after concat ; var full = A;B;C
But i just got Blank,
if B and C are empty i get A, because not to large
but if A, B, C are not empty i get Blank. because to large string inside.
My code :
data work.amel;
set work.consoli;
full = catx(";", A,B,C);
run;
Thank you so much
From now on, when you are getting errors, please show us the log for the DATA step or PROC with the errors, including the code as it appears in the log and all ERRORs, WARNINGs and NOTEs.
You need a LENGTH statement in your DATA step, before you try to create FULL
length full $ 32;
where the 32 should be replaced by some other number that represents the max length of the resulting string.
What are the defined lengths of your variables A, B and C? Did the LOG show any notes or warnings? If so, copy the text of the LOG, open a text box window on the forum and paste the text of the log for the data step with all of the notes or other messages.
If you do not know the lengths of your variables then run:
proc contents data=work.consoli; run;
to show the properties of the variables.
IF you do not provide a defined length for the variable FULL then it will get a length of 200 which may result in truncated values if the variables combined are "long".
It is a best practice to assign a length to new character variables before use. In your example the length should be the total of the lengths of the variables A, B and C plus 2 to allow for the inserted semicolons. However a single variable is limited to 32K characters in SAS.
Hello,
i'm trying to concatenate 3 columns separated by commas but the final result: full displays nothing it's totally empty because the text is too large
example: varA
“stringA............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................stringA ”
in varB i have :
"stringB............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................stringB
in varC :
"stringC............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................stringC
after concat I must have var full = varA;varB;varC
with long texts separated by commas
Mycode :
data work.amel;
set work.consoli;
full = catx(";",A,B,C);
I got blank
I would verify each of your assumptions.
Confirm that work.consoli actually contains A, B, and C:
proc contents data=work.consoli;
run;
Next, confirm that A, B, and C contain data:
proc print data=work.consoli (obs=1);
var a b c;
run;
That will probably clarify what needs to change, but try it and see.
Related threads combined.
If the result of CAT... functions is too long for the target variable then nothing is saved. Example:
1 data test; 2 A='stringA'; 3 B='stringB'; 4 C='stringC'; 5 length full $20 ; 6 full=catx(';',a,b,c); 7 run; WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough to contain the concatenation of all the arguments. The correct result would contain 23 characters, but the actual result might either be truncated to 20 character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most argument that caused truncation. NOTE: Argument 4 to function CATX(';','stringA','stringB','stringC') at line 6 column 8 is invalid. A=stringA B=stringB C=stringC full= _ERROR_=1 _N_=1 NOTE: The data set WORK.TEST has 1 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Result
Obs A B C full 1 stringA stringB stringC
So define the variable long enough in the first place.
If you really want the value to be truncated so at least something is stored then wrap the function call in a SUBSTR() function call. You can use VLENGTH() to get the defined length of the target variable.
10 data test; 11 A='stringA'; 12 B='stringB'; 13 C='stringC'; 14 length full $20 ; 15 full=substr(catx(';',a,b,c),1,vlength(full)); 16 run; NOTE: The data set WORK.TEST has 1 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
Result
Obs A B C full 1 stringA stringB stringC stringA;stringB;stri
@Idi wrote:
StringA B and C are in dataset , i have no values in var full with your method.
Thanks for yr help
That makes no sense. Just use the dataset you already have.
Let's assume that A B and C exist in a dataset named HAVE and your goal is to make a new dataset named WANT that adds a new variable named FULL. So make sure you define FULL long enough to store the longest possible value.
data want;
set have;
length full $400 ;
full=catx(';',a,b,c);
run;
You cannot change the storage length of a variable once it has been set. In your data step for the variables A B and C that is done when the SET statement checks what is in CONSOLI.
Either remove A B and C from the LENGTH statement(s). Or move them to BEFORE the SET statement so they will actually have an impact.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.