BookmarkSubscribeRSS Feed
cpmcn19
Calcite | Level 5

Attempting to create a new variable in a data step called top breed based on a breed column in previous data set. Data in breed column of old data varies, ie English Bulldog, American Bulldog, Labrador Mix, Labrador Retriever, Jack Russel Terrier, etc. 

Trying to write if then index code so that if breed contains Bulldog, Lab, Terrier, Beagle, or Shepherd topbreed = 1. If not 0. I have only been able to figure out the the coding for one breed I am trying to assign a value for. Is there any ways to add multiple if then index clauses within the same data step?

 

Current code: 

 

data new variable;

set old variables;

if index(breed, 'Bulldog') then topbreed = 1;

else topbreed = 0;

run;

 

Trying to get: if index(breed, 'Bulldog', 'Lab', 'Terrier', 'Shepherd', 'Beagle') then .... with no success 

1 REPLY 1
Reeza
Super User
This is still related to your previous question which is not marked as solved. Is there some reason you chose to open a new question? It helps to keep the discussion together so others know what's already been suggested.

In general though, with cleaning data and data that's fuzzy it's a bit of an interative approach. Things you need to consider, which you currently are not, are case differences, spelling differences, partial matches, and fuzzy matching - which is likely what you need. I suspect using LIKE in a SQL query may be more efficient overall but less accurate.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 353 views
  • 0 likes
  • 2 in conversation