DATA Step, Macro, Functions and more

making sure data was entered correctly

Accepted Solution Solved
Reply
Contributor gsk
Contributor
Posts: 23
Accepted Solution

making sure data was entered correctly

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! 


Accepted Solutions
Solution
‎02-15-2018 03:34 PM
Super User
Posts: 13,292

Re: making sure data was entered correctly

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


All Replies
Super User
Posts: 6,624

Re: making sure data was entered correctly

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.

PROC Star
Posts: 1,555

Re: making sure data was entered correctly

Posted in reply to Astounding

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

Solution
‎02-15-2018 03:34 PM
Super User
Posts: 13,292

Re: making sure data was entered correctly

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 82 views
  • 1 like
  • 4 in conversation