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: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 808 views
  • 2 likes
  • 3 in conversation