BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The OR in code like

 where name='Alfred' or 'John';

does not apply the Name='John' condition to the where clause.

In effect it becomes the logical equivalent of

where 'John';

because there is no variable value compared. So the literal value of 'John' is always true since there is no comparison to a value in the data set. So all records are selected.

 

Note: you can test such yourself. You should have the  SASHELP.CLASS set available in your installation.

data junk;
   set sashelp.class;
   where name='Alfred' or 'John';
run;

The clue is in the LOG:

2713  data junk;
2714     set sashelp.class;
2715     where name='Alfred' or 'John';
2716  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
      WHERE 1 /* an obviously TRUE WHERE clause */ ;
NOTE: The data set USER.JUNK has 19 observations and 5 variables.

See the note with the "obviously true where clause". That tells you that whatever condition was applied is always true.

 

You would have been better off posting the PICTURE using the paste image icon, the camera, that appears above the message window instead of attaching a document if at all possible.

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

The OR in code like

 where name='Alfred' or 'John';

does not apply the Name='John' condition to the where clause.

In effect it becomes the logical equivalent of

where 'John';

because there is no variable value compared. So the literal value of 'John' is always true since there is no comparison to a value in the data set. So all records are selected.

 

Note: you can test such yourself. You should have the  SASHELP.CLASS set available in your installation.

data junk;
   set sashelp.class;
   where name='Alfred' or 'John';
run;

The clue is in the LOG:

2713  data junk;
2714     set sashelp.class;
2715     where name='Alfred' or 'John';
2716  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
      WHERE 1 /* an obviously TRUE WHERE clause */ ;
NOTE: The data set USER.JUNK has 19 observations and 5 variables.

See the note with the "obviously true where clause". That tells you that whatever condition was applied is always true.

 

You would have been better off posting the PICTURE using the paste image icon, the camera, that appears above the message window instead of attaching a document if at all possible.

 

 

PaigeMiller
Diamond | Level 26

Hey @Bhagyalakshmi please go back to you original post and provide a meaningful title that describes the SAS problem you are trying to understand, rather than a title that talks about how confused you are. Also, please keep this in mind as you create titles for future posts.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 965 views
  • 2 likes
  • 3 in conversation