I have 4 columns I am trying to concatenate and unconcatenate later
Var Samp Test Unit
A Sample1 Test1
A Sample2 kg
I tried the following catx("-", Var, Samp, Test, Unit); which will give me the following and doesn't leave any room for spaces. I would like to concatenate with the space so that I can unconcatenate later.
New
A-Sample1-Test1
A-Sample2-kg
Want
A-Sample1-Test1-
A-Sample2- -kg
As for unconcatenating, I would try somethig like the following but am unsure how to use the scan function.
data want;
set have;
array var(3) $;
do i = 1 to dim(var);
var[i]=scan(row,i,'-','M');
end;
run;
Your code seems fine.
Just add the variable names on the array statement.
Thanks. I've updated the other part of my question. In the concatenate part, how can I concatenate so that I still retain the spaces? The deliminator skips blanks.
did you try as below
catx(" - ", Var, Samp, Test, Unit);
The CATX() function will ignore missing (including all blank character values) when building the result. If you want to keep the space for missing values then build the string yourself. For just a few values just list them, for more use some type of DO loop.
string=cat(trim(a),'-',trim(b),'-',trim(c));
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 16. 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.