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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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