BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dman
Calcite | Level 5

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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" ) ;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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" ) ;

 

dman
Calcite | Level 5

Thanks so much!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 4782 views
  • 0 likes
  • 2 in conversation