BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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 ;
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

3 REPLIES 3
ballardw
Super User

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 

Quentin
Super User

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 ;
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Batman
Quartz | Level 8

Ugh, yes, that is the reason.

 

Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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