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!
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.