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

Hello everyone, 

 

I have a table like this : 

////App1App2Pj1Pj2//
////26..//
////..59//
////..41//

 

And I want to have this : 

////APAP2//
////26//
////59//
////41//

 

The idea is to concatenate the columns. 

Do I have to use cat functions here ? Because I have several columns to use and I don't know how to apply this in my case. 

 

// = random numbers, not important 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

And what should happen if more than one value is non-missing?

In the meantime try

data want;
  set have;
  /* assuming all vars are numeric */
  ap1 = coalesce(App1, Pj1);
  ap2 = coalesce(App2, Pj2);

  /* maybe drop the old vars */
  drop App1 App2, Pj1 Pj2;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User

It might help to describe which "column" is concatenated with which.

It might be that you are looking for COALESCE but with out stating which "columns" are combined to get the output I can't be sure. Example might be

                    SQL: Coalesce (AP, Pji) as Ap.

              data step:   Ap = Coalesce (AP, Pji);

Coalesce goes through a list of variables from left to right and returns the first non-missing(if any) value.

And

 

Not a transpose and SQL is generally a poor tool for transpose.

Adir92
Obsidian | Level 7
Thank you,

I want to App1 and Pj1 ---> AP ; App2 and Pj2 ----> AP2
andreas_lds
Jade | Level 19

And what should happen if more than one value is non-missing?

In the meantime try

data want;
  set have;
  /* assuming all vars are numeric */
  ap1 = coalesce(App1, Pj1);
  ap2 = coalesce(App2, Pj2);

  /* maybe drop the old vars */
  drop App1 App2, Pj1 Pj2;
run;
Adir92
Obsidian | Level 7

There's always a value missing in a row. 

 

Thank you very much ! I think this will work. 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 721 views
  • 2 likes
  • 3 in conversation