@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
all zeros can be identified as
input(yourvariablename,?? best32.)=0
@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
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;
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!
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.