DATA Step, Macro, Functions and more

Listing all entries that have certain number of digits

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 77
Accepted Solution

Listing all entries that have certain number of digits

Hello,

 

I have a list of IDs that may contain invalid entries. I am trying to find a code that will let me list specifically any IDs that have a scheme of 10 numeric only digits. Here's my sample dataset:

 

data CDC.IDCHECK1;
  infile datalines dsd truncover;
  input id:$20.;
datalines4;
1017003801
1017004496
1030026248
54001035830
01852007047
01009007174
01009011515
25001025286
61006035046
24001040480
36450004527
36650000268
24301052233
01701118316
60250040109
01450104046
01024026940
65240000170
01010002662
60001072076
01013014318
01952010879
01853006185
01150004587
01353000726
31001006047
16001011547
11001016837
01027058475
01005035399
01024082887
34001008435
01003017389
01025002276
01024007351
01750007924
59001048134
25001026800
59101137244
46001003301
01001098053
01650094658
51001030463
24301050497
01150095595
01010010724
01002008858
01150103312
01027027431
31001050508
59001090681
12001026057
37650001125
01950101954
01250118327
01009003600
44501005965
01017025728
01001070822
24001007336
62001044471
20001063785
01005034793
01753006003
36250004683
01019072387
01024037949
43350001835
01450031804
14350000313
01017037087
36001001131
01013011655
01017046940
01408064857
05001002999
19001055872
01350077716
59650011040

01036005010
35001051420
59001126232
01550110872
01154009238
59901131225
39450008278
01010000112
01024053273
01150098508
01950105445
12001083915
01011072696
01030042967
19450011582
61350033457
01030005854
18401073355
18001061841
54001058777
60001124114
62006063280
01001047111
60001031201
19001111515
60650049138
41001031497
60450049044
19001024963
37001050981
58001026071
01001069323
01350129082
01450019547
01350030184
01454017744
01350007135
01356001807
01008028061
33001012216
01411117357
59250007583
19350000210
01451008751
35001119536
12001081589
01652011501
59001116752
01917058525
57001059823
01653005083
28001069071
11001031685
60001146443
20001059557
01019075202
51001002076
58001030321
60001136222
01017051380
01008056466
62001038612
01019064254
01007000258
01150029775
01101116737
38250002551
59001107898
01556005187
37001034239
12001096076
01653012824
01020012654
12001091225
01753018593
01752012081
61004066744
01217060612
36001051906
01351005781
01008007592
01008007592
01353009827
28001115701
01005036939
01011096113
01950001518
01353003039
01008049831
62007016134
01024062979
08650000372
25001037580
01001088584
59001120554
01850074054
01025001728
01024016041
12001034205
01119090854
01756006870
19650000402
01156012300
01654016471
01308070038
01554014133
01956001375
01950009774
01024023256
01154016829
01654006204
01017050860
40101041836
36001051200
62001039524
25001030802
01013028581
01951001261
54001056268
01005021482
01654007615
01354002941
40001005767
01019051853
01006013029
65008001689
31001055566
01024024648
01950001585
31001054894
01008052845
57250001513
11001008329
01656010065
15001022902
59001037346
01011095409
38650003397
26001035025
50001002602
15950001132
01354018730
37001051888
01001075397
01854020413
01356001824
29001024493
10001064879
54901062531
04001002283
01027073713
01027010604
54001055954
01008062251
20001016250
01253007609
29001039830
01005028498
46001001192
01191013912
13001000370
25001044744
01005021401
61002011154
13001001516
01017057497
12001090160
08901039692
01027073746
61001081885
59001089592
01024090343
01753007711
16001015689
57601062164
62003000480
62007015150
54750002202
18001007396
54001022514
54001021071
54950003024
54001016193
54001023640
39550007273
54250001523
54001011993
01020008796
54450002795
54001057971
54001036907
54550001690
54001058946
54850002444
01491008363
53001043657
01027056952
43001011584
30001007194
28350014949
28550016019

01019036722
60002018992
51001002623
14001002011
05001008502
31001048778
35001085427

01027007382
01030049220
01030050171
01007014276
54001015520
01005041050
01025011402
01001003231
01030032854
14001010134
01013025284
01015008851
01008000383
01027025638
59001093041
59004004315
01027013342
01019020492
62001001160
20001004412
01007007691
01015017126
01030021431
01019008069
01030050206
08001037620
01008046169
56001001136
01026015589
01030024266
01013012120
01030048699
01030031693
39001012369
01027074388
33001056811
01030029860
39001033778
01006021601
01021014328
01019025522
01030048975
01005009151
01013028242
01030020521
01030030984
01030016752
50001001904
19001054287
01030007714
62001030462
01030039116
01030044675
01001004128
01005043163
19001079035
01030020058
01030039687
01030038656
01005014146
01019008634
01024042785
01005035120
62006024184
40001007860
24001044790
61007000821
01027037994
01011016125
01020008323
01017017462
01005003841
01012016001
62001033277
54001022883
01015021441
01030045346
01027021668
01030016092
01024039549
01005044596
31001019207
35001084692
13001034198
01005017422
02001004575
53001060320
01005001086
31001043312
01030046676
19001050266
01007002703
01012010387
51001005793
01008029222
01018004618
01030000107
59001057956
54001003765
35001043185
02001002122
01017046664
01017030361
27001002100
36001034346
01008030297
01030005189
36501054239
22001023334
01030020726
39001016535
01030031045
01011028360
01019036469
01011080966
01030035195
61006049528
01019074778
37001023464
42850001249
14001006052
35001039839
01027008572
01025002219
43001018077
01013024963
01019057790
01003005562
11001026359
28001061229
31001037986
45001036822

38650000638
01850094293
01652002575
22001021960
38450002335
01150020545
05001002706
05001003746
05001008799
05001006266
05001008986
05001002121
05001009732
05001009798
05001010793
05001000949
49001008149
49001010048
49001010470
60002007346
49001010851
49001013022
49001006905
49001007359
49001006377
49001008208
49001003227
49001004372
61006055089
62003003044
36001011722
59001035787
23001006819
61006026123
20001064283
34001002976
20001010227
58001004098
18001010738
60001106345
56001002953
01001061950
19001102939
42001026262
42001039111
42001037902
42001040457
01029019079
42001008590
62005025747
02001020774
42001039226
02201026308
42401041336
42001035142
42001024839
02001020108
42001023208
42001033109
48001010640
42001034782
42001011232
56001000880
01024029944
01024023389
01013022535
35001108263
01011007359
61009003054
59004003792
61009003054
62006039018
12001041735
51001020194
28001051296
57001024914
01013022535
1017003802
1017003803
;;;;

Thank you so much for your help!

 


Accepted Solutions
Solution
‎03-22-2017 04:57 AM
Super User
Posts: 7,758

Re: Listing all entries that have certain number of digits

Use the notdigit() and length() functions:

data want;
set have;
if length(id) = 10 and notdigit(id) = 11;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎03-22-2017 04:57 AM
Super User
Posts: 7,758

Re: Listing all entries that have certain number of digits

Use the notdigit() and length() functions:

data want;
set have;
if length(id) = 10 and notdigit(id) = 11;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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