Hi, I hope I am posting in the correct area. I would like to combine Gender1 and Gender5 with Gender5 being the winner if there is a value in both. Also for Education1 and Education5.
Is this possible in EG or EM?
I would do this in excel, but there are about 20 columns i would like to combine.
Any help would be appreciated.
Thanks!
Seth
id | Gender1 | Gender5 | Education1 | Education5 |
1 | F | 1 | ||
2 | F | 2 | ||
3 | F | 3 | ||
4 | F | 3 | ||
5 | F | 1 | ||
6 | M | 1 | ||
7 | F | |||
8 | F | 1 | ||
9 | F | 1 | ||
10 | F | 2 | ||
11 | F | 1 | ||
12 | F | 1 | ||
13 | F | M | 3 | 3 |
14 | F | 1 | ||
15 | F | 1 | ||
16 | F | 1 |
So the variables are in the same data set?
Use the coalesce function. In EG you can use the query builder and there you need to define a calculated column.
Yes, the variables are in the same data set.
What do you mean by combine? Can more than one variable have a value at the same time, i.e. Gender1=F Gender5=M?
For each ID there will only be one Gender value and one Education value like the combined columns below.
id | Gender Combined | Gender1 | Gender5 | Education Combined | Education1 | Education5 |
1 | F | F | 1 | 1 | ||
2 | F | F | 2 | 2 | ||
3 | F | F | 3 | 3 | ||
4 | F | F | 3 | 3 | ||
5 | F | F | 1 | 1 | ||
6 | M | M | 1 | 1 | ||
7 | F | F | ||||
8 | F | F | 1 | 1 | ||
9 | F | F | 1 | 1 | ||
10 | F | F | 2 | 2 | ||
11 | F | F | 1 | 1 | ||
12 | F | F | 1 | 1 | ||
13 | M | F | M | 3 | 3 | 3 |
14 | F | F | 1 | 1 | ||
15 | F | F | 1 | 1 | ||
16 | F | F | 1 | 1 |
The coalesceC function is what you're looking for.
In EG can use a computed column, not sure about EM but could always write a code node.
gender_combined=coalesceC(of gender1-gender5);
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.