BookmarkSubscribeRSS Feed
krg1140
Calcite | Level 5

I have instructions to do the following:

  1. The variable AUDITOR_FKEY is coded 1, 2, 3, or 4 for the “Big 4” auditors.  Code the binary variable “BIGN” as 1 for “Big 4” auditors, and 0 otherwise.

However, I've never worked with binary values so I'm unsure how to do this? So far I have an if statement that reads data reg.sorted1; set reg.sorted;
if auditor_fkey =1 and auditor_fkey =2 and auditor_fkey=3 and auditor_fkey=4 then BIGN = 1;
else BIGN = 0;
run;

 

but this also doesn't run the correct values? Advice?

4 REPLIES 4
SASKiwi
PROC Star

A better way of doing what you want is this:

BIGN = (if auditor_fkey in (1,2,3,4));

The reason why your version doesn't work is you need to use OR not AND - AND assumes they use all 4 auditors at the same time which is impossible.

Tom
Super User Tom
Super User

Note that SAS only has two types of variables: floating point numbers and fixed length character strings.

So I assume by "binary" they mean a numeric variable that just only zero (false) or one (true).  Those are the values that SAS will return when it evaluates a boolean expression.

 

In your case you just want to test whether or not AUDITOR_FKEY has one of those four values.

data want;
  set have;
  bign = auditor_value in (1:4);
run;

The notation 1:4 is shorthand for the integers from 1 to 4, inclusive.

PhilC
Rhodochrosite | Level 12

Because you say you are new to Boolean expressions, I'd say I think you did well enough.  Does the instruction imply using ANDs or ORs?  I think I would have picked ANDs based on the instructions as well.  One thing that could go wrong is if AUDITOR_FKEY was a string variable type rather than numeric, as Tom said.  In that case the if statement would look like:

  if auditor_fkey ="1" and auditor_fkey ="2" /*...*/
    then BIGN = 1;
    else BIGN = 0;
ballardw
Super User

Just for completeness sake, is the value of AUDITOR_FKEY ever missing? As in did you confirm it is never missing?

If there are missing values do you want to assign 0 for those?

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