Hello
I am using CATX to concatenate multiple string fields with delimator minus between them.
In the resulted field I get value 100-200-300-.-.-.-.-.-.-.
However I want to concatenate only mon-missing fields that the value will be 100-200-300
What is the way to correct it please?
Data have;
input X1 X2 X3 X4 X5 X6 X7 X X9 X10;
cards;
100 200 300 . . . . . . .
;
Run;
Data wanted;
set have;
Vector=CATX('-',OF X:);
Run;
CATX() id doing implicit conversion from number to text so "missing value" is set to a "dot",
Data have;
input X1 X2 X3 X4 X5 X6 X7 X X9 X10;
cards;
100 200 300 . . . . . . .
;
Run;
Data wanted;
set have;
array XX X:;
length Vector $ 100;
do over XX;
if XX then Vector=CATX('-',Vector, XX);
end;
Run;
proc print;
run;
Bart
CATX() id doing implicit conversion from number to text so "missing value" is set to a "dot",
Data have;
input X1 X2 X3 X4 X5 X6 X7 X X9 X10;
cards;
100 200 300 . . . . . . .
;
Run;
Data wanted;
set have;
array XX X:;
length Vector $ 100;
do over XX;
if XX then Vector=CATX('-',Vector, XX);
end;
Run;
proc print;
run;
Bart
Read the doc. 😉
"In SAS, any numeric value other than 0 or missing is true, and a value of 0 or missing is false."
Bart
options missing=' '; Data wanted; set have; Vector=CATX('-',OF X:); Run;
Since your issue resolves around MISSING values consider the options involved with missing:
options missing=' ';
Data wanted;
set have;
Vector=CATX('-',OF X:);
Run;
options missing='.';
You get all the - in your result because, as correctly stated by @yabwon the implicit conversion to the dot character for missing numeric. Setting the Missing option to a blank means the conversion still happens but CATX will remove all trailing blanks, the only character, and get the desired result.
When using this approach don't forget to reset the missing option to avoid other possible confusions.
I think a better idea is to use arrays on X1-X10, rather than the much harder creating the proper string with missings '100-200-300' and then working with this string. Then its easy to test to see if X4 is missing and just skip processing in that case.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.