BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Waby
Fluorite | Level 6

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;

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20
You don't need spaces to parse it back to its initial components.

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

Your code seems fine.

Just add the variable names on the array statement.

Waby
Fluorite | Level 6

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.

Jagadishkatam
Amethyst | Level 16

did you try as below

 

catx(" - ", Var, Samp, Test, Unit);
Thanks,
Jag
Waby
Fluorite | Level 6
I did but thanks for your suggestion. I ended up resolving the issue in the unconcatenate section.
ChrisNZ
Tourmaline | Level 20
You don't need spaces to parse it back to its initial components.
Tom
Super User Tom
Super User

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));

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1344 views
  • 1 like
  • 4 in conversation