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?


 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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