BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ramgouveia
Obsidian | Level 7
I want to identify the registers in a SAS dataset that in a character variable contains only zeros.
 
How can I do this?
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@ramgouveia wrote:
I want to identify the registers in a SAS dataset that in a character variable contains only zeros.
 
How can I do this?

So the variable is filled with zeros?  So if the variable is defined as length $10 it has 10 zeros?

Or do you also want the strings that have 9 zeros and those with 8 zeros?

 

Try this:

data test;
  input string $5. ;
cards;
1
0
00
000
0000
00000
.
;

data want;
 set test;
 want=  verify(string||'x','0')>length(string) ;
run;

proc print;
run;

Result

Obs    string    want

 1     1           0
 2     0           1
 3     00          1
 4     000         1
 5     0000        1
 6     00000       1
 7                 0

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

all zeros can be identified as

 

input(yourvariablename,?? best32.)=0
--
Paige Miller
Tom
Super User Tom
Super User

@ramgouveia wrote:
I want to identify the registers in a SAS dataset that in a character variable contains only zeros.
 
How can I do this?

So the variable is filled with zeros?  So if the variable is defined as length $10 it has 10 zeros?

Or do you also want the strings that have 9 zeros and those with 8 zeros?

 

Try this:

data test;
  input string $5. ;
cards;
1
0
00
000
0000
00000
.
;

data want;
 set test;
 want=  verify(string||'x','0')>length(string) ;
run;

proc print;
run;

Result

Obs    string    want

 1     1           0
 2     0           1
 3     00          1
 4     000         1
 5     0000        1
 6     00000       1
 7                 0

ramgouveia
Obsidian | Level 7

Thank you @Tom 

 

This is some example of the data I have:

 

data test;
  input string $9. ;
cards;
1103355
15126465
17007959
17008064
505495945
506795233
510150497
7133364
8418202
000000000
A36002541
000000000
a94150422
0
00
000
0000
00000
;

Your solution is a good solution.

This is a character variable. So I converted it into a numeric variable and all the "kind of" zeros were converted into a single zero.

 

I used the following code:

 

data CONT;
    set CONT;

    NP_N = input(NP, best12.) ;
run;

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
  • 4 replies
  • 500 views
  • 2 likes
  • 3 in conversation