here is my SAS code:
data nypd.aaa(compress=yes);
set nypd.master_y;
x_bw=0; if ARSTOFFN="CRIMINAL MISCHIEF" or "MAKING GRAFFITI" then x_bw=1;
label x_bw="Stops that led to arrest for Criminal Mischief or Making Graffiti";
run;
I'm trying to create a dummy variable that combines existing character variables in the dataset, which would be a metric for Broken Windows crimes. After testing the newly created x_bw variable with proc freq, it seems that the variable has only counted "CRIMINAL MISCHIEF". When I look look at the code, the "or" statement is not in blue text and seems that it is not performing its function. How can I get the "or" statement to work so that I can combine the variables into a dummy variable?
OR is not a statement. It is a boolean operator that takes two operands. If either operand is TRUE then the result is TRUE.
But "MAKING GRAFFITI" is not a expression that has true/false value.
You probably meant this:
if ARSTOFFN="CRIMINAL MISCHIEF" or ARSTOFFN="MAKING GRAFFITI" then x_bw=1
else x_bw=0;
Or since SAS will generate 1 for True and 0 for False you could eliminate the IF THEN ELSE part and just do this:
x_bw=ARSTOFFN="CRIMINAL MISCHIEF" or ARSTOFFN="MAKING GRAFFITI" ;
You could also look into using the IN operator instead.
x_bw=ARSTOFFN in ("CRIMINAL MISCHIEF" "MAKING GRAFFITI" ) ;
OR is not a statement. It is a boolean operator that takes two operands. If either operand is TRUE then the result is TRUE.
But "MAKING GRAFFITI" is not a expression that has true/false value.
You probably meant this:
if ARSTOFFN="CRIMINAL MISCHIEF" or ARSTOFFN="MAKING GRAFFITI" then x_bw=1
else x_bw=0;
Or since SAS will generate 1 for True and 0 for False you could eliminate the IF THEN ELSE part and just do this:
x_bw=ARSTOFFN="CRIMINAL MISCHIEF" or ARSTOFFN="MAKING GRAFFITI" ;
You could also look into using the IN operator instead.
x_bw=ARSTOFFN in ("CRIMINAL MISCHIEF" "MAKING GRAFFITI" ) ;
Thanks so much!
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 save with the early bird rate—just $795!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.