Hi All,
Looking to see the best way to delete a row if all numeric variables are 0.
I've seen some examples of how to delete rows with all missing values and could all do IF missing() for each variable, however, I was hoping someone may know of an easier way (because I have 30 number columns) I have a table example below, the first 3 columns are formatted as a date, character, and character, the remaining are numbers.
| Date | Name | City | Count A | Count B | Count C | Count D | Count E |
| 01/01/2021 | John | NYC | 1 | 0 | 0 | 4 | 0 |
| 01/01/2021 | John | NYC | 0 | 0 | 0 | 0 | 0 |
| 01/01/2021 | Jane | NYC | 0 | 3 | 2 | 0 | 0 |
I saw some code like this, which didn't delete any records (I assume maybe because Date may be considered numeric?)
if nmiss(of _numeric_) then delete;
I also tried the below code, which didn't work and threw an error (error shown below code).
if sum(of 'Count A'n-'Count E'n)=0 then delete;
ERROR: Alphabetic prefixes for enumerated variables (Count A-Count E) are different.
ERROR 71-185: The SUM function call does not have enough arguments.
array t counta--counte; /*this assumes your variables are contiguous*/
the if sum(of t(*)) ne 0 whatever
alternatively
sum(of counta--counte) with a double dash list
Name range lists rely on the order of variable definition, as shown in the following table:
|
Variable List |
Included Variables |
|
|---|---|---|
|
x |
all variables in order of variable definition, from variable x to variable a inclusive |
|
|
x |
all |
|
|
x |
all |
|
array t counta--counte; /*this assumes your variables are contiguous*/
the if sum(of t(*)) ne 0 whatever
alternatively
sum(of counta--counte) with a double dash list
Name range lists rely on the order of variable definition, as shown in the following table:
|
Variable List |
Included Variables |
|
|---|---|---|
|
x |
all variables in order of variable definition, from variable x to variable a inclusive |
|
|
x |
all |
|
|
x |
all |
|
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.