BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BlayLay
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

Name range lists rely on the order of variable definition, as shown in the following table:

Name Range Lists

Variable List

Included Variables

x - - a

all variables in order of variable definition, from variable x to variable a inclusive

x -NUMERIC- a

all numeric variables from variable x to variable a inclusive

x -CHARACTER- a

all character variables from variable x to variable a inclusive

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20

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

Name range lists rely on the order of variable definition, as shown in the following table:

Name Range Lists

Variable List

Included Variables

x - - a

all variables in order of variable definition, from variable x to variable a inclusive

x -NUMERIC- a

all numeric variables from variable x to variable a inclusive

x -CHARACTER- a

all character variables from variable x to variable a inclusive

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2619 views
  • 0 likes
  • 2 in conversation