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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.