Hi All
I have a list of values that i am checking in multiple fields. I have a hit if these values are present in any of the fields. Initially i coded it as below-
and ( a.dx1 in &dx.
or a.dx2 in &dx.
or a.dx3 in &dx.
or a.dx4 in &dx.
or a.dx5 in &dx.)
The issue was that i got result in which there were values other than my list in the fields DX2 to DX5 as they are separated by 'OR'
To fix this issue is re programmed as below-
and a.dx1 in &dx.
and (a.dx2 = ' ' or a.dx2 in &dx.)
and (a.dx3 = ' ' or a.dx3 in &dx.)
and (a.dx4 = ' ' or a.dx4 in &dx.)
and (a.dx5 = ' ' or a.dx5 in &dx.)
Now my issue is solved but i do not like the way it is programmed.
Is there a better way to write this? I mean a function or something that will ensure that either dx2-dx5 is a blank/missing value and if its not missing then its a value that i have listed in the macro variable &dx.
Note: As per business logic DX1 is always populated but dx2-dx5 can be blank also and its acceptable.
Thanks
Bhawna R.
Hi @ratnaparakhee,
You could add the missing value to the list &dx (if that is acceptable wherever &dx is used) and then write
and a.dx1 in &dx & a.dx1 ne ' ' and a.dx2 in &dx and a.dx3 in &dx and a.dx4 in &dx and a.dx5 in &dx
Other than that I don't see much potential for simplification.
If you could share some input data, and exemplify the different scenarios it would be easier to see possible solutions.
Hi @ratnaparakhee,
You could add the missing value to the list &dx (if that is acceptable wherever &dx is used) and then write
and a.dx1 in &dx & a.dx1 ne ' ' and a.dx2 in &dx and a.dx3 in &dx and a.dx4 in &dx and a.dx5 in &dx
Other than that I don't see much potential for simplification.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.