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.
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.