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?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: