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?


 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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