BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
advmsj
Obsidian | Level 7

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:

IDColumn 1 - Breed 1Column 2 - Breed 2Desired Column
1Poodle Purebred - Poodle
2PoodleHuskyMixed
3Husky Purebred - Husky
4Maltese Purebred - Maltese
5PoodleMalteseMixed
6Unknown Unknown
7Golden RetrieverPoodleMixed
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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?


 

View solution in original post

3 REPLIES 3
Reeza
Super User
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';
advmsj
Obsidian | Level 7

@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
Super User

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?


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1142 views
  • 0 likes
  • 2 in conversation