I apply the anyalpha function as a filter in row 35, however, it fails to stop all the cases where there is an alphabetic character. However, when I attempt to flag them after creating a new variable it does pick them up (see row 51). What gives?
28 data POS17;
29 length CCN $6;
30 set SAS.POS_DEC17(keep=&POSVARS);
31 /*AP filters, see item A.1.a.*/
32 if PRVDR_CTGRY_CD = '01'
33 and PRVDR_CTGRY_SBTYP_CD = '01'
34 and length(PRVDR_NUM) = 6
35 and anyalpha(PRVDR_NUM) = 0
36 and ELGBLTY_SW EQ "Y"
37 and ORGNL_PRTCPTN_DT le "2017.0101"
38 and TRMNTN_EXPRTN_DT = '' or TRMNTN_EXPRTN_DT gt "2017.0101"
39 ;
40 if STATE_CD in ('AS', 'FN', 'GU', 'MP', 'MX', 'PR', 'VI', 'MD')
41 or PRVDR_NUM in ('050204' '100006' '310008' '330059'
42 '050238' '100073' '310012' '330119'
43 '050351' '100080' '310019' '330167'
44 '050481' '100131' '310054' '330198'
45 '050485' '100228' '310074' '330205'
46 '050603' '100253' '330024' '330214'
47 '050678' '100275' '330045' '360027'
48 '070022' '310005' '330046' '450056')
49 then delete;
50 ccn=trim(Prvdr_num);
51 if _n_ lt 10000 and anyalpha(CCN) gt 0 then put _n_= PRVDR_NUM=;
52 run;
_N_=4259 PRVDR_NUM=03C0001312
_N_=4370 PRVDR_NUM=03X0009825
_N_=6220 PRVDR_NUM=04A327
I think you've got an order of operations problem. Note the last line of your subsetting IF:
32 if PRVDR_CTGRY_CD = '01' 33 and PRVDR_CTGRY_SBTYP_CD = '01' 34 and length(PRVDR_NUM) = 6 35 and anyalpha(PRVDR_NUM) = 0 36 and ELGBLTY_SW EQ "Y" 37 and ORGNL_PRTCPTN_DT le "2017.0101" 38 and TRMNTN_EXPRTN_DT = '' or TRMNTN_EXPRTN_DT gt "2017.0101" 39 ;
Because you have an OR at the end, any record with TRMNTN_EXPRTN_DT gt "2017.0101" will be kept, even if it has alpha characters in PRVDR_NUM. I suspect you should add parentheses to that last line, i.e.:
32 if PRVDR_CTGRY_CD = '01' 33 and PRVDR_CTGRY_SBTYP_CD = '01' 34 and length(PRVDR_NUM) = 6 35 and anyalpha(PRVDR_NUM) = 0 36 and ELGBLTY_SW EQ "Y" 37 and ORGNL_PRTCPTN_DT le "2017.0101" 38 and (TRMNTN_EXPRTN_DT = '' or TRMNTN_EXPRTN_DT gt "2017.0101") 39 ;
I suspect that you need to carefully examine the order of operations being performed and examining ALL of the variables used in that IF statement when you get unexpected results. Without more complete data for an example I might start by looking at values of TRMNTN_EXPRTN_DT for those records.
Code like TRMNTN_EXPRTN_DT gt "2017.0101" can be pretty problematic as comparison of string values with greater or less often yields unexpected results
I think you've got an order of operations problem. Note the last line of your subsetting IF:
32 if PRVDR_CTGRY_CD = '01' 33 and PRVDR_CTGRY_SBTYP_CD = '01' 34 and length(PRVDR_NUM) = 6 35 and anyalpha(PRVDR_NUM) = 0 36 and ELGBLTY_SW EQ "Y" 37 and ORGNL_PRTCPTN_DT le "2017.0101" 38 and TRMNTN_EXPRTN_DT = '' or TRMNTN_EXPRTN_DT gt "2017.0101" 39 ;
Because you have an OR at the end, any record with TRMNTN_EXPRTN_DT gt "2017.0101" will be kept, even if it has alpha characters in PRVDR_NUM. I suspect you should add parentheses to that last line, i.e.:
32 if PRVDR_CTGRY_CD = '01' 33 and PRVDR_CTGRY_SBTYP_CD = '01' 34 and length(PRVDR_NUM) = 6 35 and anyalpha(PRVDR_NUM) = 0 36 and ELGBLTY_SW EQ "Y" 37 and ORGNL_PRTCPTN_DT le "2017.0101" 38 and (TRMNTN_EXPRTN_DT = '' or TRMNTN_EXPRTN_DT gt "2017.0101") 39 ;
Ugh, yes, that is the reason.
Thanks
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.