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

find one race.JPG

 

I have a data set with many race variables, and the variables look like the attached picture.

I want to check if one of them is 'Y', other race variables are 'N', and print out any observations with two or more 'Y' in different race variables.

 

How do I write such code?

 

Thank you for the help! 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Depending on your actual data usage Hispanic Ethnicity may not exclude any race and some systems with these variable allow for "more than one race" type data.

 

 

data want;

    set have;

    if  countc(cats(h,w,b,a,ai,nhopi),'Y') >1;

run;

 

Where h,w,b,a,ai and nhopi are the names of your race variables and if they are actually character variables.

What this does is combine all of the variables into one string and then countc determines how many times the letter Y is in the result.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

If you want to write code, you need to know the names of the variables in your data set.

 

If you want someone here to write code, you have to tell us the names of the variables.

novinosrin
Tourmaline | Level 20

@Astounding   that was hilarious. Made me laugh. Nice one! lolSmiley Tongue

ballardw
Super User

Depending on your actual data usage Hispanic Ethnicity may not exclude any race and some systems with these variable allow for "more than one race" type data.

 

 

data want;

    set have;

    if  countc(cats(h,w,b,a,ai,nhopi),'Y') >1;

run;

 

Where h,w,b,a,ai and nhopi are the names of your race variables and if they are actually character variables.

What this does is combine all of the variables into one string and then countc determines how many times the letter Y is in the result.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 712 views
  • 1 like
  • 4 in conversation