Hello everyone,
I have a table like this :
// | // | App1 | App2 | Pj1 | Pj2 | // |
// | // | 2 | 6 | . | . | // |
// | // | . | . | 5 | 9 | // |
// | // | . | . | 4 | 1 | // |
And I want to have this :
// | // | AP | AP2 | // |
// | // | 2 | 6 | // |
// | // | 5 | 9 | // |
// | // | 4 | 1 | // |
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
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;
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.
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;
There's always a value missing in a row.
Thank you very much ! I think this will work.
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!
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.