SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dane7722
Fluorite | Level 6

I am trying to figure out a way to concatenate a set of columns, while skipping some when the value = "no". Unfortunately because of how the entire program is structured I am unable to change the no values to null.  Please let me know.. Thanks

image.png

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Changing no to null is the easiest way, because you can then use CATX.

You could duplicate the array and then set it to missing and use that. Otherwise you need to loop and conditionally apply catx each variable.

data want;
set have;

array _col(5) _col1-_col5;
array col(5) col1-col5;
do i=1 to 5;
if col(i) ne 'no' then _col(i)=col(i);
end;
want = catx("_", of _col(*));
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Can you post as plain text for me to copy paste and test

Reeza
Super User
Changing no to null is the easiest way, because you can then use CATX.

You could duplicate the array and then set it to missing and use that. Otherwise you need to loop and conditionally apply catx each variable.

data want;
set have;

array _col(5) _col1-_col5;
array col(5) col1-col5;
do i=1 to 5;
if col(i) ne 'no' then _col(i)=col(i);
end;
want = catx("_", of _col(*));
run;
dane7722
Fluorite | Level 6

Thank you!!

mohdfaisal89
Calcite | Level 5

Please Help !

 

I want to concatenate all the columns ending with _A in a table. I have more then 60 columns ending with _A in a table 90 columns

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3596 views
  • 0 likes
  • 4 in conversation