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?
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.