In R you can perform a condition across all rows in a column variable by using the all() or any() function. Is there an equivalent method in SAS?
I want condition if ANY rows in column x are negative, this should return TRUE.
Or, if ALL rows in column y are negative, this should return TRUE.
For example
x y
-1 -2
2 -4
3 -4
4 -3
In R:
all(x<0)would give the output FALSEall(y<0)would give the output TRUE
I wish to replicate the same column-wise operation in SAS.
If you want to operate on all observations that might be easiest to do using SQL summary functions.
SAS will evaluate boolean expressions as 1 for true and 0 for false. So to find out if any observation has a condition you want to test if the
MAX( condition )is true (ie equal to 1). To find out if all observations have the condition you want to test if theMIN( condition )is true.Result