data new;
x=' ';
z='abc';
run;
data new1;
set new;
zz=catx(',',x,z);
run;
I am trying to run this code but when I am opening the dataset new 1
Variable ZZ has value abc .It is not having ,
why ZZ is not having a value ,abc?
Catx function removes leading and trailing spaces from concatenated strings.
Hello,
The catx function has been designed that way.
The Basics
The CATX function first copies item-1 to the result, omitting leading and trailing blanks. Next, for each subsequent argument item-i, i=2, …, n, if item-i contains at least one non-blank character, CATX appends delimiter and item-i to the result, omitting leading and trailing blanks from item-i. CATX does not insert the delimiter at the beginning or end of the result. Blank items do not produce delimiters at the beginning or end of the result, nor do blank items produce multiple consecutive delimiters.
hello
But when I am running same code on SAS Host which I think is using SAS 9.2 there I am getting the , in the result
Is this thing works on SAS 9.2 but not on SAS 9.4 ?
From what I take from the CATX section in https://www.lexjansen.com/scsug/2016/SCSUG_2016_Horstman_string_concatenation.pdf, the behavior of CATX has been the same in 9.2. It might be that the variable used in your mainframe SAS code is not really empty, but has a non-displayable character.
You had posted a comma preceding the abc in your original post.
Check again.
Yes because I am using the function like this
zz=catx(',',x,z);
where x=, and Z='abc'
There is no difference in this regard in the SAS 9.2 documentation :
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002257076.htm
Check that it is indeed the same code that is run on the other host.
Hi @shubham1
CATX ignores arguments with missing values. It takes a list of variables and put a delimiter between <something> and <something>. So it never returns a string with a leading delimiter, a trailing delimiter or 2 or more consecutive delimiters. If you want delimiters between all elements, missing or not, I don't think there is a simple function. But it can be done with an array, see the following code:
data new;
a=' ';
b = 'abc';
c=' ';
d=' ';
e = 'efg';
f=' ';
run;
* No delimiters between missing;
data _null;
set new;
zz=catx(',',a,b,c,d,e,f);
put zz;
run;
/* Result:
abc,efg
*/
* Delimiters between all variables;
data _null_;
set new;
array elements[*] _character_;
length zz $20.;
zz = elements{1};
do i = 2 to dim(elements);
zz = trim(zz) || ',' || trim(elements{i});
end;
put zz=;
run;
/* Result:
,abc,,,efg,
*/
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.