- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Tags:
- concatenate
- sas
- scan
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your code seems fine.
Just add the variable names on the array statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
did you try as below
catx(" - ", Var, Samp, Test, Unit);
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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));