I have instructions to do the following:
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?
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.
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.
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;
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?
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!
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.