Hi there, I am trying to find a way to create a categorical variable in which:
1 = Mixed (given there is text in both columns 1 and 2)
2 = Unknown
3 = Purebred type 1
.
.
.
n = Purebred type n
Given the sample dataset:
ID | Column 1 - Breed 1 | Column 2 - Breed 2 | Desired Column |
1 | Poodle | Purebred - Poodle | |
2 | Poodle | Husky | Mixed |
3 | Husky | Purebred - Husky | |
4 | Maltese | Purebred - Maltese | |
5 | Poodle | Maltese | Mixed |
6 | Unknown | Unknown | |
7 | Golden Retriever | Poodle | Mixed |
Then you would check if the code was 0 rather than missing.
@advmsj wrote:
@Reeza wrote:
Check if the second column is missing, if it is, use Column1, otherwise set it to Mixed.
if missing(column2) then desired_column = column1;
else desired_column = 'Mixed';Thank for you this solution. What the missingness in column 2 is denoted with a 0. How does the code change?
@Reeza wrote:
Check if the second column is missing, if it is, use Column1, otherwise set it to Mixed.
if missing(column2) then desired_column = column1;
else desired_column = 'Mixed';
Thank for you this solution. What the missingness in column 2 is denoted with a 0. How does the code change?
Then you would check if the code was 0 rather than missing.
@advmsj wrote:
@Reeza wrote:
Check if the second column is missing, if it is, use Column1, otherwise set it to Mixed.
if missing(column2) then desired_column = column1;
else desired_column = 'Mixed';Thank for you this solution. What the missingness in column 2 is denoted with a 0. How does the code change?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.