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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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