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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1266 views
  • 0 likes
  • 2 in conversation