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

Hi Everyone,

 

I have this problem that looks sooooo simple but can't seem to figure it out, as it gives no errors.

 

I have this variable called 'specialty'. It consists of numeric values.

 

I want to extract only the code 1 and 95 from my data set. I used the code below:

data specialty_code;
set master_data;
where specialty=1 and 95;
run;

When I submit it, it runs smoothly and gives me the observation number of x. but when I do a quick quality check, it only kept the specialty code 1 and didn't keep any of the code 95. Am I using the where statement wrong? It worked when I used where-and statement for 2 different variables.

 

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try "in" operator

 

data specialty_code;
set master_data;
where specialty in (1 95);
run;
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try "in" operator

 

data specialty_code;
set master_data;
where specialty in (1 95);
run;
Thanks,
Jag
Reeza
Super User

Where specialty in (1 95);

PGStats
Opal | Level 21

For SAS any number other than 0 or missing is equivalent to the logical value TRUE. When specialty is 1, specialty=1 evaluates to TRUE, then TRUE and 95  is equivalent to TRUE and TRUE which evaluates to TRUE. When specialty is 95, or anything other than 1, you end up with the equivalent of FALSE and TRUE, which is FALSE. The proper syntax is:

 

data specialty_code;
set master_data;
where specialty=1 or specialty=95;
run;

/* Or */

data specialty_code;
set master_data;
where specialty in (1, 95);
run;

 

 

PG

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!

How to Concatenate Values

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.

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
  • 3 replies
  • 825 views
  • 4 likes
  • 4 in conversation