I have a dataset which is created using datastep as shown below.
input x y $;
I want the output dataset to be
i.e. subsetting the obeservation where y should have only numeric values.
When I use the SAS code,
if y ne 'as' or y ne 'aq';
I'm not getting the desired output instead I have all the data points.
But the desired output is obtained when the following SAS code is used.
if y ne 'as' and y ne 'aq';
Usually the generic understanding is whenever we don't want either 'as' or 'aq', we can use OR operator in IF statement. But in the given code it works well using AND operator. Can anyone give the explanation on how does SAS work when these OR & AND operators are used in the IF statement?
Let's go through the logic of your subsetting if statement.
The first record x=12, y=as
Your logic: if y ne 'as' or y ne 'aq';
y ne 'as', so that is false
y ne 'aq', so that is true
With an OR statement any true resolves to true, hence false or true will resolve to true. With an AND both statements need to be true for it to resolve to true, which is why the AND works and the or does not
BTW: SAS has a function called NOTDIGIT which searches a character string for any character that is not a digit and returns the first position at which that character is found
* For Example;
if num_check then delete;